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 numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

class unionfind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.size = [1 for i in range(n)]
    def find(self,a):
        if a == self.parent[a]: return a
        else: self.parent[a] = find(self,self.parent[a]); return self.parent[a]
    def unite(self,a,b):
        pa,pb = self.find(self,a), self.find(self,b)
        if pa == pb: return
        else: self.parent[pb] = pa; self.size[pa] += self.size[pb]
    def same(self,a,b): return find(self,a) == find(self,b)

n = iinput()
x = iarr()

vals = []
for p in range(1,101):
    val = sum([(xx - p)**2 for xx in x])
    vals.append(val)
    
ans = min(vals)
print(ans)

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

Solution (Python):
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn = 10**9
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()

Solution (Python):
N = int(input())
Nlist = list(map(int, input().split()))
Nmax = max(Nlist)
Nmin = min(Nlist)
ans = 100**3
for i in range(Nmin, Nmax+1):
    total = 0
    for j in Nlist:
        total += (j-i)**2
    if ans > total:
        ans = total
print(ans)

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



def pow(X_list, M):
    P = 0
    for X in X_list:
        P += (X-M)**2
    return P

min_X = min(X_list)
max_X = max(X_list) +1
pow_min=pow(X_list, max_X)
pow_=0
for i in range(min_X,max_X,1):
    pow_ = pow(X_list,i)
    if pow_ <= pow_min:
        pow_min = pow_
print(pow_min)

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))
med = int(sum(X)/N + 0.5)
c = 0
for i in range(N):
  c += (X[i] - med)**2
print(c)

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))
medf = math.floor(sum(X)/N)
medc = math.ceil(sum(X)/N)
cf = 0
cc = 0
for i in range(N):
  cf += (X[i] - medf)**2
  cc += (X[i] - medc)**2
print(min(cf,cc))

Solution (Python):



n = int(input())
a = list(map(int, input().split()))
ans = 100 ** 5

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

print(ans)

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

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

Solution (Python):
import sys
from io import StringIO
import unittest


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

    for i in range(1, 101, 1):
        ans.append(
            sum([(i - xx) ** 2 for xx in x])
        )

    print(min(ans))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 4"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
import math

def main():
  N = int(input())
 
  X = list(map(int,input().split()))
  
  
  start = min(X) 
  end = max(X)
  
  
  power = list()
  ans = 10000000000
  
  for i in range(start, end + 1):
    for n in X:
      power.append((i - n)**2)
    if ans > sum(power):
      ans = sum(power)
      
    power.clear()
    
  print(ans)
  
main()

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

out = 10000 * n
for i in range(max(X) + 1):
    c = 0
    for j in range(n):
        c += (X[j] - i) ** 2
    out = min(out, c)
print(out)

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

best = 10 ** 9
minx, maxx = min(X), max(X)
for p in range(minx, maxx + 1):
    tmp = 0
    for i in range(N):
        tmp += (X[i] - p) ** 2
    best = min(best, tmp)

print(best)

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

ans = 10 ** 9
for P in range(X[0], X[N - 1] + 1):
  cons_pow = sum(map(lambda x: pow(x - P, 2), X))
  if cons_pow < ans:
    ans = cons_pow
    
print(ans)

Solution (Python):
import numpy as np
N = int(input())
X = np.array(list(map(int,input().split())))
ans_sum = float('inf')
for i in range(1,101):
    ans_sum=min(ans_sum,sum((X-i)**2))
print(ans_sum)

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

dis = [0] * 101
point = X[0]

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

print(min(dis))

Solution (Python):

N = int(input())
X = list(map(int,input().split()))
sum = 0
stamina = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin,xmax+1):
    for j in range(N):
        sum += (X[j]-i)**2
    if i == xmin:
        stamina = sum
    if stamina > sum:
        stamina = sum
    sum = 0
print(stamina)

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

center = sum(x)//n


ans1 = 0
ans2 = 0

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

print(min(ans1, ans2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = sum(a)/len(a)
b = int(b + 0.5)
ans = 0
for i in a:
  ans += (i-b)**2
print(ans)

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

X_mean=sum(X)//N
a=b=0
for i in X:
    a+=(i-X_mean)**2
    b+=(i-(X_mean+1))**2

if a>b:
    print(b)
else:
    print(a)

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

print(ans)

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

result = min([sum((x-p)**2 for x in X) for p in range(1, 101)])
print(result)

Solution (Python):
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


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

ans = 1000000
for i in range(1,100+1):
    sum = 0
    for j in range(len(X)):
        sum += ( X[j] - i ) ** 2

    if sum < ans:
        ans = sum

print(ans)

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
Xlist = list(map(int, input().split()))
sumX = 0
for x in Xlist:
  sumX += x
average = Decimal(sumX/N).quantize(Decimal('1'),ROUND_HALF_UP)
answer = 0
for x in Xlist:
  answer += (x-average)**2
print(answer)

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

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

t= n* 10000

for i in range(1, 101):
    a = sum([(j-i)**2 for j in xn])

    if t > a:
        t=a


print(t)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
result=[]       
for i in range(0,102):
  count=0
  for j in range(n):
    count+=(a[j]-i)**2
  result.append(count)
print(min(result))

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

lst = []
for i in range(1,101):
    wa = 0
    for x in xl:
        wa += (x-i)**2
    lst.append(wa)

print(min(lst))

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

M=10**10
for x in range(1,101):
    T=0
    for a in A:
        T+=(x-a)*(x-a)
    M=min(T,M)
print(M)

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
m=10000000000
for p in range(1,100):
    total=0
    for i in range(n):
        total+=(x[i]-p)**2
    if total<m:
        m=total
print(m)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort()
p = X[0]
Cost = 0
MinCost = 0
for k in X:
    MinCost += (k-p)**2
while p <= X[N-1]:
    Cost = 0
    for i in X:
        Cost += (i-p)**2
    if Cost < MinCost:
        MinCost = Cost
    p += 1
    
print(MinCost)

Solution (Python):









ans = float('inf')
N = int(input())
list_x = list(map(int, input().split()))

for x in range(1, 101):
    temp = 0
    for xi in list_x:
        temp += (x - xi) ** 2
    ans = min(ans, temp)

print(ans)

Solution (Python):
n=int(input())
l=list(map(int, input().split()))
ans=10000000000000000000000000000000000000000000000000000000000000000
for i in range(min(l), max(l)+1):
  cnt=0
  for s in l:
    cnt+=(s-i)**2    
  ans=min(ans, cnt)
print(ans)

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

Solution (Python):
def calc(p):
    res = 0
    for x in X:
        res += (x - p) ** 2
    return res

N = int(input())
X = list(map(int, input().split()))
mean = sum(X) // N
res = min(calc(mean), calc(mean+1))
print(res)

Solution (Python):
def resolve():
    n = int(input())
    xn = list(map(int, input().split()))
    p = round(sum(xn) / len(xn))
    s = sum([(x - p) ** 2 for x in xn])
    print(s)


if __name__ == '__main__':
    resolve()

Solution (Python):

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

minX = min(X)
maxX = max(X)
if minX==maxX:
    print(0)
    quit()

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
x = na()

z = sum(x)
Z = z/n

p = round(Z)

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

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

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

X.sort()
Max = X[len(X)-1]

res=100000000
for i in range(Max+1):
    SUM=0
    for j in range(len(X)):
        SUM += (X[j] - i) ** 2
    res = min(res, SUM)

print(res)

Solution (Python):
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inlis.sort()

    ans = 100 ** 6
    for i in range(1, 101):
        tmp = 0
        for j in range(len(inlis)):
            tmp += (inlis[j] - i ) ** 2
            if tmp > ans:
                break
        if tmp < ans:
            ans = tmp
    print(ans)
    
    
if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=int(sum(a)/n+0.5)
print(sum((i-m)**2 for i in a))

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int , input().split()))
m = sum(x)/n
m = round(m)
ans = sum((num-m)**2 for num in x)
print(ans)

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

ans = float("inf")
for i in range(1,101):
    dis_total = 0
    for x in X:
        dis = 0
        dis = (x-i)**2
        dis_total += dis
    if dis_total < ans:
        ans = dis_total
print(ans)

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

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

ans = 1000100010001
for i in range(100):
    dist = 0
    for j in x:
        dist += (j-i)**2
        
    ans = min(ans,dist)
    
print(ans)

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

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

    s.append(sum)
    sum = 0

print(min(s))

Solution (Python):
import numpy as np
import math

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

mean_num_1 = int(np.mean(X))
mean_num_2 = math.ceil(np.mean(X))

result_1 = 0
result_2 = 0
for i in X:
    result_1 += abs(mean_num_1 - i) ** 2
    result_2 += abs(mean_num_2 - i) ** 2
    
print(min(result_1, result_2))

Solution (Python):
n=int(input())
k=list(map(int,input().split()))
ap=float('inf')
for i in range(min(k),max(k)+1):
    ans=0
    for j in k:
        a=(j-i)**2
        ans+=a
    if ans<ap:
        ap=ans
print(ap)

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

min_x = min(X)
max_x = max(X) + 1

min_hp = float("inf")
for i in range(min_x, max_x):
    hp = 0
    for x in X:
        hp += (x - i) ** 2
    if hp < min_hp:
        min_hp = hp

print(min_hp)

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

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

m = round(sum(d)/n)

print(sum(map(lambda x: (x-m)**2, d)))

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

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

x.sort()

mean = sum(x)/n
med = int(n / 2)

if mean - int(mean) < 0.5:
    mean = int(mean)
elif mean - int(mean) > 0.5:
    mean = int(mean) + 1
else:
    if n % 2 == 0:
        if (x[med-1] + x[med])/2 <= mean:
            mean = int(mean)
        else:
            mean = int(mean) + 1
    else:
        if x[med] <= mean:
            mean = int(mean)
        else:
            mean = int(mean) + 1
sum = 0

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

print(sum)

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

X_mean = round(mean(X))
length = 0
for iter in range(len(X)):
    length += (X_mean - X[iter])**2

print(length)

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

print(ans)

Solution (Python):



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

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

print(sum((x-P)**2 for x in X))

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

Solution (Python):
def main():
	N = int(input())
	X = list(map(int, input().split()))
	P = [p for p in range(min(X),max(X)+1)]
	m_list = [sum([(x-p)**2 for x in X]) for p in P] 
	print(min(m_list))
  
if __name__=="__main__":
	main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans = []
for P in range(1, 101):
  wa = 0
  for x in X:
    wa += (x - P)**2
  ans.append(wa)
print(min(ans))

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

minP=float('inf')

for p in range(min(X),max(X)+1):
    P=0
    for x in X:
        P+=(x-p)**2
        if minP<P:
            break
    if P<minP:
        minP=P

print(minP)

Solution (Python):
N= int(input())
input_data = [int(x) for x in input().split()]
mini = min(input_data)
length=max(input_data)-mini
zahyo = [n-mini for n in input_data]
energy=[0 for i in range(length+1)]
for i in range(length+1):
    for j in range(N):
        energy[i]=energy[i]+(i-zahyo[j])**2
print(min(energy))

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

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


ans = 100**100

for i in range(101):
    sum = 0
    for j in range(N):
        sum += (X[j]-i)**2
    if sum <= ans :
        ans = sum

print(ans)

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

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

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

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

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

mi = min(X)
ma = max(X)
for i in range(mi, ma+1):
  temp = 0
  for j in X:
    temp += (j-i) ** 2
  l.append(temp)
  
print(min(l))

Solution (Python):
import sys
read = sys.stdin.read
def main():
    n, *x = map(int, read().split())
    r = float('inf')
    for i1 in range(1, 101):
        rt = 0
        for xe in x:
            rt += (xe - i1)**2
        r = min(r, rt)
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
List=list(map(int,input().split()))
List.sort()
ans=1000000000
for i in range(List[0],List[-1]+1):
    add=0
    for j in List:
        add+=(j-i)**2
    if add<ans:
        ans=add
print(ans)

Solution (Python):

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

hp = [0 for i in range(101)]
for i in range(101):
    for j, x in enumerate(X):
        hp[i] = hp[i] + (x-(i+1))**2

print(min(hp))

Solution (Python):
import numpy as np

n = int(input())

xs = np.asarray(list((map(int, input().split()))))

q = np.round(np.sum(xs) / n)

ans = np.sum((xs - q)**2, dtype=np.int32)

print(ans)

Solution (Python):
import numpy as np

n = int(input())

xs = np.asarray(list((map(int, input().split()))))

q = np.round(np.sum(xs) / n)

ans = np.sum((xs - q)**2, dtype=np.int32)

print(ans)

Solution (Python):
import numpy as np

n = int(input())

xs = np.asarray(list((map(int, input().split()))))

q = np.round(np.sum(xs) / n)

ans = np.sum((xs - q)**2, dtype=np.int32)

print(ans)

Solution (Python):
import math

N = input()
xs = [int(i) for i in input().split()]
p = round(sum(xs)/len(xs))

print(int(sum(math.pow(x-p, 2) for x in xs)))

Solution (Python):
n,*l=map(int,open(0).read().split())
m=round(sum(l)/n)
print(sum((i-m)**2 for i in l))

Solution (Python):
def calc_cost(arr, choice):
    ans = 0
    for num in arr:
        ans += (num - choice) * (num - choice)
    return ans

def main():
    N = int(raw_input())
    
    arr = [int(x) for x in raw_input().split()]
    
    avg = sum(arr) / N
    
    ans = min(calc_cost(arr, avg+1), calc_cost(arr, avg-1), calc_cost(arr, avg))
    
    print(ans)
    

main()


"""

using namespace std;

using ll = long long; 
/*

2
1 4


*/
int calc_cost(vector<int> arr, int choice) {
    int ans = 0;
    for (int num : arr) {
        ans += (num - choice) * (num - choice);
    }
    return ans;
}

int main() {
    int N;
    
    scanf("%d", &N);
    
    vector<int> arr(N);
    
    int total = 0;
    
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        total += arr[i];
    }
    
    int avg = total / N;
    
    /*
    sort(arr.begin(), arr.end());
    
    int med = arr[N/2];
    
    cout << med << endl;
    
    int ans = 0;
    
    for (int n : arr) {
        ans += (n - med) * (n - med);
    }
    */
    
    int ans = min({calc_cost(arr, avg-1), calc_cost(arr, avg), calc_cost(arr, avg+1)});
    
    
    printf("%d\n", ans);
	
	return 0;
}
"""

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

for p in range(1,101):
  for i in range(N):
    P[p-1]+=(X[i]-p)**2
print(min(P))

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

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

print(ans)

Solution (Python):
import sys

n = int(input())
xs = list(map(int, input().split(' ')))
xs.sort()
x_min = xs[0]
x_max = xs[-1]
min_power = sys.maxsize

for i in range(x_min, x_max + 1):
    power = sum([(x - i) ** 2 for x in xs])
    min_power = min(min_power, power)

print(min_power)

Solution (Python):
import sys
from io import StringIO
import unittest
import os


sys.setrecursionlimit(999999999)



def resolve(test_def_name=""):
    
    
    
    
    
    

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

    ans = [0 for i in range(101)]

    for i in range(1, 101):
        for xin in x:
            ans[i] += pow(xin - i, 2)

    ans = ans[1:]
    print(min(ans))



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2
1 4"""
        output = """5"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

Solution (Python):
import math
n = int(input())
x = list(map(int, input().split()))
mu_floor = math.floor(sum(x)/len(x))
mu_ceil = math.ceil(sum(x)/len(x))
x_floor = list(map(lambda i:(i-mu_floor)**2, x))
x_ceil = list(map(lambda i:(i-mu_ceil)**2, x))
ans = min(sum(x_floor),sum(x_ceil))
print(ans)

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

ans = 10**18
for i in range(0,101):
    curr_sum = 0
    for x in xl:
        curr_sum += (i-x)*(i-x)
    ans = min(ans,curr_sum)

print(ans)

Solution (Python):
n=int(input())
li=list(map(int,input().split()))
check=[]
for i in range(103):
  all=0
  for k in li:
    all+=(i-k)**2
  check.append(all)
  
print(min(check))

Solution (Python):
def main():
    num = int(input())
    l = list(map(int, input().split()))
    l.sort()

    ans_list = []

    for i in range(101):
        if i == 0:
            i = i + 1
        sum = 0
        for x in l:
            sum = sum + ((x - i) * (x - i))
        ans_list.append(sum)
    
    ans_list.sort()
    print(ans_list[0])


main()

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
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())

def main():
    N = I()
    X = LI()
    energy = [0 for _ in range(1,100)]
    for p in range(1,100):
        for x in X:
            energy[p-1] += (x-p)**2
    print(min(energy))

main()

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

ans = 10**10
for i in range(101):
    t = 0
    for j in x:
        d = i-j
        t += d*d
    ans = min(ans, t)
print(ans)

Solution (Python):
import numpy

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

ave = numpy.average(X)

if 0 <= (ave % 1) < 0.5:
    plot = int(ave)
else:
    plot = int(ave) + 1

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
lists = list(input().split())
ave_sum = 0
for i in lists:
  ave_sum = ave_sum + int(i)
ave = round(ave_sum / N)
nijyo = 0
for i in lists:
  nijyo = nijyo + (int(i) - ave) ** 2
print(str(nijyo))

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

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
count1 = 0
count2 = 0
x.sort ()
ans1 = sum(x)//n
ans2 = ans1+1
for i in range(n):
    count1 += (x[i]-ans1)**2
    count2 += (x[i]-ans2)**2
print(min(count1,count2))

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

mn=10**7
for i in range(1,101):
    hp=0
    for k in range(n):
        hp+=(x[k]-i)**2
    if hp<mn:
        mn=hp

print(mn)

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

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


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

print(ans)

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


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

print(ans)

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 += (x[j]-i)**2
    ans = min(ans,temp)
if ans == 10**10:
        print(0)
        exit()
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp, hp)
print(hp)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
def D(x,a):
	ans=0
	for i in range(len(a)):
		ans+=(x-a[i])**2
	return ans
for i in range(0,101):
	if D(i,X)<D(i+1,X):
		print(D(i,X))
		break

Solution (Python):

def main():
    N = int(input())
    X = list(map(int,input().split()))
    sum_x = sum(X)
    sum_xsqrt = sum([x**2 for x in X])
    
    p = sum(X)//N
    candidate = [N*p**2-2*p*sum_x+sum_xsqrt,N*(p+1)**2-2*(p+1)*sum_x+sum_xsqrt]
    print(min(candidate))
main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
s = sum(X)
c = 1000000
P = 0
m = min(X)
M = max(X)
for i in range(m, M+1):
  a = abs(s - N*i)
  if a < c:
    c = a
    P = i
ans = 0
for i in range(N):
  ans += (X[i] - P)**2
print(ans)

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

MinL = min(L)
MaxL = max(L)

chobani = 10000000
set = 0

for i in range (MinL, MaxL+1):
	set = 0
	for j in range (0, N):
		set+=(L[j]-i)**2
	if set < chobani:
		chobani = set

print(chobani)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
small=min(X)
big=max(X)
A=[]
for i in range(small,big+1):
  A.append(sum(list(map(lambda Ai:(Ai-i)**2,X))))
print(min(A))

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

point = np.rint(np.average(X))
print(int(np.sum((point - X)**2)))

Solution (Python):
import numpy as np
N   = int(input())
X   = np.array([int(x) for x in input().split()])
Pos = np.around(np.mean(X))
Min = int(sum(pow(X-Pos,2)))
print(Min)

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

ans = []
for a in range(1,101):
    num = 0
    for b in x:
        num += (a - b) ** 2
    ans.append(num)

print(min(ans))

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

def get_dist(X,p):
    sum_=0
    for x in X:
        sum_+=(x-p)**(2)
        
    return sum_

dist_min=10**10
for p in range(0,101):
    dist=get_dist(X,p)
    if dist_min>dist:
        dist_min=dist
print(dist_min)

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

ans=10**9
i=1
while i<=100:
    j=0
    count=0
    while j<N:
        count+=(i-X[j])**2
        j+=1
    ans=min(ans,count)
    i+=1

print(ans)

Solution (Python):


import numpy as np

def main():
    n = int(input())
    l = list(map(int,input().split()))
    arr = np.array(l)

    suml = []
    for i in range(1, 101):
        gokei = sum((arr-i)**2)
        suml.append(int(gokei))
    
    print(min(suml))


if __name__ == '__main__':
    main()

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

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

Ans = []
for x in range(1,101):
    ans = 0
    for y in range(N):
        ans += (X[y]-x)**2
    Ans.append(ans)

print(min(Ans))

Solution (Python):
import heapq as hp
n = int(input())
X = list(map(int,input().split()))
min1=[]
a=min(X)
b=max(X)
for i in range(a,b+1):
    total=[]
    for j in X:
        total.append(abs(j-i)**2)
    else:
        ans=sum(total)
        hp.heappush(min1,ans)
print(hp.heappop(min1))

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

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

print(result)

Solution (Python):
import statistics

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

a = round(statistics.mean(x))
sums = 0
for i in x:
    sums += (i - a) ** 2
print(sums)

Solution (Python):
def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    p = 0
    ans = 0
    p = round(sum(Xs)/ N)
    for i in Xs:
        ans = ans + ((p - i) ** 2)
    print(ans)
resolve()

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

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

answer = np.inf
for p in range(100):
    a = 0
    for x in X:
        a += (x - p) ** 2
    if answer > a:
        answer = a
print(answer)