Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them.  He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).  Find the minimum total cost to achieve his objective.
import math
n = int(input())
a = map(int, input().split())
avg = math.ceil(sum(a) / n)
ans = 0
for i in a:
  ans += (i - avg) ** 2
print(ans)
import math
n = int(input())
a = sorted(map(int, input().split()))
ans = []
for i in range(a[0], a[-1] + 1):
  c = 0
  for j in a:
    c += (j - i) ** 2
  ans.append(c)
print(min(ans))