Gromozeka has
N
integers
a1
,
a2
,..,
aN
. Its purpose is get
N
equal to
integersnumbers by converting some of them. It can convert each integer at most once. Converting an integer
x
to another integer
y
costs it
\((x-y)^2 \)  ; rubles. Even if
\(a_i = a_j\) (
\(i \neq j\)) he must separately pay the cost of converting each of them (see example 2).
Find the minimum total cost to achieve Gromozeka's goal.
Input
The first line specifies the number
N (
\(1<=N<=100\)). In the second line, the numbers
a1
,
a2
,..,
aN
(
\(100<=a_i<=100\)).
Imprint
Print the minimum total cost to achieve Gromozeka's goal.
Examples
# |
Input |
Output |
Explanations |
1 |
2
48 |
8 |
The minimum total transformation of both numbers is the transformation of each number into 6 will be: (4-6)2+(8-6)2=8 rubles. |
2 |
3
1 1 3
| 3 |
Transform all numbers into 2: (1-2)2+(1-2)2+(3-2)2 =3 rubles. Gromozeka is required to pay \((1-2)^2\) rubles for each converted number 1. |
3 |
3
4 2 5
| 5 |
Let's transform 2 and 5 into the number 4: (2-4)2+(5-4)2=5 rubles. |
4 |
4
-100 -100 -100 -100
| 0 |
Nothing needs to be converted. |