peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(input())
x = list(map(int, input().split()))

if n == 1:
    print(0)
ans = 10**10
for i in range(min(x),max(x)+1):
    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()))

ans=float("inf")
for P in range(X[0],X[-1]+1):
  a=0
  for i in range(N):
    a+=(X[i]-P)**2
  ans=min(ans,a)
  
print(ans)
import math
 
N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
        if(a != c):
            all = False
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-math.ceil(C))**2
if all == True:
    print(0)
else:
    print(ans)
import numpy as np
n = int(input())
x = list(map(int,input().split()))
z = np.array(x)
ans = 10**10
for i in range(min(x),max(x)+1):
    z -= np.array([i for _ in range(n)])
    y = z*z
    ans = min(ans,sum(y))

print(ans)
N = int(input())
a = list(map(int,input().split()))
ans = 10**4
for i in range(1,N+1):
    b = sum((a[j]-i-1)**2 for j in range(0,N))
    ans = min(ans,b)
print(ans)
from math import floor, ceil

N = int(input())

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

mean = int(ceil(sum(X)/N))

print(sum(map(lambda x: (x-mean)**2, X)))
n=int(input())
x=list(map(int,input().split()))
ans=0
average=sum(x)//n

for i in x:
    ans+=(i-average)**2

print(ans)
N =int(input())
X = list(map(int,input().split()))
X.sort()
tans=[]
try:
  for i in range(1,X[N-1]):
    P=i
    ans=0
    for j in range(N):
      ans+=(X[j]-P)**2
    tans.append(ans)
  print(min(tans))
except:
  print(0)
N = int(input())
xlist = list(map(int, input().split()))
p = sum(xlist) // N
s = 0
for x in xlist:
    s += (x-p)**2
print(s)
n=int(input())
x=list(map(int,input().split()))
ans=10000000000000000

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

print(ans)
import sys

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

mean = sum(x) // n

ans = 0
for i in range(n):
	ans += (x[i]-mean) ** 2
print(ans)
X = list(map(int, input().split()))
X.sort()
ans = 10**10
for p in range(X[0], X[-1]+1):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)
n = int(input())
x = list(map(int, input().split()))
ans = 10000
for j in range(1, max(x) + 1):
    cnt = 0
    for i in range(n):
        cnt += (x[i] - j) ** 2
    if cnt < ans:
        ans = cnt
print(ans)
import numpy as np
n = int(input())
x = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
#一行で入力された数値をリストに
p = 0
x2 = np.power(x,2)

xsum = sum(x)
xsum2 = sum(x2)

p = -(-xsum//n)

print(xsum2 - 2*p*xsum + n*p*p)
from statistics import median

n = int(input())
p = list(map(int, input().split()))

min_sum = 10**9
for location in range(min(p), max(p)):
    sum = 0
    for i in range(n):
        sum += (p[i]-location)**2
    if sum < min_sum:
        min_sum = sum

print(min_sum)
N = int(input())
X = list(map(int, input().split()))
ans = 100000
for i in range(0,100):
    s = 0
    for j in range(N):
        s+=(X[j]-i)**2
    ans = min(ans,s)
print(ans)
N = int(input())
X = list(map(int, input().split()))
HP1 = 0
HP2 = 0
P1 = sum(X) // N
P2 = sum(X) // N + 1
for Xi in X:
    HP1 = HP1 + (Xi - P1) ** 2
    HP2 = HP2 + (Xi - P1) ** 2

print(min(HP1, HP2))
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]

ans = 100 * 100
tmp = 0
for i in range(min(x), max(x)): #iは集会を開く場所
    for j in range(n):
        tmp += (x[j] - i) ** 2
    if ans > tmp:
        ans = tmp
    tmp = 0
print(ans)
n = int(input())
x_list = list(map(int, input().split(" ")))


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(min, max):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp

print(ans)
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(n_list[-1]):
    sum = 0
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)
n=int(input())
x=list(map(int, input().split()))
maxn=0
for i in range(n):
    if x[i]>maxn:
        maxn=x[i]
    else:
        maxn=maxn
minp=0
for j in range(n):
    minp=minp+(x[j]-1)**2
for i in range(maxn):
    power=0
    for j in range(n):
        power=power+(x[j]-i)**2
    if power<minp:
        minp=power
    else:
        minp=minp
print(minp)
n=int(input())
x=list(map(int,input().split()))

#a=sum(x)//n+1
x=sorted(x)
m=999999999999
for j in range(x[0],x[n-1]):
    a=j
    s=0
    for i in range(n):
        s+=(x[i]-a)**2
    m=min(m,s)

print(m)
N = int(input())
X = list(map(int, input().split()))
r = max(X)
list = []
n = 1
R = 0

for i in range(r):
  while n <= N-1:
    R += (int(X[n])-i)**2
    n += 1
  list.append(R)
  R = 0
  n = 0
    
print(min(list))
n = int(input())
x = list(map(int,input().split()))

w = 0
min_w = 10**5
for p in range(1,n+1):
    for i in range(n):
        w += (x[i] - p)**2
    min_w = min(w,min_w)
    w = 0
print(min_w)
N=int(input())
X=list(map(int, input().split()))
sum=sum(X)
ave=int(sum/N)+1
Y=0
for i in X:
	Y+=(i-ave)**2
print(Y)
N = int(input())
X = list(map(int, input().split()))

def num(N,X):
    number = 0
    for x in X:
        num = x-N
        #print(str(num))
        num2 = num**2
        print(str(num2))
        number += num2
        #print(str(number))
    return number
    
kekka = str(num(N,X))
print(kekka)
n, x = int(input()), list(map(int, input().split()))
px = 0
a = 100 * 100
for i in range(100):
  s = 0
  for j in x:
    s += (i-j) ** 2
  if a < s:
    break
  else:
    a = s
print(a)
n = int(input())
x = list(map(int,input().split()))

m = sum(x) / n
mp = float(m/1)

p = 0

if m - mp < mp + 1 - m:
  p = int(mp)

else:
  p = int(mp + 1)

ans = 0
for i in x:
  ans += (i - p)**2
  
print(ans)
import math
N = int(input())
X = list(map(int,input().split()))
a = sum(X)
mean = a/N
b = 0
for i in range(N):
    b +=(X[i]-mean)**2
print(math.ceil(b))
N = int(input())
X=list(map(int, input().split()))
MaxX = max(X)

ans = 10 ** 7
for i in range(1,MaxX):
    cost = 0
    for j in range(len(X)):
        cost += abs(X[j] - i) ** 2
    
    ans = min(ans, cost)

print(ans)
N = int(input())
X = list(map(int, input().split()))
P = sum(X) // N
result = 0

for x in X:
  result += (x - P)**2


print(result)
n = int(input())
x = list(map(int, input().split()))
mid = int(sum(x)/n)
ans = 1000000000000000000000
for j in range(x[0], x[n-1] + 1):
    total = 0
    for i in range(n):
        total += (x[i] - j)**2
    if total < ans:
        ans = total
    else:
        continue
print(ans)
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = 999999999999999999
for i in range(x[0], x[-1]):
    t = 0
    for q in range(n):
        t += (i - x[q]) ** 2
    else:
        if ans > t:
            ans = t

print(ans)
from statistics import mean, median,variance,stdev

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

loc = int(mean(X))+1
i = 0
result = 0
for i in range(N):
    result = result + ((loc - X[i]) ** 2)
    i += 1
print(result)
N = int(input())
X = list(map(int, input().split()))

ans = []
count = 0

for i in range(0,101):
    number = 0
    count = 0
    for j in X:
        number = number + ((j-i)**2)
        count = count + 1
        if N == count:
            ans.append(number)

print(ans)
n = int(input())
x = list(map(int, input().split()))
ans = 10 ** 9
for p in range(0, n+1):
    cnt = 0
    for i in x:
        cnt += (i-p)**2
    ans = min(ans, cnt)
print(ans)
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)**2
ans = min(ans1, ans2)

print(ans)
n=int(input())
li=list(map(int,input().split()))
li.sort()

mi,mx=li[0],li[-1]
ans=10**9
t=10**9
for i in range(mi,mx):
    ans=min(ans,t)
    t=0
    for j,item in enumerate (li):
       try:
           t+=(li[j]-i)**2
       except IndexError:
           print(j)
       
print(ans)
n = int(input())
x_lis = list(map(int, input().split()))
ans = 0
avg = sum(x_lis)/n
if avg - int(avg) >= 0.5:
    avg = int(avg) + 1
else:
    avg = int(avg)
print(avg)
for x in x_lis:
    ans += (x - avg)**2
print(ans)
N = input()
L = list(map(int, input().split()))

mean = sum(L) / len(L)
r = round(mean)
La = list(map(lambda x: (x - r)^2, L))

result = sum(La)

print(result)
n=int(input())
x=list(map(int,input().split()))
ans=[]
num=0
for p in range(n):
    for i in range(n):
        num+=((x[i]-p)**2)
    ans.append(num)
    num=0

print(min(ans))
N = input()
L = list(map(int, input().split()))

mean = sum(L) / len(L)
r = round(mean)
import math
n = int(input())
X = sorted(list(map(int, input().split())))
start = X[0]
end = X[-1]

ans = 100001
for i in range(start, end+1):
    tmp = sum([(x-i)**2 for x in X])
    ans = min(tmp,ans) 
print(ans)
import math
N = int(input()) 
a = [int(i) for i in input().split()]

ave = math.ceil(sum(a) / len(a))

print(sum([(i-ave)**2 for i in a]))
a=int(input())
li = list(map(int,input().split()))

dis = [0]*a
for p in range(a):
    for i in range(a):
        dis[p] += (li[i]-(p+1))**2
        
print(min(dis))
hito = int(input())
pos = list(map(int,input().split()))
pos.sort()
best = 10*5
temp = 0
for i in range(pos[0], pos[hito - 1] + 1):
    for n in pos:
        temp += (i - n)**2
    if best > temp:
        best = temp
    temp = 0
print(best)
#!/usr/bin/env python

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

ave = 0
for val in x:
    ave += val

loc = int(ave / n)
if loc - ave > 0.5:
    loc += 1

ans = 0
for val in x:
    ans += (val - loc)**2
print(ans)
N = int(input())

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

smallest = 10**4
for p in range(max(X)-min(X)):
  sum=0
  for j in range(N):
    sum=sum+(X[j]-p)**2
  #print(sum)
  if sum<smallest:
    smallest=sum

print(smallest)
n = int(input())
x = list(map(int, input().split()))
s = min(x)
e = max(x)

f_inf = float("inf")
ans = f_inf
for j in range(s, e):
    res = 0
    for i in range(n):
        res += (x[i] - j) ** 2

    ans = min(ans, res)

print(ans)
import math 
N=int(input())
X=list(map(int,input().split()))
s=0
for i in range(N):
  s+=(X[i]-N)**2
  
print(s)
import math

n=int(input())
x=list(map(int,input().split()))
num=math.ceil(sum(x)/n)
ans=0

for i in x:
  ans+=(i-num)**2
  
print(ans)
N=int(input())
C=list(map(int,input().split()))
Cmin,Cmax = min(C),max(C)
Sums=[]
for i in range(Cmin,Cmax+1):
  for j in range(len(C)):
    Sums.append((C[j]-i)^2)
print(min(Sums))
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    coord = map(int, input().split())
    print(calc_sum_of_power(N, coord))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()
n = int(input())
res=0
arr  = [int(x) for x in input().split()]
for i in range(n):
  res+=arr[i]
res = res//n
if (res&1):
  res+=1
k=0
for i in range(n):
  k+=((arr[i]-res)**2)
print(k)
import math

N = int(input())

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

P = math.ceil(sum(X) / N)

total = 0
for i in X:
    total += (i - P) ** 2

print(total)
if __name__ == '__main__':
  num_resident = int(input())
  
  x_list = [int(a) for a in input().split()]
  min_x = min(x_list)
  max_x = max(x_list)
  
  fin_ps = pow(max_x, 2)
  for i in range(min_x, max_x + 1):
    sum_ps = 0
    for x_i in range(num_resident):
      sum_ps += pow((x_list[x_i] - i), 2)
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)
N = int(input())
X = list(map(int, input().split()))

ans = 100 * 100
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)
N = int(input())
X = list(map(int, input().split()))
sum = []
for n in range(1,N+1):
    s = 0
    for x in X:
        s = s + ((x-n)*(x-n))
    sum.append(s)

print(min(sum))
n = int(input())
x_list = list(map(int, input().split(" ")))


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(min, max+1):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp

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

min = 0
result = 0
for i in range(100):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)
n = int(input())
a = list(map(int,input().split()))
m = round(sum(a)/n)
x = 0
for i in a:
  x=+(i-m)**2
print(x)
n=int(input())
x=list(map(int,input().split()))

#a=sum(x)//n+1

m=999999999999
for j in range(x[0],x[n-1]):
    a=j
    s=0
    for i in range(n):
        s+=(x[i]-a)**2
    m=min(m,s)

print(m)
N = int(input())
x = tuple(map(int, input().split()))
mid = (max(x) + min(x)) // 2
curr_sum = 0
dp = [10**9] * 101
for i in range(min(x), max(x)):
  dp[i] = 0
  for num in x:
    dp[i] += (num - i) ** 2
print(min(dp))
def dist(x, p):
    return (x - p)**2


n = int(input())
x = [int(i) for i in input().split()]
index = len(x) // 2
new_x = sorted(x)
p = - (- sum(x) // len(x))
ans = 0
for i in new_x:
    ans += dist(i, p)
print(ans)
N=int(input())
X=list(map(int,input().split()))

p = X[0]
sum = 0
for x in X:
  sum += (x - p)**2
ans = sum

for p in range(X[0]+1, X[N-1]+1): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)
N=int(input())
X=list(map(int,input().split()))
X_sum=sum(X)
ans=0
if abs(int(X_sum/N)-X_sum/N)>=abs(int(X_sum/N)+1-X_sum/N):
    P=int(X_sum/N)
else:
    P=int(X_sum/N)+1
for i in range(N):
    ans+=(X[i]-P)**2
print(ans)
n = int(input())
X = list(map(int, input().split()))
dist = 1000000
d = 0
for i in range(X[n - 1] + 1):
	for x in X:
		d += (x - i) * (x - i)
	if d < dist:
		dist = d
	d = 0
print(dist)
N=int(input())
X=list(map(int, input().split()))
minX=min(X)
maxX=max(X)
minE = 1000000000
for P in range(minX,maxX):
  sum = 0
  for Xi in X:
    sum = sum + (Xi-P)**2
  if minE>sum:
    minE=sum
print(minE)
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for p in range(1, max(X)+1):
    
    for x in X:
        x_sum=0
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)
n = int(input())
point_list = list(map(int, input().split()))
hp_list = []
for p in range(max(point_list)):
    hp = 0
    for i in range(len(point_list)):
        hp += (point_list[i] - p) ** 2
    hp_list.append(hp)
print(min(hp_list))
n=int(input())
l=list(map(int,input().split()))
x=max(l)
y=min(l)
li=[]
for i in range(x-y+1):
    ans=0
    for j in range(n):
        ans+=(l[j]-i)**2
    li.append(ans)
print(min(li))
import os

def main():
    count = int(input())
    int_list = list(map(int, input().split()))
    int_min,int_max = min(int_list),max(int_list)
    score = 0

    int_avg = int(sum(int_list) / len(int_list)) 
    print(int_avg)
    for i in int_list:
        score += (i - int_avg)**2
    print(score)

if __name__ == "__main__":
    main()
n = int(input())
x = list(map(int, input().split()))
ans = 100000
for j in range(max(x)):
    cnt = 0
    for i in range(n):
        cnt += (x[i] - (j + 1)) ** 2
    if cnt < ans:
        ans = cnt
print(ans)
N = int(input())
ans = 10**9+7
X_list = list(map(int,input().split()))
for P in range(min(X_list),max(X_list)):
    ans = min(ans,sum([(i-P)**2 for i in X_list]))
print(ans)
N = int(input())
Xlist = list(map(int, input().split()))
sumX = 0
for x in Xlist:
  sumX += x
average = int(sumX/N)
answer = 0
for x in Xlist:
  answer += (x-average)**2
print(answer)
n=int(input())
x=[int(x) for x in input().split()]

if sum(x)%n==0: m = sum(x)//n
else: m = sum(x)//n + 1

ans = 0
for i in range(n):
  ans += (x[i]-m)**2
print(ans)
N = int(input())
X = list(map(int, input().split()))

minX = min(X)
maxX = max(X)
if minX==maxX:
    print(X[0])
    quit()

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))
import os

def main():
    count = int(input())
    int_list = list(map(int, input().split()))
    int_min,int_max = min(int_list),max(int_list)
    score = 0

    int_avg = int_max // 2
    print(int_avg)
    for i in int_list:
        score += (i - int_avg)**2
    print(score)

if __name__ == "__main__":
    main()
n = int(input())
x = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += (x[i] - n)**2

print(ans)
import statistics

def cal_hp(p, num_list):
    total = 0
    for num in num_list:
        temp = (num - p) ** 2
        total = total + temp
    return total

line1 = input()
line2 = input()

num_list = line2.split(" ")
num_list = [int(n) for n in num_list]
ans_list = []
for i in range(0, max(num_list)):
    ans_list.append(cal_hp(i, num_list))
print(min(ans_list))
N = int(input())
Xlist = list(map(int, input().split()))
sumX = 0
for x in Xlist:
  sumX += x
average = (sumX/N)
answer = 0
for x in Xlist:
  answer += (x-average)**2
print(answer)
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P =1
if P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum  
print(min_sum)
n = int(input())
list = list(map(int, input().split()))

sum = 0
for i in list:
  sum += i
average = sum // len(list)
print(average)

ans = 0
for i in list:
  ans += (i-average-1)*(i-average-1)
print(ans)
N=int(input())
X=list(map(int, input().split()))
k1=(max(X)+min(X))//2
k2=k1+1
ans1=0
ans2=0
for x in X:
  ans1+=(k1-x)**2
  ans2+=(k2-x)**2

print(min(ans1, ans2))
N = int(input())
X = list(map(int, input().split()))

ans = float("inf")

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

    ans = min(ans, num)

print(ans)
N = int(input())
l = map(int, input().split())

mean = int(sum(l)/N)

stamina = 0

for p in l:
	stamina += (p - mean)**2
    
print(stamina)
n = int(input())
x = input().split()
x = [int(x_i) for x_i in x]

p = sum(x) / n

ans = 0
for x_i in x:
	ans = (x_i - p) * (x_i - p)
    
print(ans)
N= int(input())
X =list(map(int,input().split()))
P = [i for i in range(X[0],X[-1] + 1)]
MIN=-1
for p in P:
    total=0
    for x in X:
        total+=(x - p)**2
    if(MIN == -1):
        MIN=total
    else:
        MIN=min(MIN,total)
print(MIN)
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = 10 ** 20
    for i in range(r):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2

        ans = min(hp, ans)

    print(ans)
N = int(input())
li = list(map(int,input().split()))
result = []
for i in li:
    n = (int(i-N)**2)
    if n < 0:
        pass
    elif n > 0:
        result.append(n)

print(sum(result))
import numpy as np

def resolve():
    input()
    x = list(map(int, input().split()))
    m = int(round(np.median(x)))
    sum = 0
    for val in x:
        sum += (val - m) ** 2
    print(sum)

if __name__ == '__main__':
    resolve()
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
print(min_sum)
N = int(input())
X = list(map(int, input().split()))

min = 0
result = 0
for i in range(N):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)
N = int(input())
X = input().split()
X = [int(s) for s in X]
if N == 1:
    print(0)
else:
    X = sorted(X)
    range_X = X[-1] - X [0]

    E_min = 10000000000000000000000
    for p in range(range_X):
        E = 0
        for x in X:
            E += (x-p)**2
        if E < E_min:
            E_min = E
    print(E_min)
P=int(input())
X=list(map(int,input().split()))
l=[]
mini=10000000000000000000000
for j in range(min(X),max(X)):
    ans = [(i-j)**2 for i in X ]
    if sum(ans)<mini:
        mini = sum(ans)
print(mini)
n = int(input())
x = list(map(int, input().split()))

p0 = sum(x)//len(x)
# 123
cost = 10**9
for i in range(0,100):
    now = 0
    for i in x:
        now += abs(p0-i)**2
    if cost > now:
        cost = now

print(now)
n = int(input())
list = list(map(int, input().split()))

sum = 0
for i in list:
  sum += i
average = sum // len(list)

ans = 0
for i in list:
  ans += (i-average-1)*(i-average-1)
print(ans)
import math
n=int(input())
x=list(map(int, input().split()))

s = sum(x)
N = len(x)
mean = s / N
mean = math.ceil(mean)
r = 0

for i in range(n):
    r = r + (x[i] - mean) * (x[i] - mean)

print(r)
def main():
    print("solve abc156 C")
    n = int(input())
    x = [int(i) for i in input().split()]
    min_x = round(sum(x) / n)
    ans = sum([(min_x - i)**2 for i in x])
    print(ans)

if __name__ == "__main__":
    main()
n = int(input())
l = list(map(int, input().split()))
m = 10**5
for p in range(1, max(l)+1):
    tmp = 0
    for x in l:
        tmp += (x-p)**2
    m = min(m, tmp)

print(m)
def main():
    n = int(input())
    x = list(map(int, input().split()))

    mu = int(sum(x)/len(x)) + 1
    res = 0
    for i in x:
        res += (i - mu)**2

    print(int(res))

if __name__ == "__main__":
    main()
import numpy as np
N = input()
X = np.array([i for i in map(int,input().split())])

print(np.sum((X-np.round(sum(X)/len(X)))**2))
N = int(input())
a = list(map(int,input().split()))
ans = 10**4
for i in range(1,101):
    b = sum((a[j]-i-1)**2 for j in range(0,N))
    ans = min(ans,b)
print(ans)
n=int(input())
x=list(map(int, input().split()))
energy=0
for i in range(0,n):
    energy+=(x[i]-n)**2
    
    
print(energy)
N=int(input())
X=list(map(int,input().split()))
l=len(X)
s=10**10
for i in range(min(X),max(X)):
    x=[]
    for j in range(l):
        x.append((X[j]-i)**2)
    if s>sum(x):
        s=sum(x)
print(s)
n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) // n)

result = 0
for i in range(n):
    result += (x[i] - p) ** 2
print(result)
n=int(input())
x=[int(i) for i in input().split()]

sum=0
for i in range(n):
  sum=sum+x[i]

if (sum/n)%1==0:
  p=(sum/n)
elif (sum/n)%1<0.5:
  p=int((sum/n))
else:
  p=int((sum/n))+1
  
answer=0
for i in range(n):
  answer=answer+(x[i]-p)**2

print(answer)
# coding: utf-8
# Your code here!

n = int(input())
a = list(map(int, input().split()))
ans = 10000

for i in range(max(a)):
  x = 0
  for j in a:
    x += (i - j) ** 2
  ans = min(x, ans)

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

ans = 10000
for i in range(1, 101):
    hp = 0
    for x in X:
        hp += (x - i) ** 2
    ans = min(ans , hp)
print(ans)
n=int(input())
x_list = list(map(int,input().split()))

min = min(x_list)
max = max(x_list)

sum_min = 10000000000
for target_i in range(min, max):
    sum_tmp = 0
    for i in range(n):
        sum_tmp += (target_i - x_list[i]) ** 2
    if sum_min >= sum_tmp:
        sum_min = sum_tmp

print(sum_min)
N = int(input())
x = list(map(int, input().split()))

min_dis = 1e5
for p in range(min(x),max(x)):
    dis = 0
    for y in x:
        dis += (p-y)*(p-y)
    min_dis = min(dis, min_dis)
print(min_dis)
N = int(input())
X = input().split()
X = [int(s) for s in X]
max = max(X)

min = 0
for i in range(max):
	sum = 0
	for j in range(N):
		sum += (X[j] - i) ** 2
	if (i == 0):
		min = sum
	elif (min > sum):
		min = sum
print(min)
N = int(input())
X = list(map(int, input().split()))

total = 0
m = round(sum(X) / N)
print(m)
for i in X:
    total += (m - i) ** 2
print(total)
import numpy as np
import math
N=int(input())
X=list(map(float,input().split()))
Xmin=int(math.floor(np.min(X)));Xmax=int(math.ceil(np.max(X)))
P=np.array([i for i in range (Xmin,Xmax+1)])
Sum=np.zeros(len(P),dtype=float)
for i in range(len(P)):
    Sum[i]=np.sum((np.array(X)-P[i])*(np.array(X)-P[i]))
print(np.min(Sum))
def MinimumStamina(N, X_list):
  P = sum(X_list) / N
  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()))
print (MinimumStamina(N, X_list))