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

pos = sum(lst)/n

x1 = int(pos)
x2 = int(pos)+1

if int(pos)==pos:
    x1 = pos
    x2 = -1
else:
    x1 = int(pos)
    x2 = x1 + 1

res = 0
tmp = float('inf')
for i in range(n):
    res += (lst[i] - x1)**2
if x2 != -1:
    tmp = 0
    for i in range(n):
        tmp += (lst[i] - x2)**2
print(min(res , tmp))
N=int(input())
X=list(map(int,input().split()))
cnt=0
P=sum(X)//N
for i in range(N):
    cnt += (i-P)**2
print(cnt)
n=int(input())
x=[int(x) for x in input().split()]
ans=float("inf")
for p in range(1,101):
  s=0
  for a in x:
    s+=(p-a)^2
  ans=min(s,ans)
print(ans)
n=int(input())
s=list(map(int,input().split()))

s.sort()
minx=s[0]
maxx=s[-1]

c=10**9
for p in range(minx,maxx):
  t=0
  for i in s:
    t=t+(i-p)*(i-p)
  if c>t:
    c=t

print(c)
n = int(input())
hp = list(map(int,input().split()))
a = []
for i in range(0,n):
  s = sum((hp[j]-i-1)**2 for j in range(0,n))
  a.append(s)

print(min(a))
N = int(input())
X = list(map(int, input().split()))
 
cost = 0
 
for i in range(-50, 201):
  cand = 0
  for x in X:
    cand += (x-i)**2
  cost = min(cost, cand)
 
print(cost)
N=int(input())
X=list(map(int,input().split()))
Min=10**10
for i in range(N):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
print(Min)
N = int(input())
X = list(map(int, input().split()))

costs = []
for i in range(max(X)):
  costs.append(sum(map(lambda x: (x - i)**2, X)))

print(min(costs))
n = int(input())
l = list(map(int, input().split()))
ll = len(l)
res = 0
ans = 10000

for i in range(1, 101):
    for j in range(ll):
        res += (l[j] - i)**2
    ans = min(ans, res)
    res = 0

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

s=float("inf")
for i in range(X[0],X[-1]+1):
   d=0
   for j in X:
      d+=(j-i)**2
   s=min(s,d)
print(s)
import math
def main():
  N=int(input())
  X=list(map(int,input().split()))
  x_mean=math.ceil(sum(X)/len(X))
  sumX=0
  for i in range(len(X)):
    sumX=sumX+(X[i]-x_mean)**2
  print(sumX)

if __name__ == '__main__':
	main()
# coding: utf-8
 
a = int(input())
b=list(map(int,input().split()))
sum = 0

for i in range(a):
    sum += b[i]


ans_pre = sum/a
ans = round(ans_pre)

print(ans)
N = int(input())
X = list(map(int, input().split()))
 
P = 0
for i in range(N):
  P += X[i]/N
 
sum=0
for i in range(N):
  sum += (X[i]-P)**2
 
print(sum)
if __name__ == '__main__':
  num_resident = 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 in x_list:
      sum_ps += pow((x - i), 2)
    # print("sum: " + str(sum_ps) + " fin: " + str(fin_ps))
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)
n = int(input())
x = [int(i) for i in input().split()]
x.sort()

ans = 10000
for p in range(1,101):
  sum =0
  for i in range(n):
    sum += (x[i]-p)**2
    
  ans = min(ans,sum)
  
print(ans)
s =list( map( int, input().split()))

sum=0
for x in s:
    sum=sum+x**2
    
g=0
for x in s:
    g=g+x
    
z=[]
n=len(s)
for i in range(100):
    p=i+1
    x=n*p**2 -2*g*p +sum
    z.append(x)
print(min(z))
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)
# -*- coding: utf-8 -*-
N = int(input())
X = list(map(int, input().split()))

min_x = X[0]
max_x = X[0]
for i in range(N):
  if X[i] > max_x: max_x = X[i]
  if X[i] < min_x: min_x = X[i]

ans = 100000
for p in range(min_x, max_x+1):
  ans_p = 0
  for x in X:
    ans_p += (x-p)**2
  if ans > ans_p: ans = ans_p

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

min_ans = 10 ** 6
for i in range(1, N+1):
    ans = 0
    for x in x_list:
        ans += (i - x) ** 2
    min_ans = min(min_ans, ans)
print(min_ans)
n = int(input())

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

ans = 0

x_sum = sum(x_list)

x_sum = x_sum // n
x_sum += 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

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

ans = 10**5
for i in range(101):
    tmp = sum([(y - i)**2 for y in x])
    ans = min(ans,tmp)
print(ans)
n = input()
s = map(int,input().split())
m = 10000000
for p in range(0,101):
  t = 0
  for x in s:
    t+=(x-p)**2
  m = min(t,m)
print(m)
N = int(input())
X = list(map(int, input().split()))
ans = 10e9
for i in range(1,max(X)):
    tmp = 0
    for j in range(N):
        tmp += (X[j]-i)**2
    if tmp < ans:
        ans = tmp
#    print(tmp)
print(ans)
#import math

N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
P = 0
while P <= xList[-1]:
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)
  P +=1

result = min(dList)

if N == 1:
  result = 0

print(result)
def cal_cost(X, P):
    cost = 0
    for x in X:
        cost += (x - P) ** 2
    return cost


def main(N, X):
    """
    >>> main(2, [1, 4])
    5
    >>> main(7, [14, 14, 2, 13, 56, 2, 37])
    2354
    """
    return min(cal_cost(X, p) for p in range(max(X)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)
N = int(input())
X = list(map(int,input().split()))
ans = float('inf')
for i in range(1,N+1):
  tmp = 0
  for n in X:
    tmp+=(n-i)**2
  ans = min(ans,tmp)
print(ans)
def main():
    num = int(input())
    l = list(map(int, input().split()))
    l_sum = 0
    ans = 0
    for i in l:
        l_sum = l_sum + i
    divide = l_sum // num
    for x in l:
        ans = ans + ((x - divide)*(x - divide))
    print(ans)

main()
N = int(input())

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

max_x = max(x_list)
min_x = min(x_list)

each_value_list = []
min_value = 10e1000
for i in range(min_x, max_x):
    tmp_sum = 0
    for x in x_list:
        tmp_sum += (x - i)**2
    if min_value > tmp_sum:
        min_value = tmp_sum

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

cnt = 0
res_ = []
for i in range(0,x_[n-1]+2):
    cnt = 0
    for j in range(len(x_)):
        cnt += (x_[j] - i)**2
    res_.append(cnt)

print(min(res_))
import math
import numpy as np
N = int(input())
X = list(map(int,input().split()))
P = np.round(np.average(X))

print(np.dot(X,X) + P * P * N - 2 *np.sum(X)*P)
n = int(input())
nums = [int(i) for i in input().split()]
print(min([sum([(num-i)**2 for num in nums]) for i in range(1,n+1,1)]))
n = int(input())
arr = list(map(int,input().split()))
aprx = round(sum(arr)/n)
ans = 0
d={}
for i in arr:
  if i in d:
    ans+=d[i]
  q = ((i-aprx)**2)
  d[i] = q
  ans+=q
  
print(ans)
n = int(input())
data = list(map(int, input().split()))

p_min = min(data)
p_max = max(data)

ans_min = 100000000000000

for i in range(p_min, p_max):
  ans = 0

  for d in data:
    ans += (i-d)**2

  if ans < ans_min:
    ans_min = ans

print(ans_min)
import math
N = int(input())
x = list(map(int, input().split()))
 
t = 0
min = 0

for i in range(0,N):
     t = t +  x[i]/N

s = math.floor(t)
for i in range(0,N):
    min = min + (x[i] - s) **2

print(min)
N = int(input())
List = list(map(int,input().split()))
cost = 10**18
for i in range(min(List),max(List)):
  temp = 0
  for item in List:
    temp += (item - i)**2
  if temp < cost:
    cost = temp
print(cost)
#import math

N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
P = 0
while P < xList[-1]:
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)
  P +=1

result = min(dList)

print(result)
from statistics import mean
import math
N = (map(int, input().split()))
X = list(map(int, input().split()))
A = mean(X)
A = math.ceil(A)
a_list =[]
for i in range(0, len(X)):
    B = X[i] - A
    B =pow(B,2)
    a_list.append(B)
Sum = sum(a_list)
print(Sum)
# input
N = int(input())
X = list(map(int, input().split()))

# check
ans = 0
for i in range(max(X)):
    sub_life = sum([(j - i) ** 2 for j in X])

    if ans == 0 or ans > sub_life:
        ans = sub_life

print(ans)
N = int(input())

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

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

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

if sum(l) % n == 0:
    k = sum(l) // n
else:
    k = sum(l) // n + 1
    
ans = 0
for i in l:
    ans += (k - i) ** 2

print(ans)
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r+1):
      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())
X = list(map(int, input().split()))

A = []
for P in range(X[N-1]+1):
    for i in range(N):
        A.append((X[i]-P)**2)
    if sum(A[0:N]) < sum(A[N:2*N]) or len(A) == N:
        A = A[0:N]
    else:
        A = A[N:2*N]
print(sum(A))
N = input().rstrip()
X = list(map(int,input().split()))

P = 1
Pmin = 999

while P <= 100:
	sum = 0
	for Xi in X:
  		sum = sum + (Xi-P)**2
    
	if P == 1:
		Smin = sum
	else:
		if Smin > sum:
			Smin = sum
			Pmin = P
	P= P+1      
      
print(Pmin)
N = int(input())
A = list(map(int, input().split()))
B = []
CCC = 0
j = 1
max_A = max(A)
for j in range(100):#部屋の座標最大値までのループ
    if j == 0:
        continue
    CCC = 0
    if N == 1:
        B.append(A[0])
        break
    for k in range(N):#各部屋からの計算
        CCC += (A[k] - j) ** 2
    B.append(CCC)
x = min(B)
print(x)
# coding: utf-8
import math

n = input()
xs = map(int, raw_input().split())

avg = 1.0 * sum(xs) / n


mindist = math.ceil(sum((x - avg) ** 2 for x in xs))
print int(mindist)
import math
import sys
X = int(input())
L = list(map(int,input().split()))
if(X == 1):
    print(0)
    sys.exit()
ans = []
tmp = sum(L)/len(L)
#tmp = int(tmp)
#print("tmp",tmp)
anser = map(lambda x:(x-tmp)**2,L)
print(math.ceil(sum(anser)))
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    X = list(map(int,input().split()))
    min = float("inf")
    s = X[0]
    g = X[N-1]
    for p in range(s,g+1):
        s = 0
        for x in X:
            s += (x-p)**2
        if min >= s:
            min = s
    print(min)

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

ans=1145141919
for p in range(max(x)):
    tmp_ans=0
    for i in range(n):
        tmp_ans+=(x[i]-p)**2
    ans=min(ans,tmp_ans)
print(ans)
n = int(input())
x_list = list(map(int, input().split()))

x_ave = sum(x_list) // len(x_list)

diff_sum = 0
for x in x_list:
    diff = abs(x - x_ave)**2
    diff_sum += diff
print(diff_sum)
N = int( input())
X = list( map( int, input().split()))

v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    x += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
MAX = max(X)
res = []
if MAX == 1:
  print(1)
  sys.exit()
for a in range(1, MAX+1):
  total = 0
  for x in X:
    kyori = (x - a) * (x - a)
    total += kyori
  res.append(total)
print(min(res))
print(res)
N = int(input())
X = list(map(int, input().split()))

ans = float("inf")

i = 0
while i < max(X):
    cnt = 0
    if i not in X:
        for j in range(N):
            cnt += abs(i-X[j])**2

        ans = min(ans, cnt)

    i += 1

print(ans)
# Initializing variables
n = int(input())
x = list(map(int, input().split()))
max_X = max(x)
mini = 0
maximum = 1000000

# Calculating the minimum total of stamina
for i in range(0, max_X) :
    for j in range(n) :
        mini += (x[j] - i) ** 2
    if mini < maximum :
        maximum = mini

print(maximum)

# Check out my Youtube channel! https://www.youtube.com/channel/UCMOKVyAbTZOpKikTrX5dy_A
N = int(input())
X = list(map(int, input().split()))

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

ans = 10**9

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

  if ans > count:
    ans = count

print(ans)
import math
N = int(input())
n = input().split()
total = 0
for i in n: 
  total = total + pow((int(i)-N),2)
print(total)
N = int(input())
X = list(map(int,input().rstrip().split(" ")))
ans = 0
ansb = 0
for i in range(100):
  ansb = 0
  for i2 in range(N):
    ansb += (X[i2] - i)**2
  if ans == 0 or ans > ansb:
    ans = ansb
print(ans)
N=int(input())
K=list(map(int,input().split()))
Za=sorted(K)
S=0
T=0
for i in range(0,len(Za)):
  S+=Za[i]
  T+=Za[i]**2
G=S%N
if G==0:
  print(int(T-S**2/N))
elif G/N<0.5:
  print(int(T-S**2/N+G**2/N))
else:
  print(int(T-S**2/N+(N-G)**2/N))
N = int(input())
X = list(map(int, input().split()))

ans = 100000

for i in range(1, 101):
  num = 0
  for j in range(N):
    num += (X[j]-i)**2
  ans = min(ans, num)
print(ans)
N = int(input())

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

minv = (max(X) - min(X))**2

for i in range(100):
    temp = 0

    for j in X:
        temp += (j - i) ** 2

    if minv > temp:
        minv = temp


print(minv)
import math
N = int(input())
A = list(map(int, input().split()))
X = sum(A)/N
ans = 0
X = math.ceil(X)
for i in A:
  ans += (i-X)**2
print(ans)
n = int(input())

x = [0] * n

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

x.sort()
sum = 0
min_sum = 100 * 1000
for i in list(range(x[0], x[-1] + 1)):
    sum = 0
    for j in x:
        sum += (j - i) * (j - i)
    if sum < min_sum:
        min_sum = sum
    else:
        break
print(min_sum)
n = int(input())
x = list(map(int, input().split()))

ans = 0

for i in range(100):
    a = 0
    for j in range(n):
        a += (x[j]-i-1)**2
        print(x[j], i+1, a)
    if i == 0:
        ans += a
    else:
        ans = min(a, ans)

print(ans)
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(val)
N = int(input())
X = list(map(int, input().split()))

hp = [0 for i in range(101)]
for i in range(101):
    for j, x in enumerate(X):
        hp[i] = hp[i] + (x-(i+1))**2

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

cnt_min = 9999

for P in range(1, 101):
  cnt = 0
  for x in X:
    cnt += (P-x)**2
    
  if cnt < cnt_min:
    cnt_min = cnt
  
print(cnt_min)
n = int(input())
x = list(map(int, input().split()))
av = int(sum(x)/n)
print(sum([(i-av)**2 for i in x]))
N = int(input())
X = list(map(int, input().split()))

ans = 100000
for i in range(min(X), max(X) + 1):
    tmp_ans = 0
    for j in range(N):
        tmp_ans += (X[j] - i) ** 2 
    ans = min(ans, tmp_ans)
print(ans)
N=int(input())
a=list(map(int,input().split()))
s=[]
for i in range(10):
  m=0  
  for j in range(0,len(a)):
    m+=(a[j]-i)**2
  s.append(m)
print(min(s))
n = int(input())

x = [0] * n

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

x.sort()
sum = 0
min_sum = 100 * 1000
for i in list(range(x[0], x[-1] + 1)):
    sum = 0
    for j in x:
        sum += (j - i) * (j - i)
    if sum < min_sum:
        min_sum = sum
    else:
        print(i)
        break
print(min_sum)
N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
S = []
if X_min == X_max:
    S.append(X_min)
for x in range(X_min, X_max):
    s = 0
    for i in range(N):
        s += (X[i]-x)**2
    S.append(s)
print(min(S))
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    if r == 0:
        print(0)
    else:
        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())
X = list(map(int, input().split()))
 

cnt_min = 9999

for P in range(0, 101):
  cnt = 0
  for x in X:
    cnt += (P-x)**2
  if cnt < cnt_min:
    cnt_min = cnt
  
print(cnt_min)
# c
n = int(input())
x = [int(i) for i in input().split()]

print(  min( sum( (xx-j)**2 for xx in x ) for j in range(max(x)) ) )
N = int(input())
X = list(map(int, input().split()))
ptc = 0
tc = 100**2*100
for i in range(min(X), max(X)):
    for k in X:
        ptc += (k-i)**2
    tc = min(ptc,tc)
    ptc = 0
print(tc)
n=int(input())
xlist=list(map(int,input().split(" ")))
count=100000

for kaisai in range(101):
    sum=0
    for hito in xlist:
        sum+=(hito-kaisai)**2
    #print(sum)
    if sum<count:
        count=sum
print(count)
n=int(input())
ls=input().split(' ')
hp=0
for i in range(n):
  hp+=(int(ls[i])-n)**2
print(hp)
line1 = input('')
line2 = input('')
n = int(line1)
xs = line2.split(' ')

min = 0
for p in range(1,100):
  sum = 0
  for x in xs:
    xi = int(x)
    d = (xi - p)*(xi-p)
    sum += d
  if min == 0:
    min = sum
  if sum < min:
    min = sum

print(min)
n=int(input())
a=list(map(int,input().split()))
k=0
s=9999999999999999999999999999
for i in range(1,n+1):
  k=0
  for j in range(n):
    k+=(a[j]-i)**2
  s=min(s,k)
print(s)
n = int(input())
X = list(map(int, input().split()))

p=(sum(X)//n)+1
cnt=0
for x in X:
  cnt += (x-p)**2
  
print(cnt)
N =int(input())
X = map(int,input().split())
c = 0
for i in range(1,101):
  t=0
  for j in X:
    t += (j-i)**2

  if t<c:
    t=c
print(c)
# coding: utf-8
# Your code here!

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

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())
L=list(map(int,input().split()))
ans=10**10
for P in range(L[0],L[-1]):
    temp=0
    for l in L:
        temp+=(l-P)**2
    ans=min(temp,ans)
print(ans)
from math import ceil, floor


def tai(X, p):
    return sum((X[i] - p) ** 2 for i in range(len(X)))


if __name__ == "__main__":
    N = int(input())
    X = [int(x) for x in input().split(" ")]
    mean_x = sum(X) / N
    if mean_x == int(mean_x):
        print(tai(X, mean_x))
    else:
        print(int(min(tai(X, ceil(mean_x)), tai(X, floor(mean_x)))))
n = int(input())
hp = list(map(int,input().split()))
a = []
for i in range(0,n):
  s = 0
  for j in range(0,n):
    s+=(hp[j]-i-1)**2
  a.append(s)
  
print(min(a))
import statistics
import math

ans = 0
n = int(input())
x = list(map(int, input().split()))
m = math.ceil(statistics.mean(x))
for i in range(n):
    num = (x[i]-m)**2
    ans = ans+num

print(ans)
def main():
    a = int(input())
    l = list(map(int, input().split()))
    temp = [0]*a

    #集会の場所
    for p in range(1,a+1):
        #各人の消費体力
        for score in l:
            temp[p-1] = temp[p-1] + (score-p)**2 
    print(min(temp))
            

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

if n == 1:
    print(0)
ans = 10**10
for i in range(1,102):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
print(ans)
#n , m , l = map(int , input().split())

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]

import math

N = int(input())
list_x = list(map(int, input().split()))
bar_x = sum(list_x)/N
ans = 0
for x in list_x:
    ans += x**2/N
ans = N*(ans-bar_x**2)
print(math.ceil(ans))
n = int(input())

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

ans = 0

x_sum = sum(x_list)

x_sum = x_sum//n + 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

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

ans = 0

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

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

def kyori(x,y):
    return (x-y)**2

ave=sum(X_list)//N
av2=ave+1
print(min([sum([kyori(x,ave) for x in X_list]),sum([kyori(x,av2) for x in X_list])]))
import sys
l = sys.stdin.readline().strip()
n = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = -1
def compute_dist(p):
  dist = 0
  for n in nums:
    dist += (n-p) ** 2
  return dist
for i in range(start, end):
  d = compute_dist(i)
  if d < mi:
    mi = d
print(mi)
import math
N = int(input())
n = input().split()
total = 0
for i in n: 
  if int(i) == N:
    continue
  else:
    total = total + pow((int(i)-N),2)
print(total)
N = int(input())
X = list(map(int,input().split()))
M = round(sum(X)/N)
answer = 0
for i in X:
  answer +=(i-M)*2
print(answer)
n = int(input())
x = list(map(int, input().split()))
ans = []
l = min(x)
r = max(x)

for i in range(l, r+1):
  tmp = 0
  for j in range(n):
    tmp+= (x[j]-(i+1))*(x[j]-(i+1))
  ans.append(tmp)
print(min(ans))
N = int(input())
X = list(map(int, input().split()))
if N == 1:
  print(0)
  exit()
ans = float('inf')
for p in range(X[0], X[N - 1] + 1):
  sum = 0
  for x in X:
    sum += (x - p) ** 2
  ans = min(sum, ans)
print(ans)
N= int(input())
X = list(map(int, input().split()))
print(sum(X))
M = round(sum(X)/N)
print(M)
ans = 0
for i in X:
    print("jjk",i)
    ans += (i-M)**2
print(ans)
n = int(input())
X = list(map(int,input().split()))

ans = 9999999
for p in range(1,n+1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    ans = min(ans, s)
    
print(ans)
n = int(input())
people = list(map(int, input().split()))
P = int(sum(people)/n + 0.5)
square = sum([x ** 2 for x in people])
res = n * (P - sum(people) / n) ** 2 + square - sum(people) ** 2 / n
print(int(res))
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
X = iil()
ti = 100*100
for i in range(min(X),max(X)+1):
    cal = 0
    for item in X:
        cal += (item-i)**2
    ti = min(cal,ti)

print(ti)
N=int(input())
X=list(map(int,input().split(" ")))
P=X[0]
L=X[N-1]
sum1=0
for i in range(N):
  sum1+=(X[i]-P)*(X[i]-P)
sum2=0
for i in range(N):
  sum2+=(X[i]-P-1)*(X[i]-P-1)
while sum1>sum2:
  P+=1
  sum1=0
  sum2=0
  for i in range(N):
    sum1+=(X[i]-P)*(X[i]-P)
  for i in range(N):
    sum2+=(X[i]-P-1)*(X[i]-P-1)
print(sum1)
import sys

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


def cal(number):
    an = 0
    for X in Xn:
        an += (X - number)**2
    return an

ans = sys.maxsize
for i in range(min(Xn), max(Xn), 1):
    ans = min(ans, cal(i))

print(ans)
n=int(input())
x=list(map(int,input().split()))
x.sort()
min = 10**10
su=0
print(x)
print(x[0],x[n-1])
for j in range(x[0],x[n-1]):
    for i in x:
        su=(i-j)**2+su
    
    if min>su:
        min=su
    su = 0
print(min)
n = int(input())
a = list(map(int, input().split()))
x = 0
for i in a:
    x = x + (i-2)**2 
print(x)
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
X = [int(i) for i in input().split()]

ans = 0
X_mean = Decimal(str(sum(X) / N))
X_mean = X_mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
print(X_mean)

for i in range(N):
    ans += (X[i] - X_mean) ** 2

print(ans)
def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    sum = 0
    p = 0
    ans = 0
    anss = 0
    for i in range(N):
        sum = sum + Xs[i]
    if sum % N == 0:
        p = sum / N
    else:
        p = sum // N
    for i in range(N):
        ans = ans + ((p - Xs[i]) * (p - Xs[i]))
        anss = anss + ((p + 1 - Xs[i]) * (p + 1 - Xs[i]))
    if ans > anss:
        ans = anss
    print(ans)
resolve()
N = int(input())
num = input().split()
#print(num)
sum = 0

for i in num:
  sum = sum + int(i)

##print(sum)
ave = sum / N
ave_int = sum // N
##print(ave)
##print(ave_int)

if ave_int - ave >= 0.5:
  out = ave_int +1
else:
  out = ave_int

temp = 0
out_sum = 0

for i in num:
  temp = (out - int(i)) **2
  out_sum += temp

print(out_sum)
N = int(input())
X = list(map(int, input().split()))
sorted(X)
maxP = X[-1]
total = 1000000000000
for P in range(maxP + 1):
    tmpTotal = 0
    for tmpX in X:
#        print("{} {} {}".format(tmpX, N, (N-int(tmpX))**2))
        tmpTotal = tmpTotal + (P - int(tmpX))** 2
    if tmpTotal < total:
        total = tmpTotal

print(total)