#P3650. Ski Camp Tax Avoidance

    ID: 16901 Type: Default 1000ms 256MiB

Ski Camp Tax Avoidance

Ski Camp Tax Avoidance

Farmer John owns a farm with ( n ) mountain peaks, where each mountain has an integer elevation between ( 0 ) and ( 100 ). In winter, John organizes ski training camps. However, due to a new tax law, if the difference between the highest and lowest mountain exceeds ( 17 ), a tax is imposed. To avoid this tax, John can adjust the elevation of the mountains by an integer amount. Changing the height of a mountain by ( x ) units costs ( x^2 ) units. Your task is to compute the minimum total cost required so that the difference between the highest and the lowest mountain is at most ( 17 ).

inputFormat

The first line of input contains a single integer ( n ) (the number of mountain peaks). The second line contains ( n ) space-separated integers representing the heights of the mountains.

outputFormat

Output a single integer, the minimum total cost required to adjust the mountain heights such that the difference between the highest and lowest mountain is no more than ( 17 ).

sample

3
3 15 5
0