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

x.sort()

l = x[0]
r = x[-1]

res = int(1e18)
for i in range(l, r+1):
    _res = 0
    for j in x:
        _res += (i - j) * (i - j)
    if _res < res:
        res = _res

print(res)

Solution (Python):
N = int(input())
ls = list(map(int,input().split()))
sum0 = 100*100**2
for i in range(1,100):
    sum1 = 0
    for x in ls:
        sum1 += (x-i)**2 
    sum0 = min(sum0,sum1)

print(sum0)

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

ans = 10 ** 9
for i in range(1, 101):
    for j in range(n):
        ans = min(ans, sum(map(lambda p: (p - i) ** 2, x)))
print(ans)

Solution (Python):
N = int(input())
c = list(map(int,input().split()))
ans = 10**7
for i in range(1,101):
  a = 0
  for j in c:
    a += (i-j)**2
  ans = min(ans,a)
  
print(ans)

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

res = 10**7

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

print(res)

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

res2 = 10**7
for P in range(100):
    res = 0
    for x in X:
        res += (P-x-1)**2
    if res2 > res:
        res2 = res

print(res2)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = float('inf')
for k in range(1, 101):
  a = 0
  for j in range(len(X)):
    a += (X[j]-k)**2
  ans = min(ans, a)
print(ans)

Solution (Python):
import numpy

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

X2 = X ** 2

S1 = numpy.sum(X)
S2 = numpy.sum(X2)

ans = []
for i in range(-3, 3):
    P = round(S1 / N) + i
    ans.append(S2 - 2 * S1 * P + N * P ** 2)

print(int(min(ans)))

Solution (Python):
def main():
    N = int(input())
    X = [int(x) for x in input().split()]
    avgX = round(sum(X) / len(X))
    diff = 0
    for i in range(N):
        diff += (X[i] - avgX)**2
    print(diff)

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
S=[]
for i in range(100):
  s=0
  for j in L:
    s+=(j-i)**2
  S.append(s)
S=sorted(S)
print(S[0])

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
ans = 99999999999
for i in range(1, max(X)+1):
    tmp = sum(list(map(lambda x:(x-i)**2, X)))
    ans = min(tmp, ans)

print(ans)

Solution (Python):


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

Y = [0 for x in range(100+1)]
for i in range(1, 100+1):
    Y[i] = 0
    for x in X:
        Y[i] += (i - x) ** 2

print(min(Y[1:100+1]))

Solution (Python):
import numpy as np

def Rally(n, array):
    min_ = max(np.array(array)*10**7)
    for i in range(1,max(np.array(array)+1)):
        if min_ > sum((np.array(array)-i)**2):
            min_ = sum((np.array(array)-i)**2)
    return min_

n = int(input())
array = list(map(int,input().split()))
print(Rally(n, array))

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

hplist = []

for i in range(min(x),max(x)+1):
    hp = 0
    for j in range(n):
        hp += (x[j] - i)**2
    hplist += [hp]

print(min(hplist))

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
X = LI()

X_np = np.array(X)

costs = []
for p in range(1,101):
    costs.append(np.sum((X_np - p)**2))
ans = min(costs)
print(ans)

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

if N == 1:
    print(0)
else:
   for i in range(min(li),max(li)+1):
       cost_sum = 0
       for t in range(N):
           cost_sum += (li[t]-i) ** 2
       li_2.append(cost_sum)
   print(min(li_2))

Solution (Python):
def my_round(x):
  t=str(int(x*10))
  s=len(t)
  if int(t[s-1])>4:
    return int(x)+1
  else:
    return int(x)
N=int(input())
X=list(map(int,input().split()))
ave=sum(X)/N
P=my_round(ave)
ans=0
for y in range(N):
  ans += (X[y]-P)**2
print(ans)

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    X = LI()

    ans = 10 ** 9

    for i in range(1, 101):
        sum_temp = 0
        for x in X:
            sum_temp += (x - i) ** 2

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


main()

Solution (Python):

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

ans = 99999999999

for i in range(100):
    cnt = 0

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

    ans = min(ans, cnt)

print(ans)

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

p = -1
if S % N == 0:
    p = S // N
    print(sum([(p-i)**2 for i in X]))
else:
    cand1 = (S+N) // N
    cand2 = S // N
    p1 = sum([(cand1-i)**2 for i in X])
    p2 = sum([(cand2-i)**2 for i in X])

    if p1 < p2:
        print(p1)
    else:
        print(p2)

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

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
P = int(sum(X) / N + 0.5)
ans = 0

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

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
P = int(sum(X) / N + 0.5)
ans = 0

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

print(ans)

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

ans=100000000000

for x in range(1,101):
  ans1=0
  for y in range(len(a)):
    ans1+=(x-a[y])**2
    
  ans=min(ans,ans1)
  
print(ans)

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

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

print(min(ans))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
han=999999999999999999
gou=0

for b in range(1,101):
    gou=0
    for a in X:
        gou+=(a-b)**2
    
    if gou<han:
        han=gou
print(han)

Solution (Python):

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

cand = sum(X) // N
ans0 = sum((v - cand) ** 2 for v in X)
ans1 = sum((v - cand - 1) ** 2 for v in X)
print(min(ans0, ans1))

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

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

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

print(ans)

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

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

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

L = min(X)
R = max(X)

answer_list = []
for i in range(L, R+1):
  total = 0
  
  for x in X:
    total += (x-i)**2
  answer_list.append(total)
print(min(answer_list))

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

for i in range(1, 101):
    cost = 0
    for x in X:
        cost += (i - x) ** 2
    if cost < ans:
        ans = cost

print(ans)

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

Solution (Python):

from decimal import Decimal, ROUND_HALF_UP
n = int(input())
l_x = list(map(int, input().split()))
mtg_p = Decimal(str(sum(l_x) / n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

print(sum([(x-mtg_p)**2 for x in l_x]))

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

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

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

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

print(ans)

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

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

t = []
for i in range(min(X), max(X) + 1):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for x in range(100):
    temp = 0
    for j in range(N):
        temp += (X[j] - (x)) ** 2
    ans = min(ans, temp)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 10000000
l = 0
for i in range(100):
  s = 0
  for j in range(n):
    s += pow((a[j]-(i+1)), 2)
  ans = min(s, ans)
  if(ans == s):
    l = i+1
print(ans)

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

mean = np.round(np.mean(np.array(x)))

print(int(np.sum((np.array(x)-mean)**2)))

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
saisyou = 10**7
for p in range(1,101):
    tairyoku = 0
    for x in range(N):
        tairyoku += (X[x]-p)**2
    saisyou = min(saisyou, tairyoku)

print(saisyou)

Solution (Python):
def main():

    n = int(input())
    x = list(map(int, input().split()))
    min_p = round((1 / n) * sum(x))
    stamina = sum((x[i] - min_p) ** 2 for i in range(n))
    print(stamina)

main()

Solution (Python):
N = int(input())
xxx = list(map(int, input().split()))
ans = 10**8
for P in range(100):
    acc = 0
    for i in range(N):
        acc += (xxx[i] - P) ** 2
    ans = min(ans, acc)
print(ans)

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

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

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

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

Solution (Python):
n = int(input())
nums = [int(i) for i in input().split()]
rem = 2_000_000_000
for i in range(0, 101):
  distance_sum = 0
  for x in nums:
    distance_sum += (x - i)**2
  
  if distance_sum < rem: rem = distance_sum
    
print(rem)

Solution (Python):
import numpy as np

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

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s

print(ans)

Solution (Python):
import numpy as np

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

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s

print(ans)

Solution (Python):
import numpy as np

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

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s
    p += 1

print(ans)

Solution (Python):
n=int(input())
c=sorted(list(map(int, input().split())))
b = c[-1]
l = []
ans = 0

for i in range(1,b+1):
    for k in c:
        ans += (k-i)**2
    l.append(ans)
    ans = 0

print(min(l))

Solution (Python):
import numpy as np
N=int(input())
X=np.array(list(map(int, input().split())))

MIN=100000000
for p in range(1,101):
  SUM=((X-p)**2).sum()
  if MIN>SUM:MIN=SUM
print(MIN)

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

l = []

for p in range(x[0], x[-1] + 1):
  ans = 0
  for i in range(n):
    ans += (x[i] - p) ** 2
  l.append(ans)
print(min(l))

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
P = [p for p in range(1, max(X) + 1)]
min = 0
energy = 0

for x in X:
    min += (1 - x) ** 2

for p in P:
    for x in X:
        energy += (x - p) ** 2

    if energy < min:
        min = energy
    energy = 0
print(min)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
Xmin = min(X)
Xmax = max(X)
HP = [0] * (Xmax - Xmin + 1)
P = Xmin
while P <= Xmax :
    for i in range(N) :
        HP[P-Xmin] += (X[i] - P) ** 2
    P += 1
print(min(HP))

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

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

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = il()
    X = sum(D) // N
    ret = MAX
    for x in range(X - 3, X + 3):
        tmp = 0
        for d in D:
            tmp += (d - x) ** 2
        ret = min(ret, tmp)
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
if __name__ == '__main__':
	n = int(input())
	A = list(map(int,input().split()))
	ma = max(A) + 1
	ans = 1000000
	for x in range(1,ma):
		tmp = 0
		for y in A:
			tmp2 = (y-x)*(y-x)
			tmp += tmp2
		ans = min(ans,tmp)
	
	print(ans)

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

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

Solution (Python):
from statistics import median, mean

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

INF = float('inf')
res = INF
for a in range(min(X), max(X)+1):
  tmp = 0
  for x in X:
    tmp += (x-a) * (x-a)
  res = min(tmp, res)
  
print(res)

Solution (Python):
import sys
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
X.sort()

INF = 10**9+7
ans = INF
for p in range(0, 102):
    res = 0
    for x in X:
        res += (p-x)**2
    ans = min(ans, res)
print(ans)

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

su = sum(x)//n

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (x[i]-su)**2
for i in range(n):
    ans2 += (x[i]-su-1)**2

print(min(ans1,ans2))

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

Solution (Python):
import sys

def main():
    N = int(input())
    X = sorted(list(map(int, input().split())))
    ans = sys.float_info.max
    for p in range(X[0], X[-1]+1):
        hp = sum([(p - x) ** 2 for x in X])
        if hp < ans:
            ans = hp
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 10**100

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

print(ans)

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

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

Solution (Python):
def main():
    n = int(input())
    x = list(map(int, input().split()))
    min = 10000000000
    for point in range(10000):
        s = sum([(i - point)**2 for i in x])
        if s < min:
            min = s
    print(min)


if __name__ == "__main__":
    main()

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

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

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

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

print(ans)

Solution (Python):
n,*x=map(int,open(0).read().split())
sum_min=10**100
for  i in range(min(x),max(x)+1):
    sum=0
    for j in x:
        sum+=(j-i)**2
    sum_min=min(sum_min,sum)
print(sum_min)

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

Min = 10**9

for i in range(1,100):

    Sum = 0

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

    Min = min(Min,Sum)
    
print(Min)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
def meeting_cost(P,List):
    cost = 0
    for i in List:
        cost += (i - P)**2
    return cost
result = {}
for P in range(1, 101):
    result[P] = meeting_cost(P, X)
print(min(result.values()))

Solution (Python):
def main():
    N = int(input())
    X = list(map(int, input().split()))
    ans = 10**11
    for i in range(0,101):
        temp = 0
        for x in X:
            temp += (x-i)**2
        ans = min(temp,ans)

    print (ans)


if __name__ == '__main__':
    main()

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


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

print(ans)

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

Solution (Python):

def main():
    N = int(input())
    X = list(map(int, input().split()))
    min = 10000000000
    for venue in range(1, 101):
        sum = 0
        for i in range(N):
            if sum > min:
                break
            
            sum += (venue - X[i])**2
        if sum < min:
            min = sum
    print(min)

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    N = int(input())
    X = list(map(int, input().split()))
    min = 10000000000
    for venue in range(1, 101):
        sum = 0
        for i in range(N):
            if sum > min:
                break
            
            sum += (venue - X[i])**2
        if sum < min:
            min = sum
    print(min)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
p = list(map(int,input().split(" ")))
d_list = []
for i in range(100):
  d = 0
  for j in p:
    d += abs(j-i+1)**2
  d_list.append(d)

print(min(d_list))

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

a = sum(Xlist)/N

a_m = int(a)
a_p = a_m + 1

if a - a_m < a_p - a:
    p = a_m
else:
    p = a_p

ans = 0
for i in range(N):
    ans += (Xlist[i] - p)**2

print(ans)

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

s = sum(x)
avg = s // n

t = u = 0
for e in x:
    t += (e - avg)**2
    u += (e - (avg + 1))**2

print(min([t, u]))

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

s = sum(x)
avg = s // n

t = 0
for e in x:
    t += (e - avg)**2

u = 0
for e in x:
    u += (e - (avg + 1))**2

print(min([t, u]))

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

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

ans = 1000000000
for i in range(101):
    sum = 0
    for j in x:
        sum += pow(j - i, 2)
    ans = min(ans, sum)

print(ans)

Solution (Python):

N = int(input())
an = list(map(int,input().split()))
Min = 10**10

for i in range(1,102):
    k = 0
    for j in an:
        k += (j-i)**2
    if Min >k:
        Min = k
        
print(Min)

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

Solution (Python):
import numpy as np
N = int(input())
X = np.array([int(_) for _ in input().split()], dtype=int)
print(min(np.sum((X - i)** 2) for i in range(1, 101)))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x.sort()
def sump(x,p):
  s=0
  for a in x:
    s+=(a-p)**2
  return s
m=min(x)
M=max(x)
ans=[]
for p in range(m,M+1):
  ans.append(sump(x,p))
print(min(ans))

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

n, s = int(input()), list(map(int, input().split()))
def solve():
	for i in range(100):
		x = 0
		for e in s: x += (i+1 - e) ** 2
		yield x
print(min(solve()))

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

for i in range(1, 101):
  t = 0
  for j in x:
    t += (i-j)**2
  l.append(t)
    
print(min(l))

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
cost = float("inf")
for i in range(1,101):
    c = 0
    for j in X:
        c += (j - i)**2
    cost = min(cost, c)
print(cost)

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

Solution (Python):
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    mt = 10**10
    for ii in range(x[0],x[-1]+1):
        ans = 0
        for i in x:
            ans += (i-ii)**2
        mt = min(mt,ans)
    print(mt)    
    
if __name__ == "__main__":
    main()

Solution (Python):
MAX_N = 100
MAX_X = 100
INF = 1_000_000_000

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

res = INF
for i in range(1, MAX_X + 1):
    t = 0
    for x in X:
        t += (i - x) ** 2
    res = min(res, t)
print(res)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    x = list(IL())
    s = sum(x)
    ans = abs(s-n)
    i = 1
    while True:
        i += 1
        tmp = abs(s-i*n)
        if ans <= tmp: 
            i -= 1
            ans = 0
            break
        ans = tmp
        
    for rep in x:
        ans += (rep-i)*(rep-i)
    print(ans)
    return

if __name__=='__main__':
    Main()

Solution (Python):
n=int(input())
a=input()
l=a.split(" ")
l=[int(i) for i in l]
mx=max(l)
mn=min(l)
dis=[]
cnt=0
for p in range(mn,mx+1):
  dis.append(0)
  for i in l:
    dis[cnt]+=(p-i)**2
  cnt+=1
print(min(dis))

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


N=int(input())
X=list(map(int,input().split()))
ans = (100*100)**2
for i in range(min(X),max(X)+1):
    kyori = 0
    for j in range(N):
        kyori += (X[j]-i)**2
    ans = min(ans,kyori)
print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *X = map(int, read().split())

    ans = INF
    for p in range(1, 101):
        tmp = 0
        for x in X:
            tmp += (x - p) ** 2
        if ans > tmp:
            ans = tmp

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
a=min(X)
b=max(X)
dis=10**18
for k in range(a,b+1):
    D=0
    for i in range(N):
        D+=(X[i]-k)**2
    dis=min(dis,D)

print(dis)

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

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

ans = float("inf")

for p in range(100):
    total = 0
    for i in range(n):
        total += (X[i] - p) ** 2
    ans = min(ans, total)

print(ans)

Solution (Python):
_ = int(input())
*X, = 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):
_,*X=list(map(int,open(0).read().split()));print(min(map(lambda p:sum((x-p)**2 for x in X),range(min(X),max(X)+1))))

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

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    X = il()

    ret = MAX
    for p in range(0, 101):
        sm = 0
        for x in X:
            sm += calc_health(x, p)
        ret = min(ret, sm)
    print(ret)


if __name__ == '__main__':
    main()

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

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

min_result = 10**9

for p in range(1, max(X) + 1):
    result = sum([(x - p)**2 for x in X])
    if min_result > result:
        min_result = result

print(min_result)

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

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

num1=0
num2=0
for i in range(N):
  num1+=pow(X[i]-msum,2)
  num2+=pow(X[i]-(msum+1),2)
print(min(num1,num2))

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

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

Solution (Python):
import numpy as np
N = int(input())
point_arr = np.array(list(map(int, input().split())))

mean = point_arr.mean()
int_mean = int(mean)

print(min(sum((point_arr-int_mean)**2), sum((point_arr-(int_mean+1))**2)))

Solution (Python):
import statistics

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

mean=round(statistics.mean(X))
result=0

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

print(result)

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

k = round(sum(p)/N)

S=0
for i in range(N):
    S = S + ((p[i]-k)*(p[i]-k))
print(S)

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

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

minval = 10**6

for i in range(max(X)):
    val = 0
    for j in range(N):
        val += (X[j]-(i+1))**2
    minval = min(val, minval)

print(minval)

Solution (Python):
N = int(input())
ad_list = list(map(int, input().split()))
ave_ad = sum(ad_list) / len(ad_list)
r_ave_ad = round(ave_ad)

ans = 0
for i in range(N):
    tmp = (ad_list[i] - r_ave_ad) ** 2
    ans += tmp
print(ans)

Solution (Python):
N = int(input())
x_list = list(map(int, input().split()))
x_max = max(x_list)

min_ans = 10 ** 7
for i in range(1, x_max+1):
    ans = 0
    for x in x_list:
        ans += (i - x) ** 2
    min_ans = min(min_ans, ans)
    
print(min_ans)

Solution (Python):
import numpy as np

def calc_all_physical_strength(X, P):
    X = np.array(X)
    return np.sum((X-P)**2)

if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    min_P = sum(X) / N
    print(min(calc_all_physical_strength(X, int(min_P)), calc_all_physical_strength(X, int(min_P)+1)))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = float('inf')
for i in range(1,101):
    t = 0
    for x in X:
        t += abs(x-i)**2
    ans = min(ans, t)

print(ans)

Solution (Python):
import numpy as np

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

ans = 10**18
for x in range(101):
    Y = (X - x) * (X - x)
    ans = min(ans, Y.sum())

print(ans)

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

ans = 100000000

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

print(ans)

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

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

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1,E2))

Solution (Python):

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

""" ans=100000000000000000

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

print(ans)
print(range(n)) """

a=int(sum(x)/n)
b=a+1
ans1=0
ans2=0
for i in range(n):
    ans1+=(x[i]-a)**2
    ans2+=(x[i]-b)**2
print(min(ans1,ans2))