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 = [int(x) for x in input().split()]

ans = 10 ** 7
for p in range(1, 101):
    s = 0
    for i in range(n):
        s += (x[i] - p) ** 2
    ans = min(ans, s)

print(ans)

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

def variance(xs,mean):
    return sum([(x-mean)**2 for x in xs])

mean = sum(xs)/N
variance1 = variance(xs,int(mean))
variance2 = variance(xs,int(mean)+1)
print(min(variance1,variance2))

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

res = float('inf')
for p in range(100+1):
    tmp = sum([(i-p)**2 for i in x])
    res = min(res, tmp)
print(res)

Solution (Python):
n = int(input())
x = list(map(int , input().split()))
g = round(sum(x) / n)

ans = 0
for xi in x:
    ans += (g - xi) ** 2
print(ans)

Solution (Python):

N=int(input())
X=list(map(int,input().split()))
cost=0
for i in range(N):
    cost+=(X[i]-1)**2
for i in range(2,101):
    cost1=0
    for j in range(N):
        cost1+=(X[j]-i)**2
    if cost1<cost:
        cost=cost1
    
print(cost)

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

print(ans)

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

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

SQ_total = 0
total = 0

for i in X:
  total += i
  SQ_total += i**2
  
ans = 100 * 100 * 2

for P in range(1,101):
  temp = N * P * P - 2 * P * total 
  ans = min(ans, temp)
  
print(SQ_total + ans)

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

ans = 0
me = int(round(np.mean(l)))

for i in range(n):
  ans += (l[i]-me)**2
print(ans)

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

ave=sum(X)//N

s1=0
s2=0

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

for i in range(N):
    s2=s2+(X[i]-ave-1)**2

print(min(s1,s2))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
a=10**9
for i in range(min(x),max(x)+1):
    b=0
    for k in range(n):
        b+=(x[k]-i)**2
    a=min(a,b)
print(a)

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

ans = 10 ** 9

x_min = min(x)
x_max = max(x)

for i in range(x_min, x_max+1):
    tmp = sum([(i-j)*(i-j) for j in x])
    if ans > tmp:
        ans = tmp

print(ans)

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

ave = 0
for i in range(N):
    ave += X[i]
ave //= N

ans1,ans2 = 0,0
for i in range(N):
    ans1 += (X[i] - ave)**2
    ans2 += (X[i] - ave-1) ** 2

print(min(ans1,ans2))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X0=(sum(X))//N
a=0
b=0
for i in range (N):
  a+=(X[i]-X0)**2
for i in range (N):
  b+=(X[i]-X0-1)**2
print(min(a,b))

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    X = list(iim())

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


if __name__ == "__main__":
    resolve()

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

X.sort()
ans = sum(X) // len(X)
ans1 = ans + 1

tmp = 0
tmp1 = 0
for i in X:
    tmp = tmp + (i - ans) ** 2
    tmp1 = tmp1 + (i - ans1) ** 2
print(min(tmp, tmp1))

Solution (Python):
import numpy as np

n = int(input())
x = np.asarray(input().split(), dtype=np.int64)

p = np.mean(x)

p = (p+0.5).astype(np.int64)

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()))
n = round(sum(x)/N)
tmp=[]
for i in range(N):
    tmp.append((x[i] - n) **2)
print(sum(tmp))

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

optimum = 10 ** 18
for i in range(1, 101):
    total = 0
    for x_i in x:
        total += (x_i - i) ** 2
    optimum = min(optimum, total)
print(optimum)

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

m = max(Xn)

ans = 10**9
for i in range(m+1):
    k = sum((x-i)**2 for x in Xn)
    ans = min(ans, k)

print(ans)

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

x = sorted(x)

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

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

    mi = min(temp, mi)

print(mi)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    xs = sorted(list(map(int, input().split())))

    min_total_energy = 1e9
    for p in range(xs[0], xs[-1] + 1):
        total_energy = 0
        for i in range(n):
            total_energy += (xs[i] - p)**2
        min_total_energy = min(min_total_energy, total_energy)

    print(min_total_energy)

Solution (Python):




import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')
def Z(f):
    if f:
        print('Yay!')
    else:
        print(':(')
def ispow(n):
    if int(n**.5)**2==n:
        return True
    return False

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

res = 10 ** 100
for i in range(-100, 200):
    tmp = 0
    for j in a:
        tmp += (i - j) ** 2
    res = min(res, tmp)
print(res)

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

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

ans = 10**31

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

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

c = [0] * 100

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

print(min(c))

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

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

def destance(a,b):
    return (a-b)**2

x_L = list(sorted(x_L))
start = x_L[0]
end = x_L[-1]

ans = 10**20
for i in range(start,end+1):
    tmp = 0
    for k,val in enumerate(x_L):
        tmp += destance(x_L[k],i)
    ans = min(ans,tmp)
print(ans)

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

avg = sum(X) // N

c1 = avg
c2 = avg + 1

ans1 = 0
ans2 = 0
for xi in X:
    ans1 += (xi - c1) ** 2
    ans2 += (xi - c2) ** 2

ans = min(ans1, ans2)
print(ans)

Solution (Python):
def read():
    N = int(input().strip())
    X = list(map(int, input().strip().split()))
    return N, X

def solve(N, X):
    smin = 1000000000
    for p in range(1, 101):
        s = sum([(x - p) ** 2 for x in X])
        smin = min(smin, s)
    return smin


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

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

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

Solution (Python):
n = int(input())
x = sorted(list(map(int,input().split())))
ans = float("inf")
def solve(p,m):
  a = len(m)
  b = 0
  for i in range(a):
    b += (m[i]-p)**2
  return b
for j in range(1,101):
  ans = min(ans,solve(j,x))
print(ans)

Solution (Python):
n=int(input())
xs=list(map(int,input().split()))
p1=sum(xs)//n
p2=(sum(xs)+n-1)//n
print(min(sum((x-p)*(x-p) for x in xs) for p in (p1,p2)))

Solution (Python):
import sys
import heapq
import copy
import numpy as np
from collections import deque

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

cnt=10**10

for p in range(min(x),max(x)+1):
    curcnt=0
    for xx in x:
        curcnt+=(xx-p)**2
    cnt=min(cnt,curcnt)
print(cnt)

Solution (Python):
def main():
    n=int(input())
    X=list(map(int,input().split()))
    ans=100**2*n
    for p in range(101):
        s = 0
        for x in X:
            s += (x-p)**2
        ans = min(ans, s)
    print(ans)
main()

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

min_sum = 10e9
for i in range(1,100):
    sum = 0
    for j in range(0,n):
        sum += (x[j]-i)*(x[j]-i)
    if sum < min_sum:
        min_sum = sum
print(min_sum)

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

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
for i in range(1,101):
  if i == 1:
    x=sum([(i-a)**2 for a in X])
  else:
    _x=sum([(i-a)**2 for a in X])
    if x<_x:
      break
    else:
      x=_x
print(x)

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

result = float("inf")

min_num = min(Xs)
max_num = max(Xs)

for i in range(min_num, max_num+1):
    temp_result = 0
    for x in Xs:
        temp_result += pow(x-i, 2)
    result = min(result, temp_result)


print(result)

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

ans=float("inf")
for i in range(1,101):
  ans=min(ans,sum([(c-i)**2 for c in l]))
print(ans)

Solution (Python):
import math
n = int(input())
x = [int(i) for i in input().split()]
ls1 = []
ls2 = []
mx = sum(x)/n
if math.ceil(mx) == math.floor(mx):
    for i in range(n):
        ls1.append((x[i]-mx)**2)
    print(int(sum(ls1)))
else:
    l = math.floor(mx)
    m = math.ceil(mx)
    for i in range(n):
        ls1.append((x[i]-l)**2)
        ls2.append((x[i]-m)**2)
    print(int(min(sum(ls1),sum(ls2))))

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

for i in range(min(x), max(x)+1):
    temp = 0

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

    ans = min(ans, temp)

print(ans)

Solution (Python):
n=int(input())
x=[int(i) for i in input().split()]
ans=10**9
for i in range(1,101):
    res=0
    for j in x:
        res+=(j-i)**2
    ans=min(ans,res)
print(ans)

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

s = 0
for i in X:
    s += i
s = s/N

muf = math.floor(s)
muc = math.ceil(s)
ansf = 0
ansc = 0
for i in X:
    ansf += (muf-i)**2
    ansc += (muc-i)**2

print(min(int(ansf),int(ansc)))

Solution (Python):
def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    ans = 10**9
    for i in range(1, 101):
        p = i
        cur = 0
        for j in range(N):
            cur += (X[j] - p)**2
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
ans = 10 ** 18

for i in range(100):
    tmp = 0
    for j in range(n):
        tmp += (arr[j] - (i + 1)) ** 2
    ans = min(tmp, ans)
print(ans)

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

ave = sum(X) / N
ave = round(ave)

ans = 0

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

Solution (Python):
n=int(input())
xlist=list(map(int,input().split()))
stamin=10**7
for i in range(1,101):
    sta=0
    for j in range(n):
        sta+=(xlist[j]-i)**2
    if stamin>sta:
        stamin=sta
print(stamin)

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

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

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

print(result)

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

m = 10 ** 10
for num1 in range(1, max(nums)+1):
    tmp = 0
    for num2 in nums:
        tmp += (num1 - num2) ** 2
    m = min(m, tmp)
print(m)

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

y = sorted(x)

cost = 0
for i in x:
    cost += (i-1)*(i-1)
mini = cost
for p in range(y[0], y[-1]+1):
    cost = 0
    for i in x:
        cost += (i-p)*(i-p)
    if cost < mini:
        mini = cost

print(mini)

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

X.sort()
ans = []
for i in range(X[0], X[-1]+1):
    tmp = 0
    for j in range(N):
        tmp += (abs(X[j]-i))**2
    ans.append(tmp)

print(min(ans))

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

def main():
    n=int(input())
    x=list(map(int,input().split()))
    mans=100**4
    for i in range(1,101):
        ans=0
        for j in x:
            ans+=(j-i)**2
        mans=min(mans,ans)
    print(mans)

if __name__ == '__main__':
    main()

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[i]-p)**2 for i in range(n)]))
print(ans)

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
a=min(X)
b=max(X)
ans=10**9
for i in range(a,b+1):
  d=0
  for j in X:
    d+=(j-i)**2
  ans=min(d,ans)    
print(ans)

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

List.sort()
ans = []

for i in range(1,100):
  sum=0
  for j in List:
    sum += (j - i) * (j-i)
  ans.append(sum)
  
print(min(ans))

Solution (Python):
mod=1000000007
n=int(input())
x=[int(i) for i in input().split()]
ans=mod**2
for i in range(1,101):
    chk=0
    for j in x:
        chk+=(j-i)**2
    ans=min(ans,chk)
print(ans)

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

Solution (Python):


stdin = open(0)
import numpy as np


data = np.fromstring(stdin.read(), np.int64, sep=' ')


X = data[1:]
costs = []
for p in range(101):
    costs.append(np.sum((X-p)**2))


answer = min(costs)
print(answer)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
hp = 0
hp_li = []
for p in range(1,101):
  hp = 0
  for k in range(n):
    hp += (li[k]-p)**2
  hp_li.append(hp)
print(min(hp_li))

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


min_sigma = 1000000000
for i in range(1,101):
    
    sigma = 0
    for j in range(N):
        sigma= sigma + (i-X[j])**2
    if min_sigma>sigma:
        min_sigma=sigma

print(min_sigma)

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

ans = 1000000000

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

Solution (Python):
import numpy as np

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

av=sum(x)/n

a=int(av)

v1=sum([(int)(i-a)*(i-a) for i in x])
v2=sum([(int)(i-a-1)*(i-a-1) for i in x])

print(min(v1,v2))

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = 100 ** 4
for cand in range(1, 101):
    tmp = 0
    for xi in x:
        tmp += (xi - cand) ** 2
    ans = min(ans, tmp)
print(ans)

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

max=max(X)
ans = (100**5)*N
for i in range(max+1):
    tmp=0
    for x in X:
        tmp+=(x-i)**2
    ans=min(ans,tmp)
print(ans)

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

min_ = float('inf')
for p in range(1, 101):
    s = 0
    for i in range(n):
        s += (X[i]-p)**2
    if s <= min_:
        min_ = s

print(min_)

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

print(ans)

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
power = []
for p in range(1,101):
    power.append(sum([(x-p)**2 for x in X]))
print(min(power))

Solution (Python):
input()
x = sorted([int(i) for i in input().split()])
cost = sum([xi**2 for xi in x])
for p in range(x[0], x[-1] + 1):
    c = 0
    for xi in x:
        c += (xi - p)**2
    cost = min(c, cost)
print(cost)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ans=0
hantei=100000000000
for i in range(100):
  ans=0
  for j in range(n):
    ans+=(x[j]-i)**2
  if hantei>ans:
    hantei=ans
print(hantei)

Solution (Python):
N = int(input())
lis = list(map(int,input().split()))
lis.sort()
S = 0
ans = 10**10
for i in range(lis[0],lis[N-1]+1):
    for j in range(N):
        S += (i-lis[j])**2
    if S < ans:
        ans = S
    S = 0
print(ans)

Solution (Python):


import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
X = LI()

p = sum(X) // N
ret = INF

for pp in range(p - 1, p + 2):
    ans = 0
    for x in X:
        ans += (x - pp)**2
    ret = min(ret, ans)

print(ret)

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

ans = set()
for p in A:
    HP = 0
    for j in range(N):
        HP += (X[j] - p) ** 2
    ans.add(HP)

print(min(ans))

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

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

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

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

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

P = int(sum(X_list) / N)

Ps = [P - 1, P, P + 1]

print(min([sum([(X - P) * (X - P) for X in X_list]) for P in Ps]))

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

answer = 9e+100

for i in range(max(x)+1):
    _sum = 0
    for _n in x:
        _sum += (_n-i)**2
    answer = min(answer, _sum)
print(answer)

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

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

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

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

ave = np.mean(lst)
ave = round(ave)
loss = [(l - ave)**2 for l in lst]
print(int(np.sum(loss)))

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

min_dist = 1 << 32

def evaluate(posi):
    ans = 0
    for i in range(N):
        ans += (X[i]-posi)**2
    return ans

for i in range(1,101):
    tmp = evaluate(i)
    if tmp < min_dist:
        min_dist = tmp

print(min_dist)

Solution (Python):
import numpy as np

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

average = np.mean(X)

m1 = int(average)
m2 = m1 + 1

ans1 = np.dot(X - m1, X - m1)
ans2 = np.dot(X - m2, X - m2)

print(min(ans1, ans2))

Solution (Python):

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

ans = 10**15
c = l[-1]+l[0]
c //= 2
for i in range(l[0],l[-1]+1):
    check = 0
    for j in l:
        check += (i-j)**2
    ans = min(check,ans)

print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
ans = 10 ** 19
for i in range(101):
  sums = sum([(x - i) ** 2 for x in X])
  ans = min(ans, sums)
  
print(ans)

Solution (Python):
N = int(input())
pe_lis = list(input().split())

result = []
for i in range(1, 101):
  base = 0
  for j in pe_lis:
    base += (int(j)-i)**2
  result.append(base)
  
print(min(result))

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

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

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

res = 100000000000000000000000000000000

t.sort()

for i in range(t[0], t[-1]+1):
    memo = 0
    for j in t:
        memo += (j-i)**2
    res = min(memo, res)

print(res)

Solution (Python):
import math

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

med = 0
for i in a:
    med += i
    
p = math.ceil(med/n)
q = math.floor(med/n)

ans1 = 0
ans2 = 0

for i in a:
    ans1 += (p-i)**2
    ans2 += (q-i)**2
    
print(min(ans1,ans2))

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

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



mn=min(xl)
mx=max(xl)
dis=[]
for p in range(mn,mx+1):
    total=0
    for i in range(n):
        total+=(xl[i]-p)**2
    dis.append(total)
print(min(dis))

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

ans = []
for i in range(max(x)):
  i+=1
  sqrt = 0
  for j in x:
    sqrt += ((i-j)**2)

  ans.append(sqrt)

print(min(ans))

Solution (Python):
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
INF = 1001001001

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

ans = INF
for i in range(1, 101):
    tmp = 0
    for j in range(N):
        tmp += (X[j] - i) * (X[j] - i)
    ans = min(ans, tmp)

print(ans)

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

Solution (Python):

n=int(input())
x=[]
x=list(map(int,input().split()))
x.sort()
cost=[]
for i in range(x[0],x[-1]+1):
    aaa=[(xx-i)**2 for xx in x]
    cost.append(sum(aaa))
ans=min(cost)
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = LIST()

a = sum(X) / N
ans1 = 0
ans2 = 0

big = int(a) + 1
small = int(a)
for i in range(N):
    ans1 += (X[i] - big) ** 2
    ans2 += (X[i] - small) ** 2
print(min(ans1, ans2))

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

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

minn=1e99
a=max(x_list)

for i in range(1,a+1):
    sumn=0
    for x in x_list:
        sumn+=(x-i)**2
    
    if sumn < minn :
        minn=sumn


print(minn)

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

ansm = 10 ** 7

for i in range(1, 101):
    s = 0
    for j in range(n):
        s += (x[j] - i) ** 2
    if s < ansm:
        ansm = s

print(ansm)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
a=sum(A)//n
b=a+1
s=0
t=0
for i in range(n):
  s=s+(A[i]-a)**2
  t=t+(A[i]-b)**2
print(min(s,t))

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def main():
  n=I()
  l=LI()

  l.sort()
  
  

  avg=sum(l)/len(l)
  center1=-(-avg//1)
  center2=int(avg)

  ans1=0
  ans2=0
  for x in l:
    ans1+=(x-center1)**2
    ans2+=(x-center2)**2

  
  return int(min(ans1,ans2))


print(main())

Solution (Python):
inputs = open(0).readlines()
n = int(inputs[0])
*X, = map(int, inputs[1].split())
p = round(sum(X) / n)
print(sum((x-p)**2 for x in X))

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


def main():
    n = int(input())
    xs = list(map(int, input().split()))
    min_score = 10000000000000000000000000000
    for p in range(1, 101):
        score = 0
        for x in xs:
            score += (x - p)**2
        min_score = min(score, min_score)

    print(min_score)


if __name__ == "__main__":
    main()

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

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

for x in xarr:
  X += x
  
mean = X//n

ans1 = 0
ans2 = 0

for x in xarr:
  ans1 += (x - mean) * (x - mean)
  ans2 += (x - mean - 1) * (x - mean - 1)

print(min(ans1, ans2))

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


List.sort()
sumList = [] 

for i in range(1,100):
	sumList.append(0)
	for j in List:
		sumList[i - 1] += (j - i)**2

sumList.sort()

print(sumList[0])

Solution (Python):
import numpy as np


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


def calc(x):
    return x**2


ans = float('inf')
for P in range(max(X)+1):
    ans = min(ans, sum(map(calc, X - np.array([P] * N))))
print(ans)

Solution (Python):
import math

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

sum_x = sum(x)
avg_x = sum_x / n

p = math.floor(avg_x + 0.5)

ans = sum((xi - p) ** 2  for xi in x)
print(ans)

Solution (Python):
N = int(input())
X = sorted(map(int, input().split()))
answer = float('inf')
for i in range(X[0], X[-1]+1):
    cost = 0
    for Xn in X:
        cost += (Xn - i)**2
    if answer > cost:
        answer = cost

print(answer)

Solution (Python):
import sys


def main(S):
    pass


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

    m = int(sum(x) / n)

    ans = 10000000000
    for i in range(4):
        tmp = 0
        for j in range(n):
            tmp += pow((x[j] - (m - 1 + i)), 2)
        ans = min(ans, tmp)

    print(ans)

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

ans = float('inf')
for i in range(1, 101):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)
print(ans)

Solution (Python):

import sys


def solve(N: int, X: "List[int]"):
    result = 10 ** 9
    for p in range(1, 100 + 1):
        cost = 0
        for i in range(N):
            cost += (X[i] - p) ** 2

        result = min(result, cost)
    print(result)
    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())
X = list(map(int, input().split()))

X.sort()
temp = 10**10
a = 0
for i in range(X[0], X[N-1]+1):
    a = 0
    for j in X:
        a += (j - i) ** 2
    if a < temp:
        temp = a

print(temp)

Solution (Python):
n=int(input())
X=list(map(int, input().split()))
goukei=sum(X)
heikin=int(goukei/n)
heikin2=heikin+1
ans1=0
ans2=0
for x in X:
    ans1+=(x-heikin)**2
    ans2+=(x-heikin2)**2
print(min(ans1,ans2))

Solution (Python):
import math

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

avg = 0
for i in x:
    avg += i
avg = round(avg/n)

result = 0
for i in x:
    result += math.pow(avg-i, 2)

print(int(result))

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

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


total_ = 0
m = 100000000000000000000000000000000000

for i in range(100):
    for j in A:
        total_ += (j - i)**2
    if total_ < m:
        m = total_
    total_ = 0
print(m)

Solution (Python):
import numpy as np
n = int(input())
x = np.array([int(i) for i in input().split(" ")])
a = np.mean(x)
if a % 1 >0.5:
    a = int(a//1) + 1
else:
    a = int(a//1)
print(np.sum((x-a)**2))

Solution (Python):
import collections

N=int(input())
X=list(map(int,input().split()))
X.sort(reverse=True)
max=X[0]
min=X[len(X)-1]
power=0
minpower=float("inf")
for i in range(min,max+1,1):
    for j in range(N):
        power=power+(i-X[j])*(i-X[j])

    if minpower>power:
        minpower=power
    power=0
print(minpower)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
mean1 = sum(x)//len(x)
mean2 = mean1+1
ans1 = 0
ans2 = 0
for num in x:
    ans1 += (num - mean1)**2
    ans2 += (num - mean2)**2
print(min(ans1,ans2))

Solution (Python):


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

def resolve():
    N=int(input())
    X=[int(i) for i in input().split()]
    mns=10**9
    for i in range(100):
        mns=min(mns,sum([cost(i,j) for j in X]))
    print(mns)






if __name__ == "__main__":
    resolve()

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

mn = 1234567890

for i in range(111):
	res = 0;
	for e in a:
		res = res + (e - i)*(e - i)
	mn = min(mn, res)

print(mn)

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

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

l.sort()


ans = 1001001001
for i in range(1, 101):
    tmp = 0
    for j in l:
        tmp += (j-i)**2
    ans = min(tmp, ans)
print(ans)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
a = min(lis)
b = max(lis)
all_lis = []

for i in range(a,b+1):
    tmp = 0
    for l in lis:
        tmp += (l-i)**2
    all_lis.append(tmp)
print(min(all_lis))

Solution (Python):

import sys
import numpy as np

def solve(N: int, X: "List[int]"):
    cost = []
    X = np.asarray(X)
    for p in range(101):
        cost.append(np.sum((X-p)**2))
    print(min(cost))
    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())
x = list(map(int, input().split()))
x_ans = round(sum(x)/len(x))
ans = 0
for i in x:
    ans += (i-x_ans)**2
print(ans)