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

def wa(avg):
    max=0
    for i in range(len(x)):
        s=x[i-1]-avg
        max=max+s**2
    return max


maxj=1000000
max=wa(1)
avg=2
while maxj>max:
    maxj=max
    max=wa(avg)
    avg=avg+1
print(maxj)

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

d_min = 10**18
for i in range(min(x), max(x)+1):
  d = 0
  for j in range(len(x)):
    d += (i-x[j])**2
    
  if d<d_min:
    d_min = d
    
print(d_min)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
minvalue = 0
list1 = []
for i in range(1, 101):
    for j in range(len(X)):
        minvalue += (X[j]-i)**2
    list1.append(minvalue)
    minvalue = 0
minvalue1 = 10**200
for x in range(len(list1)):
    if minvalue1 > list1[x]:
        minvalue1 = list1[x]
print(minvalue1)

Solution (Python):
import numpy as np
n = int(input())
x = list(map(int, input().split())) 

p = 0
x2 = np.power(x,2)

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

p = -(-xsum//n)
p2 = xsum//n

print(min(xsum2 - 2*p*xsum + n*p*p,xsum2 - 2*p2*xsum + n*p2*p2))

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

sq_mylist=[i*i for i in mylist]


coord_max=max(mylist)
sum_list=sum(mylist)
point=sum_list//N
over_point=point+1

def fun1(p):
    total=p*p*N+sum(sq_mylist)-2*p*sum_list
    return total

print(min(fun1(point),fun1(over_point)))

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

mi = min(x)
ma = max(x)

a = 0
for i in range(mi, ma+1):
    s = 0
    for j in x:
        s += pow(j - i, 2)
    if a == 0:
        a = s
    else:
        a = min(a, s)
print(a)

Solution (Python):
N=int(input())
X= list(map(int, input().split())) 
K=max(X)
Y=0
for j in range(N):
    Y=Y+X[j]**2
for i in range(K+1):
    S=0
    for l in range(N):
        S=S+(X[l]-i)**2
    if S<Y:
        Y=S
print(Y)

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

spot = round(sum(X) / len(X))
stamina = 0
for x in X:
    stamina += pow(x - spot, 2)

print(stamina)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
min_total = 0
X_ = sum(X) // len(X)

for i in range(2):
    total = 0
    for j in range(N):
        total += (X[j] - (X_ + i)) ** 2
    if i == 0 or min_total >= total:
        min_total = total
print(min_total)

Solution (Python):

N = int(input())
x_list = list(map(int, input().split()))
maxValue = max(x_list)
minValue = 1000000
for i in range(1,100):
    ans = 0
    for j in range(N):
        ans += ( x_list[j] - i ) **2

    if(ans < minValue):
        minValue = ans

print(minValue)

Solution (Python):
import numpy as np
N = int(input())
X = list(map(int, input().split()))
x = np.array(X)
ans = 100000000000
for i in range (0,101):
    b = np.array([i]*N)
    c = x -b
    tem = np.square(c)
    tem_ans = np.sum(tem)
    if ans >= tem_ans:
        ans = tem_ans
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split())) 
    a=round(sum(A)/N)
    total=0
    for i in range(N):
        total+=(A[i]-a)*(A[i]-a)
    print(total)
main()

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

MaxCoo = max(X)
MinCoo = min(X)
ave = (MaxCoo + MinCoo)//2
Range = MaxCoo - MinCoo + 2
MinCost = 10**12
for i in range(Range//2):
    pos = ave + i
    cost = 0
    for member in X:
        cost += (member-pos)**2
    if cost < MinCost:
        MinCost = cost

    pos = ave - i
    cost = 0
    for member in X:
        cost += (member-pos)**2
    if cost < MinCost:
        MinCost = cost
print(MinCost)

Solution (Python):
N = int(input())
inX = input().split()
X = []
a = 0
for x in inX:
	X.append(int(x))
	a += int(x)
P = round(a / N)


sum = 0
for x in X:
	sum += (x - P) * (x - P)

print(sum)

Solution (Python):
n=int(input())
ls=input().split(' ')
mp=[]
for i in range(100):
    hp=0
    for j in range(n):
        hp+=(i-int(ls[j]))**2
    mp.append(hp)
print(min(mp))

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

min_X = min(X_list)
max_X = max(X_list)

min_cost = 0
for p in range(min_X, max_X + 1):

    cost = 0
    for i in range(N):
        cost += (X_list[i] - p) ** 2
    
    if cost < min_cost or min_cost == 0:
        min_cost = cost

print(min_cost)

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

Solution (Python):
def main():
	n = int(input())
	X=list(map(int, input().split()))
	wa = 10000000000000000
	for i in range(min(X),max(X)+1):
		dmy_wa = sum(list(map(lambda x:(x-i)**2, X)))
		if dmy_wa < wa:
			wa=dmy_wa
	print(wa)
main()

Solution (Python):
import math

n = int(input().rstrip())
x = [0] * (n)

line = input().rstrip().split(' ')
sum = 0
for i in range(n):
    x[i] = int(line[i])
    sum += x[i]

ave = int(round((sum / n), 0)) 

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

print(ans)

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

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

physical_min = float('inf')
for p in range(min(X), max(X)+1):
    physical_total = 0
    for x in X:
        physical_total += (x-p)**2
    if physical_total < physical_min:
        physical_min = physical_total
print(physical_min)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X.sort()
m=10**18
for p in range(102):
    s=0
    for i in range(N):
       s+= (X[i]-p)**2
    if(m>s): m=s
print(m)

Solution (Python):
import numpy as np

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

m = int(np.median(x))
k = int(np.std(x))
ans = max(x) ** 2 * n





low = max(1, m - k)
high = min(m + k, np.max(x))

for i in range(low, high+1, 1):
  cost = 0
  for j in range (n):
    cost += (x[j] - i) ** 2
  
  if cost < ans:
    ans = cost

print(ans)

Solution (Python):
import numpy as np

n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
min = np.inf

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

print(min)

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

s = sum(X)
p = s // n

ans = 100100100100
for j in range(-5, 6):
    tmp = 0
    for i in range(n):
        tmp += (X[i] - p+j)**2
    if ans > tmp:
        ans = tmp
print(ans)

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

phy = []
tmp = 0
max1 = 0
count = 0

for i in range(101):
    phy.append(i*i)

for j in range(1,max(x)+1):
    for k in range(n):
        tmp += phy[abs((j-x[k]))]
    if(max1 > tmp or count == 0):
        max1 = tmp
    count += 1
    tmp = 0

print(max1)

Solution (Python):
n,*x=map(int,open(0).read().split())

import numpy as np

xar=np.array(x)

ans=float("inf")
for p in range(0,101):
    tmp=sum((xar-p)**2)
    ans=min(ans,tmp)
    
print(int(ans))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X.sort(key=int)
P=0
out=0
for i in X:
    P+=i
P=round(P/N)

def cost(x,p):
    return (x-p)*(x-p)
for i in X:
    out+=cost(i,P)

print(out)

Solution (Python):
n = int(input())
people = list(map(int, input().split()))
P = int(sum(people)/n + 0.5)
res = sum([(P - x) ** 2 for x in people])
print(res)

Solution (Python):
import numpy as np
import math

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

p1_sum = []
p2_sum = []

p1 = math.floor((1/n) * sum(x))
p2 = math.ceil((1/n) * sum(x))

for i in x:
    p1_sum.append((p1 - i)** 2)
    p2_sum.append((p2 - i)** 2)

print(min(sum(p1_sum),sum(p2_sum)))

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

mini = (100-1)**2 * n
for p in range(1, 101):
    temp = 0
    for i in x:
        temp += (i-p)**2
    mini = min(mini, temp)

print(mini)

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

print(ans)

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

Solution (Python):
import numpy as np
N = int(input())
x = np.array(sorted(list(map(int, input().split()))),dtype = 'int64')

s = []
for p in range(x[0],x[-1]+1):
    s.append(np.sum((x-p)*(x-p)))
    
print(min(s))

Solution (Python):

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

ans = 2147483647
tmp = 0
for i in range(-1000, 1001): 
    for j in range(n):
        tmp += pow(x[j] - i, 2)
    if ans > tmp:
        ans = tmp
    tmp = 0
print(ans)

Solution (Python):
import statistics
import math

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

if ans1 > ans2:
    ans = ans2
else:
    ans = ans1
print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ans=0
pri=float('inf')
for i in range(100):
    p=i+1
    for j in range(n):
        ans+=(x[j]-p)**2
    pri=min(pri,ans)
    ans=0
print(pri)

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

sum = 0
for x in X:
    sum = sum + x

ele = sum/N
ele1 = math.ceil(ele)
ele2 = ele1-1





ans1 = 0
ans2 = 0
for x in X:
    ans1 = ans1 + (x-ele1)**2
    ans2 = ans2 + (x-ele2)**2

print(min(ans1,ans2))

Solution (Python):
import itertools

N = input()


x = input().split()

summ =0
ave =0

for ii in x:
    ave += int(ii)

ave = ave / int(N)
ave = round(ave)


for i in x:
    summ+= (int(i) - ave)**2

print(summ)

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

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

p = round(sum(x) / n)
print(sum(list(map(lambda xi: (xi - p)**2, x))))

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

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

pmin = 99999999999999999

bsum = []
for count1 in range(0,N):
    asum = []
    for count2 in range(1,100):
        asum.append(abs(X[count1]-count2)**2)
    bsum.append(asum)


for count3 in range(0,99):
    asum = 0
    for count4 in bsum:
        asum += count4[count3]
    pmin = min(pmin,asum)

print(pmin)

Solution (Python):
from collections import defaultdict,deque,Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
xx = inpl()


ans = INF
for a in range(102):
    tmp = 0
    for x in xx:
        tmp += (a-x)**2
    ans = min(ans,tmp)

print(ans)

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

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

a_min = min(a)


for i in range(100):
    z = i + a_min
    hp = 0
    for x in a:
        hp += (x - z) ** 2
    if i == 0:
        ans = hp
    if ans > hp:
        ans = hp

print(ans)

Solution (Python):
N = int(input())
X = sorted([int(x) for x in input().split()])
min_cost = 0
is_first = True
for p in range(X[0]+1, X[-1]):
    cost_sum = 0
    for x in X:
        cost_sum += (x-p)**2
    if is_first:
        min_cost = cost_sum
        is_first = False
    else:
        min_cost = min(min_cost, cost_sum)

print(min_cost)

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

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

x.sort()

s = 0
t = 0
for i in range(N):
    s += (x[i]-100)**2
    t += (x[i]-1)**2

s = max(s,t)

for i in range(1,100):
    a = 0
    for j in range(N):
        a += (x[j]- i)**2
    s = min(s, a)
    
print(s)

Solution (Python):
import random
n = int(input())
l = input().split()
l = list(map(int, l))
print(min([sum([(i-j)**2 for i in l]) for j in range(1, 10000)]))

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

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

print(ans)

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

sum=0
A=[]

for i in range(-10,int(X[N-1]+100)):
    for j in range(N):
        sum+=(X[j]-i)**2
    A.append(sum)
    sum=0

print(min(A))

Solution (Python):
b = int(input())
a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])

a2 = a.copy()

best = None

for i in range(len(a)):
    a[i] = a[i] + 1

for i in range(100):
    x = [0] * b
    for j in range(len(a)):
        a[j] = a[j] - 1
        x[j] = a[j]**2
    s = sum(x)
    if best is None or s < best:
        best = s

print(best)

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

s = input().split()

s = [int(x) for x in s]

x_max = max(s)
x_min = min(s)


    
    
def ex(pnt):
    sm = 0
    for j in s:
        sm += (pnt - j)**2
    
    return sm

result = 10 **9

for i in range(x_min,x_max+1):
    koho = ex(i)
    if(result > koho):
        result = koho

print(result)

Solution (Python):


N=int(input())

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

temp=sum(P)/len(P)
temp//=1
temp2=temp+1

ans=0
for item in P:
    ans+=(item-temp)**2
    
ans2=0
for item in P:
    ans2+=(item-temp2)**2
    
print(int(min(ans,ans2)))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
x.sort()
ans = 10**18
for i in range(x[0],x[n-1]+1):
    temp = sum(list(map(lambda x:(x-i)**2,x)))
    ans = min(ans,temp)
print(ans)

Solution (Python):



import sys
from collections import deque as deq
import math

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

S = 0
for x in X:
    S += x

S /= len(X)
f, i = math.modf(S)
if f >= 0.5:
    i += 1

S = 0
for x in X:
    S += (i - x) ** 2

print(int(S))

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

for i in range(100):
  temp = 0
  for j in range(N):
    temp += (X[j] - (i+1))**2
  if ans > temp:
    ans = temp

print(ans)

Solution (Python):
def f(p, xs):
    r = 0
    for x in xs:
        r += (x-p)**2
    return r

N, = map(int, input().split())
X = list(map(int, input().split()))
r = 10**18
for i in range(101):
    r = min(r, f(i, X))
print(r)

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

min_cnt = 10000000

for p in range(1, 100):
    cnt = 0
    for i in range(n):
        cnt += (p - x[i])**2
    if min_cnt > cnt:
        min_cnt = cnt

print(min_cnt)

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

max_x = max(x)
min_x = min(x)

ans = []
for i in range(1, 101):
  a = 0
  for xi in x:
    a += (xi - i)*(xi - i)
  ans.append(a)
  
print(min(ans))

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

myavg = sum(mylist)//N

mysum1 = 0
for m in mylist:
    mysum1 += (m-myavg)**2
mysum2 = 0
for m in mylist:
    mysum2 += (m-(myavg+1))**2
print(min(mysum1, mysum2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ave = round(sum(X) / N)
S = 0
for val in X:
    x = (val - ave) ** 2
    S = S + x
print(S)

Solution (Python):
import numpy as np

minans = 100000000

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

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

for i in range(mi, ma+1):
	ans = np.sum((X-i) ** 2)
	if ans < minans:
		minans = ans

print(minans)

Solution (Python):
import math

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

low_center = math.ceil(sum(coods)/n)
hi_center = sum(coods)//n

ans = 0

if low_center == hi_center:
    for c in coods:
        ans += (c-low_center)**2
else:
    aa = 0
    ab = 0
    for c in coods:
        aa += (c-low_center)**2
        ab += (c-hi_center)**2
    ans = min(aa, ab)
print(ans)

Solution (Python):
def main():
    _ = int(input())
    X = list(map(int, input().split()))
    min = 10**8
    i = 0
    cnt = 0

    while True:
        sum = 0
        for a in X:
            sum += (a - i) ** 2
        i += 1
        if sum < min:
            min = sum
            cnt += 1
        if i > cnt:
            break
    print(min)


if __name__ == '__main__':
    main()

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

minSum = 0
for i in range(max):
	sum = 0
	for j in range(N):
		sum += (X[j] - i-1) ** 2
	if (i == 0):
		minSum = sum
	elif (minSum > sum):
		minSum = sum
print(minSum)

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ans=float('inf')
for i in range(1,101):
    ans=min(ans,sum([(i-j)**2 for j in l]))
print(ans)

Solution (Python):
import math
import numpy as np
N = int(input())
Xs = [int(x) for x in input().split()]
best_position_float = np.average(Xs)
best_position1 = math.floor(best_position_float)
best_position2 = math.ceil(best_position_float)
cost1 = sum([(best_position1 - x)**2 for x in Xs])
cost2 = sum([(best_position2 - x)**2 for x in Xs])
best_cost = min(cost1, cost2)
print(best_cost)

Solution (Python):
n = int(input())
k = list(map(int, input().split()))
p = min(k)
counta = 0
min_ = 2147483647
if max(k) == min(k):
    print(0)
    exit()

while p != max(k):
    tmp = 0
    for i in range(0,n):
        tmp += ((k[i]-p)**2)
    if tmp < min_:
        min_ = tmp
    p += 1
print(min_)

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

count = 0
ll = []

for P in range(1, 101):
    for k in range(N):
        count += (X[k] - P) ** 2
        if k == N-1:
            ll.append(count)
            count = 0
        else:
            pass
print(min(ll))

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

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

Solution (Python):
from statistics import mean
n = input()
x_s = list(map(int,input().split()))
point_x = int(format(mean(x_s), '.0f'))
sum_e = sum([(x - point_x) ** 2 for x in x_s])
print(sum_e)

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

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

Solution (Python):


n = int(input())
x = [int(x) for x in input().split(' ')]
    
min_len =  100**2 * n

for i in range(100):
    all_len = 0
    for j in range(n):
        all_len += (x[j] - (i+1))**2

    min_len = min(min_len,all_len)

print(min_len)

Solution (Python):


import sys

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

if x == 1:
    print("0")
    sys.exit()

sta = min(san)
goa = max(san)

if sta == goa:
    print("0")
    sys.exit()

tai = 0
ans = [] 

for i in range(sta,goa):
    tai = 0
    for j in range(x):
        tai += (i - san[j])**2
    ans.append(tai)
    
print(min(ans))

Solution (Python):

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

left = min(x)
right = max(x)

min_cost = 100000000000000
min_pos=-1

for i in range(left,right+1):
  cost=0
  for j in range(n):
    cost = cost + (x[j]-i)*(x[j]-i)
  if min_cost>cost:
    min_cost=cost
    min_pos=i

print(min_cost)

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

Xm = sum(X)/N
Xmi = int(Xm)
Xmc = math.ceil(Xm)

Si = list(map(lambda x:(x-Xmi)**2, X))
Sc = list(map(lambda x:(x-Xmc)**2, X))

ans = min([sum(Si),sum(Sc)])
print(ans)

Solution (Python):
n = int(raw_input())
x = raw_input()
ints = []
for i in x.split(" "):
  ints.append(int(i))
  
tmin=922337203685477580
for p in range(1,101):
  t = 0
  for i in ints:
    t += (i - p)**2
  if t<tmin:
    tmin = t

print(tmin)

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

for i in range(min(x),max(x)+1):
  for j in x:
    total+=(j-i)**2
  else:
    ans.append(total)
    total=0
print(min(ans))

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

cog = 0
for i in range(0, N):
    cog += int(X[i])
    
cog = round(cog/N)
ans = 0
for i in range(0, N):
    ans += (int(X[i]) - cog)**2
print(ans)

Solution (Python):
def main():
    n = int(input())
    x_s = list(map(int,input().split()))
    mn = 10 ** 14

    for i in range(101):
        

        sm = sum([((x-i)**2) for x in x_s])
        if sm < mn:
            mn = sm
    print(mn)




def distance(p,x):
    return (x - p) ** 2

main()

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

ans = 0
x_mean = round(sum(X)/N)

for x in X:
    ans += abs(x-x_mean)**2
print(ans)

Solution (Python):

N = int(input())
list_number = list(map(int,input().split()))
m = round(sum(list_number) / N)
ans = 0
for ele in list_number:
    ans += (ele - m) ** 2

print(ans)

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

rangeMin=min(X)
rangeMax=max(X)+1

for i in range(rangeMin,rangeMax):
    tmp=0
    for value in X:
        tmp+=(value - i)**2
    if(minValue>tmp or minValue==-1):
        minValue=tmp


print(minValue)

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

mid = round(sum(X) / N)
hoge = 0
for i in X:
    hoge += (i - mid)** 2
    
print(hoge)

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

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

ans = 0
tmp1 = 0
tmp2  = 0

if sum_X % N == 0:
    mean = sum_X // N
    for i in range(N):
       ans += (mean-X[i]) ** 2

else:
    mean1 = sum_X // N
    mean2 = -(-sum_X//N)
    for i in range(N):
      tmp1 += (mean1-X[i]) ** 2
      tmp2 += (mean2-X[i]) ** 2
    if tmp1 <= tmp2:
        ans = tmp1
    else:
        ans = tmp2  
print(ans)

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

for i in range(n):
    x[i]-=1

cost=[0]*100

for i in range(100):
    tai=0
    for j in range(n):
        tai+=(i-x[j])**2
    cost[i]=tai

print(min(cost))

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
li.sort()
temp = 0
min = 100000000000000000000000000
for i in range(li[0], li[-1]+1):
    for k in li:
        temp += (k - i)**2
    if temp <= min:
        min = temp
    temp = 0
print(str(min))

Solution (Python):




def main():
    N = int(input())
    X = list(map(int, input().split()))
    result = []
    for n in range(1, 100):
        tmp = 0
        for x in X:
            tmp += (x - n)**2
        result.append(tmp)
    print(min(result))


if __name__ == "__main__":
    main()

Solution (Python):
import math


n= int(input())


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

sum = 0

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


sum1 = math.ceil(sum/n)
sum2 = math.floor(sum/n)

ans1 = 0
ans2 = 0

for i in range(len(x)):
    ans1 += abs(x[i]-sum1)**2
    ans2 += abs(x[i]-sum2)**2

if ans1 <= ans2:
    print(ans1)
else:
    print(ans2)

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

power = 10**18

for i in range(1, 101):
  power_i = 0
  for x_elm in x:
    power_i += (x_elm - i)**2
  power = min(power, power_i)
  
print(power)

Solution (Python):
n = int(input())
x = list(map(int, input().strip().split()))
alist=[]
pm=10e9
for p in range (min(x),max(x)+1):
    ans=0
    for xi in x:
        ans += (xi-p)**2

    if(ans<pm):
        pm=ans
print(pm)

Solution (Python):



n = int(input())

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

print(min([sum([(temp - p) ** 2 for temp in x])for p in range(min(x), max(x) + 1)]))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
S1=0
S2=0
for i in range(N):
  S1+=(X[i])*(X[i])
  S2+=X[i]
mins=S1
for i in range(min(X),max(X)+1):
  if mins>N*i*i-2*S2*i+S1:
    mins=N*i*i-2*S2*i+S1
print(mins)

Solution (Python):
n=int(input())
mk=input().split()
t=0
s=0
ans=0
for k in mk:
  pk=int(k)
  t+=pk
  s+=(pk**2)
px=round(t/n)
ans+=s+n*(px**2)-2*px*t
print(ans)

Solution (Python):
n = int(input())
xls = list(map(int, input().split()))
mx = max(xls)
res = 0
for i in range(1, mx + 1):
    s = sum((x - i) ** 2 for x in xls)
    if res == 0:
        res = s
    if s < res:
        res = s
print(res)

Solution (Python):
from statistics import mean


n = int(input())
X = list(map(int, input().split()))
m = int(mean(X))
M = m + 1

def dist(X, mean):
    out = 0
    for x in X:
        out += (x - mean) ** 2
    return out


print(min(dist(X, M), dist(X, m)))

Solution (Python):
import numpy as np
n = int(input())
x = np.array(list(map(int, input().split())))
p = np.min(x)
e = np.sum((x-p)**2)
for i in range(p+1, np.max(x)):
    tmp = np.sum((x-i)**2)
    if(e > tmp):
        e = tmp
print(e)

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

s.sort()
if len(set(s))==1:
  print(0)
else:
  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)

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

p = round(sum(x)/n)

d = sum([(i-p)**2 for i in x])

print(d)

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

c = 100000000000000000
for p in range(X[0], X[-1] + 1):
    P = sum([pow(x - p, 2) for x in X])
    if P >= c:
        break
    c = P
print(c)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(max(X)+1):
    goukei = 0
    for j in range(N):
        if i%1==0:
            goukei+=(X[j]-i)**2
    ans.append(goukei)
kotae=set(ans)
print(min(kotae))

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

ave1 = -1*(-1*sum(X)//len(X))
ave2 = ave1 - 1
dist1 = sum([(i-ave1)**2 for i in X])
dist2 = sum([(i-ave2)**2 for i in X])

print(min(dist1, dist2))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
Ans = 0
M = round(sum(X)/N)
for i in X:
    Ans +=(i-M)**2
print(Ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
d = min([sum([(k-i)**2 for k in x]) for i in range(1,101)])
print(d)

Solution (Python):
list = input().split()
N = int(list[0])
list2 = input().split()
x = 0
for i in range(N):
  x += int(list2[i])
x = x / N
x = round(x)
S = 0
for i in range(N):
  S += (int(list2[i]) - x)**2
print(S)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]


min_s = 100000000
for i in range(1, 101):
    s = 0
    for v in A:
        s += (v - i) ** 2

    min_s = min(min_s, s)

print(min_s)

Solution (Python):
import numpy as np

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

if np.mean(X)-int(np.mean(X))>=0.5:
    count=int(np.mean(X))+1
else:
    count=int(np.mean(X))    

result=0
for i in range(N):
    result+=(X[i]-count)*(X[i]-count)
print(result)

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

costs = []
for p in range(min(X), max(X)+1):
    cost = 0
    for x in X:
        cost += pow(x - p, 2)
    costs.append(cost)

print(min(costs))

Solution (Python):
import math

def round_manual(n):
    if n-int(n) >= 0.5:
        res = math.ceil(n)
    else:
        res = math.floor(n)
    return res

def resolve_c():
    n = input()
    l = list(map(int, input().split()))
    mean = sum(l) / len(l)
    res = round_manual(mean)
    ans = sum([(i-res) ** 2 for i in l])
    print(ans)
resolve_c()

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
avex = round(sum(X)/N)
sumX = 0

for x in X:
    sumX = sumX + (x - avex) ** 2    
print(sumX)

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

print(min(l))

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

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

avg = round(sum(x) / len(x))

sum = 0
for i in x :
    sum = sum + ((i - avg) * (i - avg))

print(sum)

Solution (Python):
N = int(input())
X = [int(_) for _ in input().split()]
max = 0
min = 100
for i in X:
    if max < i:
        max = i
    if min > i:
        min = i

ans = 0
for p in range(max-min):
    total = 0
    for i in X:
        total += (i-p) ** 2
    if ans == 0:
        ans = total
    if ans > total:
        ans = total
print(ans)

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

ans = float('inf')

for a in range(1, 1001):
    tmp = 0
    for b in A:
        tmp += (a - b) * (a - b)
    ans = min(ans, tmp)

print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split(' ')))
distlist = [1000000] * 101
for P in range(1, 101):
    dist = 0
    for Xi in X:
        dist += (Xi - P) ** 2
    distlist[P] = dist
print(min(distlist))

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

ans=10000000
f=0
for p in range(1,101):
  f=0
  for y in x:
    f+=(y-p)*(y-p)
  ans=min(ans,f)



print(ans)

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

p = round(sum(X)/len(X))
ans = 0
for a in X:
  ans += (a-p)*(a-p)
print(ans)

Solution (Python):
n = int(input())
x_list = input().split()
avg = 0
for i in range(n):
  x_list[i] = int(x_list[i])
  avg += x_list[i]
avg = round(avg / n)
ans = 0
for i in range(n):
  ans += (x_list[i] - avg) * (x_list[i] - avg)
print(ans)