n = int(input())
A = list(map(int,input().split()))
val1 = sum(A)//n
val2 = val1+1
ans1 = 0
ans2 = 0
for a in A:
    ans1 += (a-val1)**2
    ans2 += (a-val2)**2
print(min(ans1,ans2)) n = int(input()) n int(input()) int input() input A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split val1 = sum(A)//n val1 sum(A)//n sum(A) sum A n val2 = val1+1 val2 val1+1 val1 1 ans1 = 0 ans1 0 ans2 = 0 ans2 0 for a in A:
    ans1 += (a-val1)**2
    ans2 += (a-val2)**2 a A ans1 += (a-val1)**2 ans1 (a-val1)**2 a-val1 a val1 2 ans2 += (a-val2)**2 ans2 (a-val2)**2 a-val2 a val2 2 print(min(ans1,ans2)) print min(ans1,ans2) min ans1 ans2 val1 = sum(A)//n sum(A)//n val1 A = list(map(int,input().split())) list(map(int,input().split())) A ans1 += (a-val1)**2 (a-val1)**2 ans1 n = int(input()) int(input()) n ans2 = 0 0 ans2 ans2 += (a-val2)**2 (a-val2)**2 ans2 ans1 = 0 0 ans1 val2 = val1+1 val1+1 val2
n = int(input())
A = list(map(int,input().split()))
val1 = sum(A)//n
val2 = val1+1
ans1 = 0
ans2 = 0
for a in A:
    ans1 += (a-val1)**2
    ans2 += (a-val2)**2
print(min(ans1,ans2))
