N=int(input())
#people
li = list(map(int, input().split()))
Ave1=sum(li)//N
Ave2=sum(li)//N+1
S1=0
S2=0
for i in range(N):
  S1=S1+(Ave1-li[i])**2
for i in range(N):
  S2=S2+(Ave2-li[i])**2

if S1>S2:
  print(S2)
else:
  print(S1) N=int(input()) N int(input()) int input() input li = list(map(int, input().split())) li list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Ave1=sum(li)//N Ave1 sum(li)//N sum(li) sum li N Ave2=sum(li)//N+1 Ave2 sum(li)//N+1 sum(li)//N sum(li) sum li N 1 S1=0 S1 0 S2=0 S2 0 for i in range(N):
  S1=S1+(Ave1-li[i])**2 i range(N) range N S1=S1+(Ave1-li[i])**2 S1 S1+(Ave1-li[i])**2 S1 (Ave1-li[i])**2 Ave1-li[i] Ave1 li[i] li i 2 for i in range(N):
  S2=S2+(Ave2-li[i])**2 i range(N) range N S2=S2+(Ave2-li[i])**2 S2 S2+(Ave2-li[i])**2 S2 (Ave2-li[i])**2 Ave2-li[i] Ave2 li[i] li i 2 if S1>S2:
  print(S2)
else:
  print(S1) S1>S2 S1 S2 print(S2) print S2 print(S1) print S1 S2=0 0 S2 S1=S1+(Ave1-li[i])**2 S1+(Ave1-li[i])**2 S1 li = list(map(int, input().split())) list(map(int, input().split())) li S1=0 0 S1 S2=S2+(Ave2-li[i])**2 S2+(Ave2-li[i])**2 S2 Ave1=sum(li)//N sum(li)//N Ave1 N=int(input()) int(input()) N Ave2=sum(li)//N+1 sum(li)//N+1 Ave2
N=int(input())
#people
li = list(map(int, input().split()))
Ave1=sum(li)//N
Ave2=sum(li)//N+1
S1=0
S2=0
for i in range(N):
  S1=S1+(Ave1-li[i])**2
for i in range(N):
  S2=S2+(Ave2-li[i])**2

if S1>S2:
  print(S2)
else:
  print(S1)