peterverebics/CodeNet_Python_118 huggingface dataset:
N = int(input())
A = sorted(list(map(int,input().split())))

ave = sum(A) // N
ave2 = sum(A) // N + 1

total = [0,0]

for i in range(N):
  total[0] += abs(A[i] - ave) ** 2
  total[1] += abs(A[i] - ave2) ** 2
  
print(min(total))
N = int(input())
X = list(map(int, input().split()))
X.sort()

l = []

for p in range(min(X), max(X)+1):
    cnt = 0
    for i in range(N):
        cnt += (X[i] - p) ** 2
    l.append(cnt)
print(min(l))
N = int(input())
X=list(map(int, input().split())) 
X_max = max(X)
X_min = min(X)
 
answerlist = []
for i in range(X_min,X_max+1):
  newX = [(n-i)**2 for n in X]
  total = sum(newX)
  answerlist.append(total)
  
print(min(answerlist))
N = int(input())
s = list(map(int, input().split()))

m = min(s)
M = max(s)

lis = []
ans = 0

for i in range(m,M + 1):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))
N = int(input())
X = list(map(int, input().split()))
p_list = [0]
for P in range(1,101):
    power = 0
    for i in range(N):
        power += (X[i] - P)**2
    p_list.append(power)
sp_list = sorted(p_list)
print(sp_list[1])
#!python3.4.3
import statistics
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

n = int(input())
x_list = list(map(int, input().split(' ')))

mean = statistics.mean(x_list)
mean = Decimal(str(mean)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
result = 0


for x in x_list:
  result += (x - mean)**2
  
print(result)
N = int(input())
X = [int(x) for x in input().split()]

ans = 100 ** 2 * N
for i in range(min(X), max(X)+1):
  a = 0
  for j in range(N):
    a += (X[j] - i) ** 2
  if ans > a:
    ans = a
print(ans)
n = int(input());

v = [int(i) for i in input().split()];

res = 1000000;
for p in range(101):
    curr = 0;
    for x in v:
        curr += (x - p)**2;
    res = min(res, curr);

print(res);
N = int(input())
X = input().split()
X = [int(l) for l in X]

s = 0
for x in X:
    s += (x-X[0])**2
S = s

if N == 1:
    print(S)
else:
    m = max(X)
    n = min(X)
    for P in range(n,m+1):
        s = 0
        for x in X:
            s += (x-P)**2
        if s < S:
            S = s
    print(S)
N=int(input())
huga = list(map(int, input().split()))

m=10**9+7
for i in range(0,100):
  p=i+1
  a=0
  for j in range(0,N):
    a=a+(huga[j]-p)**2
  m=min(a,m)
  
print(m)
N = int(input())
X = list(map(int,input().split()))
t = [0]*101
for i in range (101):
    for j in range (N):
           t[i] = (i - X[j])**2 + t[i]
print(min(t))
N = int(input())
X = list(map(int,input().split()))
cmin = 10**6+10
for i in range(101):
    cnt = 0
    for j in range(N):
        cnt += (i-X[j])**2
    cmin = min(cmin,cnt)
print(cmin)
#template
def inputlist(): return [int(j) for j in input().split()]
def listinput(): return input().split()
#template
N = int(input())
X = inputlist()
ans = 10**9+7
for i in range(101):
    tmp = 0
    for j in range(N):
        tmp += (X[j]- i)**2
    ans = min(ans,tmp)
print(ans)
n = int(input())
x = list(map(int, input().split()))
ans = []
total = 0
for p in range(min(x), max(x) + 1):
    for i in range(n):
        total += (x[i] - p)**2
    ans.append(total)
    total = 0
print(min(ans))
n=int(input())
x=list(map(int,input().split()))
min_x=sum(x)/n
int_x=int(min_x)
if min_x-int_x <= int_x+1-min_x:
    mp=int_x
else:
    mp=int_x+1
ans=0
for i in range(n):
    ans+=(x[i]-mp)**2
print(ans)
N = int(input())
A = list(map(int, input().split()))

ans = 100000000
for i in range(100):
  cost = 0
  for j in range(len(A)):
    cost += (A[j] - i) *(A[j] - i)
  ans = min (ans,cost)
print(ans)
# coding: utf-8
# Your code here!

n=int(input())
x=list(map(int,input().split()))
cost_min=1000000000
for i in range(1,101):
    cost=0
    for j in x:
        cost+=(j-i)**2
    if cost>=cost_min:
        continue
    cost_min=cost
print(cost_min)
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X) / N + 0.5)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)
N = int(input())
ans = 10**9+7
X_list = list(map(int,input().split()))
for P in range(min(X_list),max(X_list)+1):
    ans = min(ans,sum([(i-P)**2 for i in X_list]))
print(ans)
def solve():
    N = int(input())
    X = [int(i) for i in input().split()]
    from decimal import Decimal, ROUND_HALF_UP
    target = int(Decimal(sum(X)/float(N)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
    ans = 0
    for x in X:
        ans += (x-target)**2
    print(ans)

if __name__ == "__main__":
    solve()
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x = na()
minx = min(x)
maxx = max(x)
ans = 10 ** 9 + 7
for i in range(minx, maxx+1):
    tmp = 0
    for j in range(n):
        tmp += (i-x[j])**2
    ans = min(tmp, ans)
print(ans)
N = input()
N = int(N)
X = input().split()
A = []

min = 100
max = 0
for x in X:
  x = int(x)
  A.append(x)
  if max < x:
    max = x
  if x < min:
    min = x

ans = 0
count = 1
for p in range(min, max):
  sum = 0
  for a in A:
    sum += (a - p) * (a - p) 
  if ans > sum:
    ans = sum
  if count == 1:
    ans = sum
  count += 1

print(ans)
n = int(input())
x = sorted(list(map(int, input().split())))

min_sum = float('inf')
for i in range(x[0], x[len(x) - 1] + 1):
    sum = 0
    for j in range(n):
        sum += (x[j] - i) ** 2
    if sum < min_sum:
        min_sum = sum

print(min_sum)
n = int(input())
x = list(map(int, input().split()))
ans = 10 ** 9
for p in range(0, 101):
    cnt = 0
    for i in x:
        cnt += (i-p)**2
    ans = min(ans, cnt)
print(ans)
n = int(input())

l = list(map(int,input().split()))
#n,m = map(int,input().split())
c=0
for i in l:
    c+=i

c=c//n
c1 = c+1 

#print(c,c1)

ans=0
for i in l:
    ans+=(c-i)*(c-i)
    
ans1=0
for i in l:
    ans1+=(c1-i)*(c1-i)
print(min(ans,ans1))
n = int(input())
x_n = list(map(int, input().split()))
ave = sum(x_n)//n
res = 0
for x_i in x_n:
    res += x_i**2
for p in range(ave - 2, ave + 3):
    point = 0
    for x_i in x_n:
        point += (x_i - p)**2
    res = min(res, point)
print(res)
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)
import math
N = int(input())
X = list(map(int, input().split()))
s = 0
t = 0

for x in X:
    s += x
    t += x ** 2

def check(k):
    return t - 2 * s * k + N * (k ** 2)

if check(math.floor(s / N)) < check(math.ceil(s / N)):
    print(check(math.floor(s / N)))
else:
    print(check(math.ceil(s / N)))
N = input()
x = list(map(int, input().split()))
start = min(x)
fin = max(x)
res = 0
for j in range(len(x)):
        res = res + (x[j]-start)*(x[j]-start)
        
for i in range(start,fin):
    sum = 0
    for j in range(len(x)):
        sum = sum + (x[j]-i)*(x[j]-i)
    if(sum < res):
        res = sum

print(res)
n=int(input())
l=list(map(int, input().split()))
ans=10000000000000000000000000000000000000000000000000000000000000000
for i in range(min(l), max(l)+1):
  cnt=0
  for s in l:
    cnt+=(s-i)**2    
  ans=min(ans, cnt)
print(ans)
n=int(input())
x=list(map(int,input().split()))
ans=10**8
for i in range(1,101):
    sum=0
    for j in range(n):
        sum+=(x[j]-i)**2
    ans=min(ans,sum)
print(ans)
n = int(input())
x = sorted(list(map(int,input().split())))
ans = float("inf")
def solve(p,m):
  a = len(m)
  b = 0
  for i in range(a):
    b += (m[i]-p)**2
  return b
for j in range(1,101):
  ans = min(ans,solve(j,x))
print(ans)
n=int(input())

X=list(map(int,input().split()))
X=sorted(X,reverse=True)
if n==1:
  print(0)
  exit()

A=[]
for i in range(1,100):
  ans=0
  for j  in range(n):
    ans += abs(i-X[j])**2
  A.append(ans)
A = sorted(A)
print(A[0])
N=int(input())
X=list(map(int,input().split()))
cost=0
for i in range(len(X)):
    cost=cost+X[i]**2

for i in range(1,101):
    cost2=0
    for j in range(len(X)):
        cost2=cost2+(X[j]-i)**2
    cost=min(cost,cost2)

print(cost)
N = int(input())
X = list(map(int, input().split()))
h = sum(X)//N
ans = 0
for x in X:
    ans+=(x-h)**2
ans2 = 0
h+=1
for x in X:
    ans2+=(x-h)**2
print(min(ans, ans2))
n = int(input())
x = list(map(int, input().split()))

s = round(sum(x)/n)
ans = [(a-s)**2 for a in x]

print(sum(ans))
import math
n=int(input())
a=list(map(int,input().split()))
t=sum(a)/n
s=0
p=0
if t==int(t):
    for i in range(n):
        s += int(math.pow(t - a[i], 2))
    print(s)
else:
    for i in range(n):
        s += int(math.pow(int(t) - a[i], 2))
        p+= int(math.pow(int(t)+1 - a[i], 2))

    print(min(p,s))
n=int(input())
x=list(map(int,input().split()))
ans=1000000000000
for p in range(100):
    a=0
    for i in range(n):
        a+=(x[i]-p)**2 
    if a < ans:
        ans = a

print(ans)
import math

def calc(N, X):
    P = round(sum(X) / N)
    res = 0
    for x in X:
        res += (P - x) ** 2
    return math.ceil(res)

if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    print(calc(N, X))
def Stamina(N, X_list, P):
  stamina = 0
  for i in range(N):
    X = X_list[i]
    stamina += X * X - 2 * P * X
  stamina += N * P * P
  return stamina

N = int(input())
X_list = list(map(int, input().split()))
P1 = int(sum(X_list) / N)
P2 = P1 + 1
stamina1 = Stamina(N, X_list, P1)
stamina2 = Stamina(N, X_list, P2)
print (min(stamina1, stamina2))
n = int(input())
l = list(map(int,input().split()))
min_sum = 10**9
for i in range(min(l),max(l)+1):
    min_sum = min(min_sum,sum([(j-i)**2 for j in l]))

print(min_sum)
N = int(input())
X = list(map(int, input().split()))

minimum = min(X)
maximum = max(X)

def shohi(zahyo, shukai):
  return pow(zahyo - shukai, 2)

saisho = None
for i in range(minimum, maximum + 1):
  ret = sum(map(lambda zahyo: shohi(zahyo, i), X))
  saisho = ret if saisho is None or ret < saisho else saisho

print(saisho)
N = int(input())
X = list(map(int, input().split()))

HP = []
for p in range(1, 101, 1):
    P = [p] * len(X)
    delta = sum([(i - j) ** 2 for (i, j) in zip(X, P)])
    HP.append(delta)

print(min(HP))
N=int(input())
X=list(map(int, input().split()))
s=[]
for i in range(min(X),max(X)+1):
    a=0
    for i2 in range(N):
        a+=(i-X[i2])**2
    s.append(a)
print(min(s))
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]

ans = 2147483647
tmp = 0
for i in range(-1000, 1001): #iは集会を開く場所
    for j in range(n):
        tmp += pow(x[j] - i, 2)
    if ans > tmp:
        ans = tmp
    tmp = 0
print(ans)
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
X = inintl()

p = 0
min_d = 10**10
ans = 0

for i in range(1,max(X)+1):
    t_d = 0
    for x in X:
        t_d += (x-i)**2
    if t_d < min_d:
        min_d = t_d
        p = i

for x in X:
    ans += (x-p)**2

print(ans)
N = int(input())
X = [int(x) for x in input().split()]

ans = 10 ** 20
for i in range(1, 101):
    temp = 0
    for j in range(N):
        temp += (X[j] - i) ** 2
    ans = min(ans, temp)
print(ans)
N = int(input())
X = list(map(int, input().split()))
print(min([sum([(x - P)**2 for x in X]) for P in range(1, 100)]))
n = int(input())
x = list(map(int,input().split()))
ans = 10 ** 6
for p in range(1, 101):
    wa = 0
    for i in x:
        wa  += (i - p) ** 2
    ans = min(ans, wa)
print(ans)
import math

n = int(input())
x = list(map(int, input().split()))
p = sum(x) / len(x)

a1 = sum([(a - math.floor(p)) * (a - math.floor(p)) for a in x])
a2 = sum([(a - math.ceil(p)) * (a - math.ceil(p)) for a in x])
print(min(a1, a2))
N = int(input())
X = [int(x) for x in input().split(' ')]
Pa = sum(X) // N
Pb = Pa + 1
Ca = Cb = 0
for i in range(N):
  Ca += (X[i] - Pa)**2
  Cb += (X[i] - Pb)**2
print(min(Ca, Cb))
n=input()
x=list(map(int, input().split()))

maxdist = x[int(n)-1]
p=int(sum(x)/len(x))
ret = 0
ret2 = 0
for i in x:
    ret = ret + (p-i)**2
    ret2 = ret2 + (p-i+1)**2
ret = ret if ret < ret2 else ret2
print(ret)
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp, hp)
print(hp)
N = int(input())
X = list(map(int, input().split()))

ans = -1
for i in range(100):
    I = i + 1
    res = 0
    for j in range(N):
        res += (I - X[j]) * (I - X[j])
    if ans == -1:
        ans = res
    else:
        ans = min(ans, res)

print(ans)
n= int(input());
ls=list(map(int,input().split()));
x=int(sum(ls)/len(ls))
y=x+1;
ans1=0;
ans2=0;
for i in ls:
    ans1+=(x-i)**2;
    ans2+=(y-i)**2;
print(min(ans1,ans2))
n = int(input())

x = list(map(int, input().split()))

min_hp = 0
sum_hp = 0

for i in range(n):
    sum_hp += (x[i]-1)**2
min_hp = sum_hp

sum_hp = 0
for i in range(2,max(x)+1):
    for j in range(n):
        sum_hp += (x[j]-i)**2
    if min_hp > sum_hp:
        min_hp = sum_hp
    sum_hp = 0
 
print(min_hp)
N = int(input())
Xn = list(map(int,input().split()))

m = max(Xn)

ans = 10**9
for i in range(m+1):
    k = sum((x-i)**2 for x in Xn)
    ans = min(ans, k)

print(ans)
input()
a = list(map(int, input().split()))
print(min(sum((x - p)**2 for x in a) for p in range(1, 101)))
N = int(input())
X = list(map(int,input().split()))
X.sort()
result = 1000000
A = 0
for i in range(101):
    for j in range(len(X)):
        A += (i-X[j])**2
    result = min(A,result)
    A = 0
print(result)
# -*- coding: utf-8 -*-
from decimal import Decimal, ROUND_HALF_UP
n = int(input())
l_x = list(map(int, input().split()))
mtg_p = Decimal(str(sum(l_x) / n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

print(sum([(x-mtg_p)**2 for x in l_x]))
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
f.sort()
ans=0
ma = []
for i in range(f[0],f[-1]+1):
    for k in f:
        ans+=((k-i)**2)
    ma.append(ans)
    ans=0
print(min(ma))
N = int(input())
s = list(map(int , input().split()))
list.sort(s , reverse = True)
L = [10**10]
for p in range(min(s) , max(s) + 1):
  a = 0
  b = L[0]
  for i in range(N):
    if a < b:
      a += (s[i] - p) ** 2
  if a < b:
    L[0] = a
print(L[0])
n = int(input())
x = list(map(int, input().split(' ')))
p0 = sum(x)/n
if p0-int(p0) > 0.5:
    p = (int(p0)+1)
else:
    p = (int(p0))
ans = 0
i = 0
while i < n:
    ans += (x[i]-p)*(x[i]-p)
    i += 1
    
print(ans)
N = int(input())
X = list(map(int, input().split()))

ans = 10**9
for i in range(1,101):
    tmp = 0
    for j in range(N):
        tmp += abs(X[j] - i) ** 2
    ans = min(ans, tmp)

print(ans)
n = int(input())
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = 9999999999
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)
n = int(input())
x = sorted([int(i) for i in input().split()])

md = int(sum(x)/n+.5)
num = 0
for i in x:
    num += (abs(i-md))**2
print(num)
N = int(input())
X = list(map(int, input().split()))

dX = round(sum(X)/N)
e = 0
for x in X:
    e = e + (x - dX)**2

print(e)
n,*a=map(int,open(0).read().split())
ave=sum(a)//n
b=sum((x-ave)**2 for x in a)
c=sum((x-ave-1)**2 for x in a)
print(min(b,c))
def main():
    N = int(input())
    X = list(map(int, input().split()))

    mini = float("inf")
    for p in range(1, 101):
        power = 0
        for n in range(N):
            power += (X[n] - p) ** 2
        if power < mini:
            mini = power
    
    print(mini)

if __name__ == '__main__':
    main()
n = int( input() )
x = list( map( int, input().split() ) )

mean = int( sum( x ) / len( x ) + 0.5 + ( 10 ** -10 ) )

var = 0
for x_i in x:
    var += ( x_i - mean ) ** 2

print( var )
N = int(input())
X = list(map(int, input().split()))

min=1000000
for i in range(100):
    sum = 0
    for j in range(N):
        sum = sum + (X[j] - i) ** 2
    if sum<min:
        min=sum

print(min)
import numpy as np

n = int(input())
x = np.array(list(map(int, input().split())))

average_x = np.mean(x)
p = round(average_x)

l = np.square(x-p)
print(int(sum(l)))
N = int(input())
A = list(map(int, input().split()))
chushin = sum(A)//N
chushin_1 = sum(A)//N +1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a-chushin) ** 2
    answer_1 += abs(a-chushin_1) ** 2
print(min(answer,answer_1))
n = int(input())
X = list(map(int,input().split()))
p = round(sum(X)/n)
total = 0
for i in range(n):
  total+=int((X[i]-p)**2)
print(total)
n=int(input())
x=list(map(int,input().split()))
p = int(sum(x) / n + 0.5)
print(sum( (i-p)**2 for i in x))
def solve():
    N, *X = map(int, open(0).read().split())
    
    ans = 10 ** 8
    for p in range(1, 101):
        sm = 0
        for xi in X:
            sm += (xi - p) ** 2
        ans = min(ans, sm)
    print(ans)


if __name__ == '__main__':
    solve()
def main():
    n = int(input())
    x_lst = list(map(int, input().split()))
    ans = 10 ** 12

    for p in range(1, 101):
        sum_hp = 0
        for x in x_lst:
            sum_hp += (x - p) ** 2
        if sum_hp < ans:
            ans = sum_hp

    print(ans)


if __name__ == "__main__":
    main()
N = int(input())
X = list(map(int,input().split()))

minimum = 10000000

for n in range(1,max(X)+1):
  kyori = 0
  for i in range(N):
    kyori += (X[i]-n)**2
  if kyori < minimum:
    minimum = kyori
print(minimum)
n = int(input())
x = list(map(int,input().split()))
count1 = 0
count2 = 0
x.sort ()
ans1 = sum(x)//n
ans2 = ans1+1
for i in range(n):
    count1 += (x[i]-ans1)**2
    count2 += (x[i]-ans2)**2
print(min(count1,count2))
a=int(input())
b=list(map(int,input().split()))
bmax=max(b)+1
bmin=min(b)
ans=1000000
for i in range(bmin,bmax,1):
  e=0
  for j in b:
    e+=(i-j)**2
  ans=min(ans,e)
print(ans)
N = int(input())
X = [int(a) for a in input().split()]

minval = 10**6

for i in range(max(X)):
    val = 0
    for j in range(N):
        val += (X[j]-(i+1))**2
    minval = min(val, minval)

print(minval)
N=int(input())
X=list(map(int,input().split()))

m=sum(X)//N
if sum(X)/N-m>=0.5:
    m+=1
ans=0
for i in range(N):
    ans+=(X[i]-m)**2

print(ans)
n = int(input())

xarr = list(map(int, input().split()))
X = 0

for x in xarr:
  X += x
  
mean = X//n

ans1 = 0
ans2 = 0

for x in xarr:
  ans1 += (x - mean) * (x - mean)
  ans2 += (x - mean - 1) * (x - mean - 1)

print(min(ans1, ans2))
n = int(input())
x = list(map(int, input().split()))

ans = 10**8
for p in range(1, 150):
    w = 0
    for i in range(n):
        w += (x[i] - p)**2

    ans = min(w, ans)
print(ans)
import numpy as np

n = int(input())
x = np.array([int(x) for x in input().split()])

ans = 10 ** 10
for i in range(1, 101):
    temp = x - i
    ans = min(ans, sum([j ** 2 for j in temp]))

print(ans)
N = int(input())
X = list(map(int, input().split()))
ans = 10**18
m = min(X)
M = max(X)

for i in range(m, M+1):
    ans_cand = 0
    
    for Xi in X:
        ans_cand += (i-Xi)**2
    
    ans = min(ans, ans_cand)

print(ans)
N=int(input())
x=list(map(int,input().split()))
mi = 10**9
for mid in range(0,max(x)+1):
    tmp = 0
    for val in x:
        tmp += (val-mid)**2
    mi = min([mi,tmp])
print(mi)
N = int(input())
X = list(map(int, input().split(" ")))
P = int((sum(X) / N) + 0.5)
print(sum([(X[i] - P) ** 2 for i in range(N)]))
n = int(input())
x = list(map(int, input().split()))

ans = 1001001001
for p in range(1, 101):
	tmp = 0
	for i in range(n):
		tmp += (x[i]-p)**2
	ans = min(ans, tmp)

print(ans)
import math

n = int(input())
l = list(map(int,input().split()))
y = sum(l)
x = y//n
x1 = math.ceil(y/n)
sum1 = 0
sum2 = 0
for i in l:
  sum1 += (i-x)**2
  sum2 += (i-x1)**2
print(min(sum1,sum2))
input()
X = tuple(map(int, input().split()))
print(min(sum((x - p) ** 2 for x in X) for p in range(min(X), max(X) + 1)))
n = int(input())
x = list(map(int, input().split()))
ret = 1000000
for p in range(1, 101):
    ret = min(ret, sum((x - p) ** 2 for x in x))
print(ret)
people=int(input())
vector=list(map(int,input().split()))
min_cordination=min(vector)
max_cordination=max(vector)
sum_squared_list=[]
for i in range(min_cordination,max_cordination+1):
  tmp_sum_squared=0
  for one_person in vector:
    tmp_sum_squared+=(i-one_person)**2
  sum_squared_list.append(tmp_sum_squared)
print(min(sum_squared_list))
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

N=int(input())
X = list(map(int,input().split()))
s=0
for i in range(len(X)):
    s+=X[i]
P=int(s/N)

Sum_round_down=0
Sum_round_up=0
for i in range(len(X)):
    Sum_round_down+=(P-X[i])**2
    Sum_round_up+=(P+1-X[i])**2
if(Sum_round_down>=Sum_round_up):
    Sum=Sum_round_up
else:
    Sum=Sum=Sum_round_down
print(int(Sum))
n = int(input())
x = list(map(int, input().split()))

min_res = float("inf")
for i in range(1, 101):
    res = sum((xi - i) ** 2 for xi in x)
    min_res = min(min_res, res)

print(min_res)
N = int(input())
X = list(map(int,input().split()))

P = int(sum(X)/N+0.5)

print(sum(map(lambda x_i: (x_i-P)**2, X)))
N = int(input())
X = list(map(int, input().split()))

S = 0
S_min = 100000000000000

for i in range(101):
    for j in X:
        S += (j - i)**2
        
    if S < S_min:
        S_min = S
        S = 0
    else:
        S = 0
print(S_min)
import sys
N = int(input())
X = [int(c) for c in input().split()]
l = [10**10]
for i in range(1,101):
    l.append(0)
    for j in range(len(X)):
        l[i] += (X[j]-i)**2
    
    if l[i-1] < l[i]:
        print(l[i-1])
        sys.exit(0)
import numpy as np
N = int(input())
X = np.array(list(map(int,input().split())))
ans_sum = float('inf')
for i in range(1,101):
    ans_sum=min(ans_sum,sum((X-i)**2))
print(ans_sum)
n = int(input())
x = list(map(int, input().split()))
ans = 1e9
for i in range(1, 101):
    a = 0
    for j in x:
        a += (j - i)**2
    ans = min(a, ans)
print(ans)
N=int(input())
a=list(map(int,input().split()))
x=int(sum(a)/N)
ans1=0
ans2=0
for i in range(N):
  ans1+=(x-a[i])**2
  ans2+=(x+1-a[i])**2
print(min(ans1,ans2))
N=int(input())
X=list(map(int,input().split()))
ans = 100000000
for j in range(1,100):
  res = 0
  for i in range(N):
    res += (X[i]-j)**2
  ans=min(ans,res)
print(ans)
n = int(input())
X = list(map(int, input().split()))
mean_L = sum(X)//n
mean_R = mean_L+1
ans = min(sum(map(lambda x: (x-mean_L)**2, X)),
          sum(map(lambda x: (x-mean_R)**2, X)))
print(ans)
N = int(input())
X = list(map(int, input().split()))

ma = max(X)
mi = min(X)

ans = 10**9

for n in range(mi, ma+1):
  count = 0
  for x in X:
    count += abs(x-n)**2

  if ans > count:
    ans = count

print(ans)
n = int(input())
a = list(map(int,input().split()))
X_a = max(a)
N_a = min(a)
L_a = X_a - N_a + 1
b=[0]*L_a

while True:
  if N_a >= X_a:
    break
  for k in range(1,L_a+1):
    for i in a:      
      b[k-1] += (i-N_a)*(i-N_a)
    N_a +=1
print(min(b))
N = int(input())
A = list(map(int, input().split()))

average = sum(A) // N
ans1 = 0
for i in A:
    ans1 += (i-average)**2
ans2 = 0
for i in A:
    ans2 += (i-average-1)**2
ans = min(ans1, ans2)

print(ans)
N = int(input())
X = list(map(int,input().split()))
ans = float("inf")
for loc in range(-100,101):
  temp = 0
  for x in X:
    temp += (loc-x)**2
  ans = min(temp,ans)
print(ans)
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


N = ii()

X = li()

import numpy as np

X = np.sort(X)

x_st = X[0]
x_ed = X[-1]

all_min = np.inf

for i in range(x_st,x_ed+1):
    itr_min = np.sum(np.abs(X-i)**2)
    # print(i,itr_min)


    if(all_min > itr_min):
        all_min = itr_min


print(all_min)
import math


def main():
    n = int(input())
    array = [int(s) for s in input().split(" ")]
    min_v = min(array)
    max_v = max(array)
    min_ans = float("inf")
    for i in range(min_v, max_v + 1):
        total = 0
        for a in array:
            total += (a - i) ** 2
        if min_ans > total:
            min_ans = total
    print(min_ans)


if __name__ == '__main__':
    main()