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):

import sys


def calcCost(P,X):
    sum = 0
    for x in X:
        sum+=(x-P)**2
    return sum

def solve(N: int, X: "List[int]"):
    minCost = 10**16
    m = -1
    for i in range(1,101):
        cost = calcCost(i,X)
        if cost < minCost:
            m = i
            minCost = cost
    print(str(minCost))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int(next(tokens)) for _ in range(N)]  
    solve(N, X)

if __name__ == '__main__':
    main()

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

def calc(a,x):
    return(a-x)**2

res = []
for j in range(100):
    for i in range(len(li)):
        tmp = sum(map(calc, [j+1 for x in range(len(li))],li))
        res.append(tmp)

print(min(res))

Solution (Python):
import statistics
import math

N = int(input())
input_resident = input()
resident = input_resident.split(" ")
resident_place = []
calc_array = []
result = 0
min = 100
x = 0

for i in resident:
    resident_place.append(int(i))

x = int(round(statistics.mean(resident_place),0))



for R in resident_place:
    result += (R-x)**2

print(result)

Solution (Python):
N = int(input().rstrip())
 
A = [int(n) for n in input().rstrip().split(' ')]
 
ans = []
for i in range(1, 100+1):
  temp = 0
  for j in range(len(A)):
    temp += (A[j]-i)**2
  ans.append(temp)
print(min(ans))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=100000000
for i in range(max(A)-min(A)+1):
  s=0
  for k in range(N):
    s+=(A[k]-(min(A)+i))**2
  if s<ans:
    ans=s
print(ans)

Solution (Python):
def f(a,m):
	ans =0
	for x in a:
		ans += abs(m- x)**2
	return ans
		
input()
a =list(map(int, input().split()))
a.sort()
m = (a[0] + a[-1]) //2
ans = f(a,m)
for x in range(a[0],a[-1]+1):
	ans = min(ans,f(a,x))
print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = x
y.sort()
mini = 10000000000000
for i in range(y[-1], 0, -1):
    tmp = 0
    for j in x:
        tmp += (j - i)**2
    if mini >= tmp:
        mini = tmp
print(mini)

Solution (Python):
import math
N = int(input())
A = list(map(int, input().split()))
X = sum(A)/N
ans = 0
X = format(X, ".0f")
X = int(X)
for i in A:
  ans += (i-X)**2
print(ans)

Solution (Python):
X = []
N = int(input())
X = list(map(int, input().split()))
tsum = 0
tsumMin = 10000000000000000000000000


for zahyou in range(1, 101):
    for i in range(N):
        tairyoku = (X[i] - zahyou)**2
        tsum += tairyoku
    if(tsum < tsumMin):
        tsumMin = tsum
        tsum = 0
    else:
        tsum = 0
        
print(tsumMin)

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
h =[]
for z in range(min(b),max(b)+1):
  d = 0
  for x in b:
    d = d + (x - z)**2
  h.append(d)
print(min(h))

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

xmin = min(x)
xmax = max(x)

ans = sum([(i-xmax)**2 for i in x])

for j in range(xmin,xmax):
  ans = min(ans,sum([(i-j)**2 for i in x]))

print(ans)

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

for i in range(1, 101):
  goukei = 0
  for j in x:
    basyo = int(j)
    tasu = (i - basyo) ** 2
    goukei += tasu
  if i == 1:
    r = goukei
  if goukei < r:
    r = goukei

print(r)

Solution (Python):
N = int(input())
inList = list(map(int, input().split()))
sqList = [item ** 2 for item in inList]

mySum1 = sum(inList)
mySum2 = sum(sqList)

x_p = float(mySum1) / float(N)

if x_p < 1:
  Ans = mySum2
elif x_p > 100:
  Ans = N * (100 ** 2) - 2 * (mySum1 * 100) + mySum2
else:
  x_p_int = int(x_p)
  Ans = min(N * ((x_p_int    ) ** 2) - 2 * (mySum1 * (x_p_int    )) + mySum2, 
            N * ((x_p_int + 1) ** 2) - 2 * (mySum1 * (x_p_int + 1)) + mySum2)

print(Ans)

Solution (Python):


import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        
        
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    n = int(lines[0])
    x = [int(e) for e in lines[1].split(" ")]

    return (n, x)


def solve(n, x):


    result = float('inf')
    for p in range(1, 101):
        tmp = int(sum([(e - p)**2 for e in x]))
        if tmp < result:
            result = tmp

    return  result


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Solution (Python):
input()
X = tuple(map(int, input().split()))
print(min(sum((x - p) ** 2 for x in X) for p in range(min(X), max(X) + 1)))

Solution (Python):
n = int(input())
xList = list(map(int, input().split()))
sum = 0
for x in xList:
    sum += x
sum /= n
p = round(sum)
result = 0
for x in xList:
    result += (p - x) * (p - x)
print (result)

Solution (Python):
n = int(input())
l=list(map(int ,input().split()))
ans=[]
for i in range(min(l)+1,max(l)):
    w=0
    for j in range(n):
        w+=(l[j]-i)**2
    ans.append(w)

if len(ans)==0:
    print(0)
else:
    print(min(ans))

Solution (Python):


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


import numpy as np
X=np.array(X)
Z=[i**2 for i in range(101)]
Y=X-1
S=np.array([Z[i] for i in Y])
T=np.sum(S)
for i in range(2,np.max(X)+1):
    Y=X-i
    S=np.array([Z[abs(i)] for i in Y])
    SS=np.sum(S)
    if int(SS)<int(T):
        T=SS
print(T)

Solution (Python):

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

s_max = max(s_list)
s_min = min(s_list)






j = s_min
k = 0
sum_testcase = 0

kingnum = 1000000


while j <= s_max :

    
    

    sum_testcase = 0
    k = 0

    
    while k < len(s_list) :

        
        

        temp =  (s_list[k] - j) * (s_list[k] - j)
        
        
        
        
        k = k + 1
        sum_testcase = sum_testcase + temp

    
    if sum_testcase < kingnum :
        kingnum = sum_testcase

    
    

    j = j + 1

print(kingnum)

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

l = [int(i) for i in input().split()]
l.sort()
ans = 1000000000
b = 0
for i in range(1,l[-1]+1):
    b = 0
    for j in l:
        b += (i-j)**2
    if b <ans:
        ans = b
print(ans)

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

Solution (Python):
n = int(input())
xl = list(map(int, input().split()))
ans = 0
for x in xl:
  ans += (x-1)**2

for i in range(2, 101):
  tmp = 0
  for x in xl:
    tmp += (x-i)**2
  if tmp < ans:
    ans = tmp

print(ans)

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

hp_sums = []

for i in range(max(X)):
    P = i+1
    distance_list = list(map(lambda x: (x-P)**2, X))
    hp_sum = sum(distance_list)
    hp_sums.append(hp_sum)

print(min(hp_sums))

Solution (Python):
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 = 0
  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(i == min_x):
      fin_ps = sum_ps 
      
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)

Solution (Python):
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())), dtype = 'int64')
a1 = np.min(A)
a2 = np.max(A)

ans = 1000000
for p in range(a1,a2+1):
    B = (A-p)**2
    s = np.sum(B)
    if s < ans:
        ans = s

print(ans)

Solution (Python):
import numpy as np
N=int(input())
x=list(input().split())
X = [int(i) for i in x]
X =  np.array(X)



n_max = max(X)
s0 = sum((X)**2)


for P in range(1,n_max+1):
    
    
    
    
    s = sum((X-P)**2)
    if s < s0:
        s0 = s
        P0 = P
print(s0)

Solution (Python):
n=int(input())
x=list(input().split())
x=[int(s) for s in x]
if n==1 or len(set(x))==1:
    print(0)
else:
    b_li=[]
    for i in range(min(x),max(x)):
        a_li=[]
        for j in range(n):
            a=(x[j]-i)**2
            a_li.append(a)
        b=sum(a_li)
        b_li.append(b)
    print(min(b_li))

Solution (Python):



def main():
    n = int(input())
    numbers = list(map(int, input().split(' ')))    

    max_number = max(numbers)
    min_number = min(numbers)
    min_sums = []
    for p in range(min_number, max_number + 1):
        sum_ = 0
        for x in numbers:
            sum_ += (x - p) ** 2
        min_sums.append(sum_)

    print(min(min_sums))

    return 0


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
X=list(map(int, input().split()))
l=[]
for i in range(1,101):
    L=[]
    for j in range(N):
        a=(X[j]-i)**2
        L.append(a)
    b=sum(L)
    l.append(b)


print(min(l))

Solution (Python):
n, *ps = map(int, open(0).read().split())
pave = round(sum(ps)/n)
psig = 0
for p in ps:
  psig += (p-pave)**2
print(psig)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 1000000
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)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
result = -1
for i in range(1,101):
    st = 0
    for item in X:
        st += (item - i) ** 2
    if result == -1 or result > st:
        result = st
print(result)

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort(reverse=True)
sum = []
p = 0

for k in range(X[0]):
	sum.append(0)
	p += 1
	for i in range(len(X)):
		sum[k] += abs(X[i] - p) ** 2

sum.sort(reverse=False)        
print(sum[0])

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

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

for j in range (1, 100):
    diff = 0
    sum = 0
    
    for i in range (N):
        diff = pow(R[i] - j, 2)
        sum += diff
    
    ans.append(sum)

print(min(ans))

Solution (Python):
n = int(input())
x = list(map(int,input().split(" ")))
x_max = max(x)
x_min = min(x)
l =[]

for i in range(x_min,x_max + 1):
    si = 0
    for j in range(n):
        xj = x[j]
        xj_p = (xj - i) ** 2
        si += xj_p
    l.append(si)

l.sort()
print(l[0])

Solution (Python):
num=int(input().rstrip())

position_line = input().rstrip().split(" ")



position_line2 = [int(s) for s in position_line]


position_line2.sort()


posiP=0
for i in range(num):
    posiP+=position_line2[i]

posiP=round(posiP/num) 




sum1=0

for i in range(num):
   a=(position_line2[i]-posiP)**2
   
   sum1+=a

print(sum1)

Solution (Python):
import math
n = int(input())
X = sorted(list(map(int, input().split())))
start = X[0]
end = X[-1]

ans = 10000000
for i in range(start, end+1):
    tmp = sum([(x-i)**2 for x in X])
    ans = min(tmp,ans) 
print(ans)

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

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

P = round(sum/N)

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

print(cost)

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

for i in range(100):
    hp = 0
    point = i
    for j in x:
        hp += (j - point) ** 2
        if loss < hp:
            break
    else:
        loss = hp
print(loss)

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

ans = []

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

print(min(ans))

Solution (Python):
import numpy as np

N = int(input())
X = np.sort([int(x) for x in input().split()])

ave = 0
for i in range(N):
  ave += X[i]/N
ave = int(np.round(ave))
sum = 0
for i in range(N):
  sum += (X[i]-ave)**2
print(sum)

Solution (Python):
ans=10**18
n=int(input())
a=list(map(int,input().split()))
for i in range(101):
  anstmp=0
  for x in a:
    anstmp+=(i-x)**2
  ans=min(ans,anstmp)
print(ans)

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

h=sum(x)//N
s=0
v=0

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

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

x_ave = round(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)

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

for i in range(n):
  a += k[i]
  
a = a / n 

for i in range(n):
  b += (round(a) - k[i])**2 
  
print(b)

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

place = round(sum(cords)/n)

score = sum([(i-place)**2 for i in cords])

print(score)

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

a=0
ls=[]

for i in range(1,101):
  a=0
  for j in range(n):
    a+=(x[j]-i)**2
  ls.append(a)
  
ans=min(ls)

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
x.sort()
y = []
minimum=x[0]
maximum=x[n-1]
s = 0
for i in range(minimum,maximum+1):
  for j in range(0,n):
    s = s + (x[j]-i)**2
  y.append(s)
  s = 0
  
lenlen = len(y)  
for k in range(1,lenlen):
  if y[k-1]<=y[k]:
    y[k] = y[k-1]

print(y[lenlen-1])

Solution (Python):
import math
import itertools
import statistics
n = int(input())

x = list(map(int, input().split()))
x.sort()
m = max(x)
total = [0]*m


for i in range(n):
    for p in range(1, m+1):
        total[p-1]+=abs(x[i]-p)*abs(x[i]-(p))
     
            
print(min(total))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
m = max(x)
ans = 100000000
for i in range(1,m+1):
  b = 0
  for j in x:
    b += (j-i)**2
  if b < ans:
    ans = b
print(ans)

Solution (Python):
import statistics

if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    X_cp = X.copy()
    P = round(statistics.mean(X_cp))
    ret = 0
    for i in X:
        ret += (i - P)**2
        
    print(ret)

Solution (Python):
from math import *

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

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

ave = int(round(sum / len(X), 0))

ans = 0
for i in range(len(X)):
    ans += int(pow(X[i] - ave, 2))

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):
from sys import stdin


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


def min_cost(n, data):
    cost = 1000000
    for p in range(1, 100 + 1):
        tmp_cost = sum([calc_cost(p, x) for x in data])
        if tmp_cost < cost:
            cost = tmp_cost
    return cost


def main():
    N = [int(x) for x in stdin.readline().rstrip()]
    CORP = [int(x) for x in stdin.readline().rstrip().split()]
    cost = min_cost(N, CORP)
    print(cost)


if __name__ == "__main__":
    main()

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

total = 0
p=round(sum(x)/len(x))
for ele in x:
    total += (ele-p)**2

print(total)

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

min = 100
max = 0
for i in range(n):
  if min > x[i]:
    min = x[i]
  if max < x[i]:
    max = x[i]

best = sys.maxsize
for i in range(min, max+1, 1):
  now = 0
  for j in range(n):
    now = now + (x[j] - i)**2
  if best > now:
    best = now
print(best)

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

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

if len(ans) == 0:
    print(0)
    exit()
print(min(ans))

Solution (Python):
from statistics import mean
import math
N = int(input())
X = list(map(int, input().split()))
P = round(mean(X))
ans = 0
for x in X:
    ans += (x-P)**2
print(ans)

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

distance_list = []
for i in range (1, 101):
    distance_list.append(sum(map(lambda x : (x - i) ** 2, Xs)))
print(min(distance_list))

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

result=10**18

for i in range(1,101):
    tmp=0
    for j in range(1,n+1):
        tmp+=(x[j-1]-(i))**2
    else:
        if result>tmp:
            result=tmp
            
print(result)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    N, *X = map(int, read().split())
    s = round(sum(X)/len(X))
    res = [(x - s) ** 2 for x in X]
    print(sum(res))
    
    return

if __name__ == '__main__':
    main()

Solution (Python):
c = int(input())
arr = list(map(int,input().split()))
median = round(sum(arr)/c)
product = temp = 0
for i in arr:
   temp = (i - median) ** 2
   product += temp
   temp = 0
print(product)

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


max_x = max(x)
min_x = min(x)
sum_a = [0]*(max_x+1)


for i in range(0,max_x+1):
    for j in range(0,N):
        sum_a[i] += (x[j]-i)**2


min_dis = min(sum_a)

check = min(sum_a)
ans = sum_a.index(check)
a = 0
for i in range(0,N):
    a += (x[i] - ans)**2

print(a)

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

num=sum(X)/N
num1=math.floor(num)
num2=math.ceil(num)

R1=[(X[i]-num1)**2 for i in range(N)]
R2=[(X[i]-num2)**2 for i in range(N)]
print(min(sum(R1),sum(R2)))

Solution (Python):

s = [input() for i in range(2)]

n = int(s[0])
x = [int(s) for s in s[1].split()]

mina = 0
a = max(x)
b = min(x)
for i in range(b,a+1):
    tem = 0
    for j in range(n):
        tem += (x[j]-i)*(x[j]-i)
    if(i==b or tem<mina):
        mina = tem
print(mina)

Solution (Python):
N=int(input())
X=list(map(int, input().split()))
"""
minX=min(X)
maxX=max(X)
"""
minE = 1000000000
for P in range(101):
  sum = 0
  for Xi in X:
    sum = sum + (Xi-P)**2
  if minE>sum:
    minE=sum
print(minE)

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

res = 10**10

for x in range(1,101):
    cnt = 0
    for e in a:
        cnt += (e-x)**2
    res = min(res,cnt)
print(res)

Solution (Python):
def main():
  from statistics import mean
  from math import floor,ceil

  n = int(input())
  x = list(map(int, input().split()))
  x_mean = mean(x) 
  if x_mean == 0.5:
      greater_than_x = len([i for i in x if i > x_mean])
      if greater_than_x * 2 >= n:
          x_mean = ceil(x_mean)
      else:
          x_mean = floor(x_mean)
  elif x_mean % 1 > 0.5:
      x_mean = ceil(x_mean)
  else:
      x_mean = floor(x_mean)
  x2 = [(num - x_mean)**2 for num in x]
  print(sum(x2))

main()

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
souwa = 0
kazu = len(x)
souwalist=[]
saidai = max(x)

for j in range(saidai):
	j += 1
	for i in range(kazu):
		tem = x[i]
		souwa = (tem - j) ** 2 + souwa
	souwalist.append(souwa)
	souwa = 0

print(min(souwalist))

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

for i in range(X[0],X[N-1]+1):
    ans = 0
    for j in range(N):
        ans += (X[j]-i)**2
    if ans < min:
        min = ans
    
print(min)

Solution (Python):

n=int(input())
x=list(map(int,input().split()))
    
x=sorted(x)
m=999999999999
for j in range(x[0],x[n-1]+1):
    s=0
    for i in range(n):
        s+=(x[i]-j)**2
    m=min(m,s)
    
print(m)

Solution (Python):
import numpy as np
N = input()
X = np.array([i for i in map(int,input().split())])

print(int(np.sum((X-np.round(sum(X)/len(X)))**2)))

Solution (Python):



def main():
    n = int(input())
    nums = list(map(int, input().split(' ')))    

    max_number = max(nums)
    min_number = min(nums)
    min_sums = []
    for p in range(min_number, max_number+1):
        sum_ = 0
        for x in nums:
            sum_ += (x - p) ** 2
        min_sums.append(sum_)

    print(min(min_sums))

    return 0


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
M = round(sum(X)/N)
ans = 0
for i in X:
    ans+=(i-M)**2
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())
ls=input().split(' ')
mp=[]
for i in range(int(min(ls)),int(max(ls))+1):
    hp=0
    for j in range(n):
        hp+=(i-int(ls[j]))**2
    mp.append(hp)
print(min(mp))

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

min = 10000*N

lst.sort()

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

print(min)

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

    mn = float('inf')
    for i in range(1, 101):
        mn = min(mn, calc(X, i))
    print(mn)


def calc(X, P):
    retval = 0
    for x in X:
        retval += (x - P) ** 2 
    return retval
    
if __name__ == '__main__':
    solve()

Solution (Python):
import math

def calcEnergy(goal, curr):
  return (curr - goal) * (curr - goal)

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

xs = x.copy()
xl = x.copy()

av = (int(sum(x)/n))

for i in range(n):
  xs[i] = calcEnergy(av, xs[i])
  xl[i] = calcEnergy(av + 1, xl[i])

small = sum(xs)
large = sum(xl)
if(small < large):
  print(small)
else:
  print(large)

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

l = min(x)
r = max(x)
ans = 100 ** 3
for i in range(l, r + 1):
    vit = sum(abs(xi - i) ** 2 for xi in x)
    ans = min(ans, vit)
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
if max(x)-min(x)==0:
    print(0)
else:
    k=max(x)-min(x)
    box=[0]*k

    for i in range(0,k):
        aa=0
        for j in range(0,n):
           aa = aa+(x[j]-min(x)-i)**2
        box[i]=aa


    print(min(box))

Solution (Python):
import math
n = int(input())
lx = list(map(int, input().split()))
if sum(lx)%n == 0:
  mx = int(sum(lx)/n)
  print(sum([(x - mx)**2 for x in lx]))
else:
  mx = float(sum(lx)/n)
  mxc = sum([(x - math.ceil(mx))**2 for x in lx])
  mxf = sum([(x - math.floor(mx))**2 for x in lx])
  if mxc < mxf:
    print(int(mxc))
  else:
    print(int(mxf))

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

P = round(sum(X) / N)

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

print(ans)

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

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
x = list(map(int, input().split()))
sum = res = 0

for i in range(n):
    sum += x[i]
    
p = sum / n
p = Decimal(str(p)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for i in range(n):
    res += (x[i] - Decimal(p)) ** 2
    
print(int(res))

Solution (Python):
N = int(input())
X = [int(i) for i in input().split(" ")]
XP2 = [i**2 for i in X]
sum_x = sum(X)
sum_xp2 = sum(XP2)

Min = 10000000000

for p in range(1,max(X)+1):
    M = sum_xp2 - 2*p*sum_x + (p**2)*N
    if  M < Min:
        Min = M
print(Min)

Solution (Python):
n = int(input()) 
x = list(map(int, input().split())) 
hp = []
sum = 0

for i in range(max(x)+1):
    for j in range(n):
        sum+=(x[j]-i)**2
    hp.append(sum)
    sum=0

print(min(hp))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()

if n==1:
    print(0)
    exit()

ans = Decimal(str(sum(arr)/n)).quantize(Decimal("0"),rounding=ROUND_HALF_UP)
cnt=0
for i in range(n):
    cnt+=(ans-arr[i])**2

print(cnt)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
m = 100**5
s = 0
for item in x:
    s += item

s = round(s/n)

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

print(result)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

ave = sum(x) / len(x)
p = Decimal(str(ave)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
squared = sum([i*i for i in x])

print(n*p*p - 2*p*sum(x) + squared)

Solution (Python):
N =int(input())
X = list(map(int,input().split()))
X.sort()
tans=[]
try:
  for i in range(1,X[N-1]+1):
    P=i
    ans=0
    for j in range(N):
      ans+=(X[j]-P)**2
    tans.append(ans)
  print(min(tans))
except:
  print(0)

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

p = round(sum(xi) / n)
hp = 0
for x in xi:
    hp += (x - p) ** 2

print(hp)

Solution (Python):
import numpy as np
N = int(input())
A = sorted(map(int, input().split())) 
P=round(sum(A)/len(A))
print(sum((np.array(A)-P)**2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort()
maxP = X[-1]

total = 1000000000000
for P in range(maxP + 1):
    tmpTotal = 0
    for tmpX in X:

        tmpTotal = tmpTotal + (P - int(tmpX))** 2
    if tmpTotal < total:
        total = tmpTotal

if total == 1000000000000:
    total = 0
print(total)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
max_N = max(X)
ans = 10000000000

for p in range(1, max_N+1):
    tmp = sum([(x-p)**2 for x in X])
    if tmp <= ans:
        ans = tmp
    else:
        break
print(ans)

Solution (Python):
n = int(input())
x = tuple(map(int,input().split()))
def cost(p):
    s = 0
    for i in range(0,n):
        s = s + (x[i] - p)**2
    return s
mid = round((max(x) + min(x))/2)
if cost(mid) == cost(mid + 1):
    print(cost(mid))
elif cost(mid) > cost(mid + 1):
    para = mid + 1
    for i in range(0,max(x)):
        if cost(para) <= cost(para + 1):
            print(cost(para))
            break
        para = para + 1
else:
    para = mid
    for i in range(0,max(x)):
        if cost(para) <= cost(para - 1):
            print(cost(para))
            break
        para = para - 1

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

div = round(sum(x)/len(x))
ans = 0
for i in x:
  ans += (div-i)**2
print(ans)

Solution (Python):
a = input()
x = input().split()
y = 0
d = 0
a = int(a)

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

for i in range(0,a):
  y = x[i] + y

m = y / a

for i in range(0,a):
  d = (round(m) - x[i])**2 + d
  
print(d)

Solution (Python):
import math
n = int(input())
xl = list(map(int, input().split()))
xl_cnt = len(xl)
xl_sum = sum(xl)
xl_avg = xl_sum / xl_cnt
xl_diff = map(lambda x: x - int(format(xl_avg, '.0f')), xl)
xl_double = map(lambda x: x * x, xl_diff)
print(sum(xl_double))

Solution (Python):
import statistics
import math

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

ave = round(statistics.mean(x))
sum = 0
for i in range(n):
    sum += (x[i] - ave) ** 2

print(sum)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
print(min(map(lambda p: sum((x - p) ** 2 for x in X), range(min(X), max(X)+1))))

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()))
ans = 10**8
for i in [int(sum(X)/len(X)), int(sum(X)/len(X)+0.5)]:
  ans = min(ans, sum([(j-i)*(j-i) for j in X]))
print(ans)

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

mid = round(sum(coordinates)/len(coordinates))

stamina = 0
for c in coordinates:
  stamina += (c - mid)**2
print(stamina)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip().split()
x = [None]*n
x = [int(s[i]) for i in range(0, n)]

ave = 0
for i in range(0, n):
   ave += x[i]
p1 = ave//n + 1
p2 = ave//n

sum1 = 0
sum2 = 0
for i in range(0, n):
   sum1 += pow(x[i]-p1, 2)
   sum2 += pow(x[i]-p2, 2)

if sum1 < sum2:
    print(sum1)
else:
    print(sum2)

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
import statistics
a = round(statistics.mean(li))

c = 0
for i in li:
    c += ((i - a) ** 2)
print(c)

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

m = 100000000
ans = 0

for p in range(min(x), max(x)+1):
    ans = 0

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

    if ans < m:
        m = ans


print(m)

Solution (Python):
import math


def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = 10**10
    for p in range(101):
        total = 0
        for i in range(n):
            total += (x[i]-p)**2
        ans = min(total, ans)
    print(ans)


main()

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

Solution (Python):
import numpy as np
import math

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

mn = np.mean(lst)
avg = np.ceil(mn)
avg2 = np.floor(mn)

ans = 0
ans2 = 0
for _ in lst:
    ans2 += (_ - avg2) ** 2
    ans += (_ - avg) ** 2
print(int(min(ans, ans2)))

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


res = 0

p = round(sum(L)/N)

for i in L:
    res += (i-p)**2

print(res)