import math
N=int(input())
C=list(map(int,input().split()))
ave = sum(C) / len(C)
X=math.floor(ave)
Y=X+1
Xsum,Ysum=0,0
for i in range(len(C)):
  Xsum += (C[i]-X)**2
  Ysum += (C[i]-Y)**2
print(min([Xsum,Ysum])) import math math N=int(input()) N int(input()) int input() input C=list(map(int,input().split())) C list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ave = sum(C) / len(C) ave sum(C) / len(C) sum(C) sum C len(C) len C X=math.floor(ave) X math.floor(ave) math.floor math floor ave Y=X+1 Y X+1 X 1 Xsum,Ysum=0,0 Xsum 0 Ysum 0 for i in range(len(C)):
  Xsum += (C[i]-X)**2
  Ysum += (C[i]-Y)**2 i range(len(C)) range len(C) len C Xsum += (C[i]-X)**2 Xsum (C[i]-X)**2 C[i]-X C[i] C i X 2 Ysum += (C[i]-Y)**2 Ysum (C[i]-Y)**2 C[i]-Y C[i] C i Y 2 print(min([Xsum,Ysum])) print min([Xsum,Ysum]) min [Xsum,Ysum] Xsum Ysum C=list(map(int,input().split())) list(map(int,input().split())) C ave = sum(C) / len(C) sum(C) / len(C) ave Xsum += (C[i]-X)**2 (C[i]-X)**2 Xsum Ysum=0,0 0 Ysum Y=X+1 X+1 Y X=math.floor(ave) math.floor(ave) X N=int(input()) int(input()) N Xsum,Ysum=0,0 0 Xsum Ysum += (C[i]-Y)**2 (C[i]-Y)**2 Ysum
import math
N=int(input())
C=list(map(int,input().split()))
ave = sum(C) / len(C)
X=math.floor(ave)
Y=X+1
Xsum,Ysum=0,0
for i in range(len(C)):
  Xsum += (C[i]-X)**2
  Ysum += (C[i]-Y)**2
print(min([Xsum,Ysum]))