Problem:
 Score : 300 points    Problem Statement There are N people living on a number line.  The i -th person lives at coordinate X_i .  You are going to hold a meeting that all N people have to attend.  The meeting can be held at any integer coordinate . If you choose to hold the meeting at coordinate P , the i -th person will spend (X_i - P)^2 points of stamina to attend the meeting.  Find the minimum total points of stamina the N people have to spend.      Constraints  All values in input are integers.  1 \leq N \leq 100  1 \leq X_i \leq 100         Input Input is given from Standard Input in the following format:  N  X_1  X_2  ...  X_N       Output Print the minimum total stamina the N people have to spend.        Sample Input 1 2
1 4      Sample Output 1 5  Assume the meeting is held at coordinate 2 . In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.  Note that you can hold the meeting only at an integer coordinate.       Sample Input 2 7
14 14 2 13 56 2 37      Sample Output 2 2354

Solution (Python):
n = int(input())
input_x = sorted([int(i) for i in input().split()])

ans = 10**10
for i in range(input_x[0],input_x[-1]+1):
    cost_x = sum([(x-i)**2 for x in input_x])
    if cost_x < ans:
        ans = cost_x
print(ans)

Solution (Python):

import numpy as np
import math

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

p1 = math.floor(np.mean(x))
p2 = math.ceil(np.mean(x))
ans1 = 0 
ans2 = 0 
for i in x:
    ans1 += (i-p1)**2
    ans2 += (i-p2)**2

print(min(ans1, ans2))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
T = 0
for i in range(N):
	T += X[i]
Square_Total = 0
for i in range(N):
	Square_Total += X[i]**2
K = int(N-2*T)
for i in range(100):
	K = min(N*(i**2)-2*T*int(i),K)
print(Square_Total+K)

Solution (Python):
N = int(input())
X = list(map(int,input().split(' ')))

minAns=100*100*100+1

for p in range(100+1):
    tmpAns=0
    for i in range(N):
        tmpAns+=(X[i]-p)**2
    minAns=min(minAns,tmpAns)

print(minAns)

Solution (Python):
import os
import math

def main():
    num = int(input())
    x_list = list(map(int, input().split()))
    min_num = 10**10    
    for i in range(100):
        result = 0  
        for j in x_list:
            result += pow((i - j), 2)
        
        if result < min_num:
            min_num = result
    print(min_num)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
X = list(map(int, input().split()))

min = 10**8

for i in range(100):
    de = 0
    for j in X:
        de += (j-i)**2
    if de < min:
        min = de
print(min)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
sum0=10000000000000000

for i in range(1,101):
  sum1=0
  for j in range(n):
    sum1 += (x[j]-i)**2
    
  sum0=min(sum0,sum1)
    
print(sum0)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
power = [0 for i in range(100)]

for i in range(100):
    for j in range(N):
        power[i] += (X[j]-i)**2

print(min(power))

Solution (Python):
n = int(input())
h = list(map(int,input().split()))

mean_a = int(sum(h)/len(h))
mean_b = int(sum(h)/len(h))+1

dist_a = 0
dist_b = 0
for i in range(len(h)):
    dist_a += (h[i]-mean_a)**2
    dist_b += (h[i]-mean_b)**2

print(min(dist_a,dist_b))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
E=[]
e=0
for i in range(min(X),max(X)+1):
    for j in range(len(X)):
        e+=(X[j]-i)**2
    E.append(e)
    e=0
print(min(E))

Solution (Python):
N = int(input())

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

ans = float('inf')
for p in range(1, 101):
    tairyoku = 0
    for i in range(N):
        tairyoku += (p-X[i])**2
    ans = min(tairyoku, ans)

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ave = round(sum(A)/len(A))
print(sum([(i-ave)**2 for i in A]))

Solution (Python):
N = int(input())
x = list(map(int, input().split()))
P = []

for j in range(min(x), max(x)+1):
    temp = 0
    for t in x:
        temp += (j - t)**2
    P.append(temp)

print(min(P))

Solution (Python):
a=int(input())
List=sorted(list(map(int,input().split())))
ans=10**1000
for i in range(List[0],List[a-1]+1):
    x=0
    for j in range(a):
        x+=(i-List[j])**2
    if ans>x:
        ans=x
print(ans)

Solution (Python):
n = input()
ls = list(map(int, input().split()))
mean = round(sum(ls)/len(ls))
cost = 0
for i in ls:
        cost += (abs(mean - i) ** 2)
print(cost)

Solution (Python):

 
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)

sum = 0 

for i in range(a):
    sum += (b[i]-ans)**2

print(sum)

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

S = []
for i in range(max(X)+1) :
    c = 0
    for j in range(N) :
        c +=  (X[j]-i) ** 2
    S.append(c)

print(min(S))

Solution (Python):
from statistics import mean
N=int(input())
X=[int(item)for item in input().split()]
meanX = round(mean(X))
print(sum([(X_-meanX)**2 for X_ in X]))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X2 = [i**2 for i in X]
temp1 = sum(X2)
temp2 = sum(X)
result = 0

for P in range(1, max(X) + 1):
    if P == 1:
        rsum = temp1 - 2* temp2 * P + N * P**2
    rsum = min(rsum, temp1 - 2* temp2 * P + N * P**2)

print(rsum)

Solution (Python):
from statistics import mean
import math
N=int(input())
X = [int(item) for item in input().split()]
meanX=mean(X)
underX = math.floor(meanX)
upperX = math.ceil(meanX)

underX=sum([(item-underX)**2 for item in X])
upperX=sum([(item-upperX)**2 for item in X])
print(underX if underX<upperX else upperX)

Solution (Python):
N = int(input())

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

add = []

for p in range(1000):
    psum = 0
    for i in range(N):
        power = (X[i] - p)**2
        psum = psum + power
        i = i + 1
    add.append(psum)
    
print(min(add))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 99999999
for i in range(min(x), max(x) + 1):
    sumhp = 0
    for j in x:
        sumhp += (j - i) ** 2
    ans = min(ans, sumhp)
print(ans)

Solution (Python):
n = int(input())

x = []

for y in input().split():
  x.append(int(y))
  
res = float('inf')

for i in range(100):
  cur = 0
  
  for y in x:
    cur += (y - i) ** 2
   
  res = min(res, cur)

print(res)

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


maxi = max(x)
mini = min(x)

tairyoku_1=1000000000000
tairyoku_2=0

for i in range(mini,maxi+1):
    tairyoku_2=0
    for j in x:
        tairyoku_2 += (j-i)**2
        
    tairyoku_1 = min(tairyoku_1,tairyoku_2)

print(tairyoku_1)

Solution (Python):
n = int(input())
xl = list(map(int, input().split()))

res = 10**9
for p in range(1,101):
    s = 0
    for x in xl:
        s += (x-p)**2
    res = min(res,s)

print(res)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
ans = 10**9
for i in range(min(li),max(li)+1):
    temp = 0
    for j in li:
        temp += (j - i)**2
    if temp < ans:
        ans = temp
print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
D=[]
for i in range(1,101):
    sum=0
    for j in range(len(X)):
        sum += abs(X[j]-i)**2
    D.append(sum)
print(min(D))

Solution (Python):
N = int(input())

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

minv = 1000000000000

for i in range(100):
    temp = 0

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

    if minv > temp:
        minv = temp


print(minv)

Solution (Python):
N=int(input())
X=[int(s) for s in input().split(" ")]

X.sort()

Ans=N*(X[-1]**2)
for i in range(X[-1]+1):
    Sum=0
    for j in range(N):
        Sum=Sum+(X[j]-i)**2
    if Sum<Ans:
        Ans=Sum

print(Ans)

Solution (Python):
N=int(input())
x=list(map(int,input().split()))
tairyoku_sum=[0]*100
for p in range(100):
    for i in range(N):
        tairyoku_sum[p]=(x[i]-p)**2+tairyoku_sum[p]
print(min(tairyoku_sum))

Solution (Python):
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
best_score = None
for i in range(np.min(X), np.max(X)+1):
    score = np.sum(np.power(X - i, 2))
    if best_score is None:
        best_score = score
    elif best_score > score:
        best_score = score
print(best_score)

Solution (Python):
a = int(input())
b = map(int, input().split())
ans_list =[]
list_b =list(b)
if a == 0:
    ans_list.append(0)
else:
    for i in range(max(list_b)+1):
        ene_list =map(lambda x: (x-i)**2, list_b)
        sum_ene= sum(list(ene_list))
        ans_list.append(sum_ene)


print(min(ans_list))

Solution (Python):
n=int(input())
x=tuple(map(int,input().split()))
s=sum(x)
ave=s//n+(1 if s/n>s//n+0.5 else 0) 
print(sum([pow(ave-i,2) for i in x]))

Solution (Python):
N = int(input())
X = list(map(int, input().split(' ')))

mean_X = int(round(sum(X) / N))
ans = 0
for x in X:
    ans += int((x - mean_X) ** 2)
print(ans)

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

p = sum(x)//n
p2 = round(sum(x)/n)
ans = 0
ans2 = 0
for i in range(n):
    ans += (x[i]-p)**2
for i in range(n):
    ans2 += (x[i]-p2)**2
print(min(ans, ans2))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
l = []
m = []
for i in range(min(x), max(x)+1):
    for j in range(n):
        m.append((x[j]-i)**2)
    l.append(sum(m))
    m.clear()
print(min(l))

Solution (Python):
n = int(input())
X = [int(i) for i in input().split()]
ans = []
for i in range(max(X)):
    ans.append(sum([(i+1-x)**2 for x in X]))
print(min(ans))

Solution (Python):
import math 

n=int(input())
x=list(map(int,input().split()))
a1=a2=0
g1,g2=math.ceil(sum(x)/n),math.floor(sum(x)/n)
for i in x:
    a1+=(i-g1)**2
    a2+=(i-g2)**2
print (min(a1,a2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = float('inf')
for p in range(min(X), max(X) + 1):
    cost = 0
    for x in X:
        cost += (x - p) * (x - p)
    ans = min(ans, cost)
print(ans)

Solution (Python):

N= int(input())
X =list(map(int,input().split()))
X.sort()
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)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X.sort()

ans=float('inf')
for p in range(1,101):
    buf=0
    for x in X:
        buf+=(x-p)**2
    ans=min(ans,buf)

print(ans)

Solution (Python):
def list_avr(list):
  total = sum(list)
  avr = round(total / len(list))
  return avr

health = 0
n = int(input())
x = list(map(int,input().split()))
avr = list_avr(x)

for i in range(n):
  health += (x[i]-avr)**2

print(health)

Solution (Python):
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)

Solution (Python):
from collections import deque

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


res = 10**100

avg = sum(xs)//N
mod = sum(xs)%N

for d in range(avg, avg+mod+1):
  r = 0
  for x in xs:
    r += (x-d) ** 2
  res = min(res, r)

print(res)

Solution (Python):
import sys
N = int(input())

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

if N == 1:
    print(0)
    sys.exit()

a.sort()

line = []

for i in range(a[0],a[N-1]+1):
    line.append(i)

def calculation(hairetu,P): 
    len_hairetu = len(hairetu)
    cal_result = 0
    for i in range(0,len_hairetu):
        cal_result += (hairetu[i] - P)**2
    return cal_result


def search_area(hairetu,line):
    length = len(line)
    if length < 5:
        return line
    
    half = length//2
    f_N = half//2

    f1 = half-f_N
    f3 = half+f_N
    if calculation(hairetu,f1) < calculation(hairetu,f3):
        line = line[0:half]
        search_area(hairetu,line)
    elif calculation(hairetu,f1) > calculation(hairetu,f3):
        line = line[half:length]
        search_area(hairetu,line)
    
search_area(a,line)

min = 1000000
for i in range(0,len(line)):
    if calculation(a, line[i]) < min:
        min = calculation(a,line[i])

print(min)

Solution (Python):
n= int(input())
A  = list(map(int,input().split()))
B = []

for i in range(min(A),max(A)+1):
    c = 0
    for j in range(n):
        c += (A[j]-i)**2
    B.append(c)

print(min(B))

Solution (Python):
import math
import sys

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

X.sort()
ans = sys.maxsize

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

print(ans)

Solution (Python):
import math
import sys

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

X.sort()
ans = sys.maxsize

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))[:n]

min=99999999999

for i in range(1,101):
    sum=0
    for j in a:
        sum+=(j-i) ** 2

    if sum < min: min=sum

print(min)

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))
ans = 10 ** 9
for p in range(100):
    t = 0
    for x in xs:
        t += (x - p) ** 2
    ans = min(ans, t)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X.sort()
min = 10000*100
for t in range(1, 101):
    sum = 0
    for x in X:
        sum += (x - t)**2
    if sum < min: min = sum
print(min)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n = II()
	x = LI()
	ans = 10**9
	for i in range(max(x)+1):
		tot=0
		for j in range(n):
			tot += (x[j]-i)**2
		ans = min(ans, tot)
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
div = round(sum(X) / N)
ans = 0
for i in range(N):
    ans += (X[i] - div) ** 2
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_sum = sum(X)

if X_sum % N == 0:
    div = X_sum // N
    ans = 0
    for i in range(N):
        ans += (X[i] - div) ** 2
    print(ans)
else:
    
    div_1 = X_sum // N
    ans_1 = 0
    for i in range(N):
        ans_1 += (X[i] - div_1) ** 2

    div_2 = X_sum // N + 1
    ans_2 = 0
    for i in range(N):
        ans_2 += (X[i] - div_2) ** 2
    print(min(ans_1, ans_2))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
p=round(sum(X)/len(X))
ans=0
for i in range(len(X)):
    ans+=(X[i]-p)**2
print(ans)

Solution (Python):
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)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
l=list(map(int,input().split()))
d=sum(l)//n
def dis(x):
    global l;ret=0
    for i in l:
        ret+=(x-i)**2

    return ret
print(min(dis(d),dis(d+1)))

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

avg_p = int(sum(X) / N)

cost_l = sum(map(lambda x: (x - avg_p)**2, X))
cost_r = sum(map(lambda x: (x - avg_p - 1)**2, X))

print(min(cost_l, cost_r))

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

p_min = min(X)
p_max = max(X)

ans = p_min
cost_min = N * p_max ** 2
for p in range(p_min, p_max + 1):
  tmp_cost = sum(map(lambda x: (x - p) ** 2, X))
  if tmp_cost < cost_min:
    ans = p
    cost_min = tmp_cost
    
print(cost_min)

Solution (Python):
import math
N= int(input())
nums = list(map(int,input().split()))
center = sum(nums) / N
center_down= math.floor(center)
center_up = math.ceil(center)

ans1  =sum([(center_down - i ) ** 2  for i in nums ])

ans2  =sum([(center_up- i ) ** 2  for i in nums ])

print(min(ans1,ans2))

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
E = [0] * 100

for p in range(100):
  for x in X:
    E[p] += (x - (p + 1)) ** 2

print(min(E))

Solution (Python):
import math

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

ave = 0
ans1 = 0
ans2 = 0
for i in range(len(L)):
    ave += L[i]
ave = ave / len(L)
ave_under = math.floor(ave)
ave_up = math.ceil(ave)

for i in range(len(L)):
    ans1 += (L[i] - ave_under) ** 2
    ans2 += (L[i] - ave_up) ** 2
if ans2 > ans1:
    print(ans1)
else:
    print(ans2)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
sum = 0
for i in range(n):
    sum = sum + x[i]
ave = round(sum / n)
ans = 0
for i in range(n):
    ans = ans + (ave - x[i]) * (ave - x[i])
print(ans)

Solution (Python):
n = int(input())
x_li = list(map(int,input().split()))
x_li.sort()
res = []
for x in range(x_li[0],x_li[-1]+1):
    ans = 0
    for y in x_li:
        ans+=(x-y)**2
    res.append(ans)
print(min(res))

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input()) 

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

ans = float('inf')
for i in range(101):
    t = 0
    for j in range(n):
        t += (x[j] - i) ** 2
    ans = min(ans, t)
print(ans)

Solution (Python):

sel='C'


if sel=='C':
    def ceilT(a,b): 
        return (a+b-1)//b

    N=int(input())
    X=[int(i) for i in input().split()]
    p=ceilT(sum(X),N)
    ans=sum((x-p)**2 for x in X)
    p-=1
    ans=min(ans,sum((x-p)**2 for x in X))
    print(ans)

Solution (Python):
N = int(input())
l = list(map(int,input().split()))
s = []
for i in range(101):
  x = 0
  for j in l:
    x += (j-i)**2
  s.append(x)
print(min(s))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(1,101):
    work=0
    for j in range(N):
        work+=(i-X[j])**2
    ans.append(work)

print(min(ans))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(1,101):
    work=0
    for j in range(N):
        work+=(i-X[j])**2
    ans.append(work)

print(min(ans))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(1,101):
    work=0
    for j in range(N):
        work+=(i-X[j])**2
    ans.append(work)

print(min(ans))

Solution (Python):

N = int(input())
X = [int(i) for i in input().split()]

X.sort()
s1 = sum([(X[i] - 1)**2 for i in range(N)])

c = 2
while c <= max(X):
    s2 = sum([(X[i] - c)**2 for i in range(N)])
    if s2 < s1:
        s1 = s2
    c += 1
print(s1)

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

point = sum(x)//n
sum1 = 0;sum2 = 0
for i in range(n):
    sum1 += (point - x[i])**2
    sum2 += (point+1 - x[i])**2
print(min(sum1,sum2))

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

a = round(sum(X) / len(X))

n=0

for i in X:
    n+=(int(i)-a)**2
print(n)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=10**9
for i in range(1,101):
    ans=min(ans,sum((x-i)**2 for x in X))
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
max(A)
min(A)
CHE = list(range(min(A), max(A)+1))


RES = 0
PP = []

for n in CHE:
    for i in A:
        i = int(i)
        RES += (i-n)**2
    PP.append(RES)
    RES = 0

print(min(PP))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = 1000**1000
for P in range(0,101):
    for i in range(1,N+1):
        if i == 1:
            c = (X[0]-P)**2
        else:
            c += (X[i-1] - P)**2
    if c < ans:
        ans = c
print(ans)

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

ans = 1000000
for i in range(1, 101):
    tmp=0
    for x in Xn:
        tmp += (x-i)**2
    ans = min(ans, tmp)
print(ans)

Solution (Python):

def experiment(xlist, coordinate):
    return sum( (xi-coordinate)**2 for xi in xlist)

N = input()
xlist = sorted([int(i) for i in input().split()])
s, l = xlist[0], xlist[-1]

min_stamina = float("inf")

for cord in range(s, l+1):
    min_stamina = min(min_stamina, experiment(xlist, cord))

print(min_stamina)

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

import numpy as np
x = np.array(x)
a = np.floor(np.mean(x))
b = a + 1

print(min(int(((x - a) ** 2).sum()), int(((x - b) ** 2).sum())))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans = 69*100**3
for i in range(101):
  tmp = 0
  for j in range(n):
    tmp += (i-x[j])**2
  ans = min(ans, tmp)
print(ans)

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

import math
p = round(sum(x)/n)

ans = 0
for i in range(n):
  ans = ans + x[i]**2 - 2*p*x[i] + p**2
  
print(ans)

Solution (Python):



'''
7
14 14 2 13 56 2 37
'''

import sys


sys.setrecursionlimit(1000000)

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

P = sum(x) / N
P = int(P)

res1 = sum([(x[i] - P)**2 for i in range(N)])
if P + 1 <= 100:
    res2 = sum([(x[i] - (P+1))**2 for i in range(N)])
else:
    res2 = float('inf')

print(min(res1, res2))

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
ans = 1000000
for i in range(1, 101):
    tmp=0
    for x in X:
        tmp += (x-i)**2
    ans = min(ans, tmp)
print(ans)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
N = int(input())
X = list(map(int, input().split()))

p = sum(X) / N
p = Decimal(str(p)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
ans = 0
for x in X:
    ans += (x - p) ** 2

print(ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
L=min(A)
R=max(A)
MIN=1000000000000000
for i in range(L, R+1):
    length=0
    for j in range(N):
        length+=(A[j]-i)**2
    if length<=MIN:
        MIN=length

print(MIN)

Solution (Python):
N = int(input())
l = list(map(int, input().split()))
ans = 0
ave = round(sum(l)/N)

for i in l:
    ans += (i-ave)**2

print(ans)

Solution (Python):
import math


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


mi_stamina = 1000000000
for i in range(-1000, 1000):
    def _distance(x):
        return (x-i)**2
    double_list = list(map(_distance, x_list))
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]

l = min(X)
r = max(X)
ans = 100000000000
for i in range(l, r+1):
    now = 0
    for j in range(N):
        now += (X[j]-i)*(X[j]-i)
    ans = min(now, ans)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ave = round(sum(X)/N)
s = [(i-ave)**2 for i in X]
print(sum(s))

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))

minx = min(xs)
maxx = max(xs)

cnt = 10**9
for i in range(minx, maxx + 1):
    all = 0
    for x in xs:
        all += (x - i)**2
    if cnt > all:
        cnt = all


print(cnt)

Solution (Python):
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n = load()
X = load_list()


mn = 2**100
for i in range(1, max(X)+1):
    power = sum([(x-i) * (x-i) for x in X])
    mn = min(power, mn)

print(mn)

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
x=n1()
ans=999999999
for y in range(min(x),max(x)+1):
    s=0
    for i in range(n):
        s+=(x[i]-y)**2
    ans=min(ans,s)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = []

for i in range(min(X), max(X)+1):
    ans.append(sum((x-i)**2 for x in X))

print(min(ans))

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

"""
    min(X) 以上、 max(X) 以下の整数を全探索
    1 <= X[i] <= 100 なので時間計算量は O(N(Xmax - Xmin)) <= O(N^2)
"""

X.sort()
ans = 10 ** 12

for p in range(1, 101):
    total = 0
    for x in X:
        total += (x - p)** 2
    ans = min(ans, total)
print(ans)

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

"""
    min(X) 以上、 max(X) 以下の整数を全探索
    1 <= X[i] <= 100 なので時間計算量は O(N(Xmax - Xmin)) <= O(N^2)
"""

X.sort()
ans = 10 ** 12
for p in range(X[0], X[N - 1] + 1):
    total = 0
    for x in X:
        total += (x - p)** 2
    ans = min(ans, total)
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
sum = 0
ans = 1000000
for i in range(1, 101):
    for j in range(n):
        sum += (x[j] - i)**2
    if sum < ans:
        ans = sum
    sum = 0

print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 0
ans1 = 0

p = sum(x)//n
pa = p + 1

for i in range(n):
    ans += x[i]**2

ans1 = ans + n*(pa**2)
ans1 -= 2*pa*sum(x)

ans += n*(p**2)
ans -= 2*p*sum(x)

print(min(ans, ans1))

Solution (Python):

n = int(input())

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


avg = sum(l)/n
sum = 0

if abs(avg//1 - avg) < abs(avg//1+1 - avg):
	for i in range(0,n):
		sum+=(l[i]-avg//1)**2
else:
	for i in range(0,n):
		sum+=(l[i]-avg//1-1)**2

print(int(sum))

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
b=sum(ls)
x=b//N
y=x+1
sumx=0
sumy=0
for e in ls:
  sumx+=(x-e)*(x-e)
  sumy+=(y-e)*(y-e)
print(min([sumx,sumy]))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = 10 ** 9
for p in range(1, 101):
    ans = min(ans, sum([(x - p) ** 2 for x in X]))
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

mi=min(a)
ma=max(a)

result=10**10
for i in range(mi,ma+1):
  temp=0
  for item in a:
    temp+=(item-i)**2
  result=min(result,temp)
  
print(result)

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

X_max = X[0]
X_min = X[0]

for i in range(N):
    if X_max < X[i]:
        X_max = X[i]
    if X_min > X[i]:
        X_min = X[i]

min = 0
count = 0
for p in range(X_min, X_max+1, 1):
    total = 0
    for i in range(N):
        total += (X[i]-p)**2
    count += 1
    if count == 1:
        min = total
    elif  min > total:
        min = total

print(min)

Solution (Python):
n = int(input())
s = list(map(int,input().split()))
s.sort()
ans = 10**9
for i in range(101):
  sum = 0
  for j in s:
    sum += (i-j)**2
  if sum < ans: ans = sum
  else: break  

print(ans)

Solution (Python):
N = int(input())
X  = list(map(int, input().split()))
s=[]
for p in range(10**4):
    w=[]
    for i in range(N):
        w.append((p-X[i])**2)
    s.append(sum(w))
print(min(s))

Solution (Python):
n=int(input())
inp=list(map(int,input().strip().split()))[:n]
min1=99999999
for i in range(max(inp)):
    sum1=0
    l=i+1
    for j in inp:
        sum1+=(j-l)**2
    min1=min(min1,sum1)
print(min1)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
p = int(sum(b) / len(b))
ans1 = ans2 = 0
for x in b:
    ans1 += (x - p) ** 2
    ans2 += (x - 1 - p) ** 2
if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
p = min(b)
saveans = 0
ans = 0
for x in b:
    ans += (x - p) ** 2

while p <= max(b):
    saveans = 0
    for x in b:
        saveans += (x - p) ** 2
    if saveans < ans:
        ans = saveans
    p += 1

print(ans)

Solution (Python):
n = int(input())
x_list = list(map(int, input().split()))
ans = 10**8
for p in range(1,101):
    d = 0
    for i in x_list:
        d += (i-p)**2
    ans = min(ans, d)
print(ans)

Solution (Python):
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);

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

ans = float('inf')
for P in range(1, 101):
    pow = 0
    for x in X:
        pow += (x-P)**2
    if pow < ans:
        ans = pow
print(ans)

Solution (Python):
N = int(input())
lists = list(map(int, input().split()))

lists_ave = round(sum(lists)/len(lists))
a = 0
for i in range(len(lists)):
    a += (lists[i] - lists_ave)**2

print(a)

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

P = round(sum(X) / len(X))
consume_HP = sum([(x-P)**2 for x in X])
print(consume_HP)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
m = int(sum(a)/n)
power1 = 0
power2 = 0
for ind in range(n):
    power1 += (a[ind]-m)**2
    power2 += (a[ind]-m-1)**2
print(min(power1,power2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
P = sum(X) // N
C = min(sum([(x - P)**2 for x in X]), sum([(x - (P + 1))**2 for x in X]))
print(C)

Solution (Python):
N = int(input())
X = [float(x) for x in input().split()]

P = round(sum(X)/N)
print(int(sum([(x-P)**2 for x in X])))

Solution (Python):
import numpy as np
n = int(input())
X = np.array(list(map(int,input().split())))
mean = np.mean(X)
koho1 = int(mean)
koho2 = int(mean+1)
ans1 = np.sum((X - koho1)**2)
ans2 = np.sum((X - koho2)**2)
print(min(ans1,ans2))

Solution (Python):
import sys
import math

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

ans = 10000000
for p in range(1, max(X) + 1 ):
    cost = 0
    for x in X:
        cost += (x-p)**2
    ans = min( cost ,  ans )

print(ans)