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())
xlis = list(map(int,input().split()))
def tai(p,x):
  return pow(x-p,2)
ans=999999999999
for i in range(0,100):
  sum=0
  for j in xlis:
    sum+=tai(i,j)
  if ans>sum:
    ans=sum
    
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate

from heapq import heapify,heappop,heappush


from functools import lru_cache


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    

    N = int(input())
    
    A = tuple(map(int, input().split())) 
    
    


    ave=round(sum(A)/N)
    ans=0
    for x in A:
        ans+=(x-ave)**2
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP

num_of_person = int(input())
coordinates = list(map(int, input().split()))

avg = sum(coordinates) / len(coordinates)
avg = Decimal(str(avg)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

power = 0
for coordinate in coordinates:
    power = power + (coordinate - avg) ** 2

print(power)

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections











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



ans = 0
ave = round(sum(X)/len(X))

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

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
ans = 0

m = np.average(A)

x = round(m)

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

print(int(ans))

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

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

print(ans)

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

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

m = min( X )
M = max( X )

v_min = 10 ** 18
for i in range( m , M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) **2
  v_min = min( v, v_min )
print( v_min )

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

ans = 10**9

for i in range(0, 101):
    tmp = 0
    for x in X:
        tmp += (x - i)**2
    ans = min(tmp, ans)

print(ans)

Solution (Python):
a = []
N = int(input())
a = list(map(int, input().split()))
ave = c = 0

for i in range(N):
  ave += a[i]
ave_l = int(ave / N)
ave_u = ave_l + 1

s_l = s_u = 0
for i in range(N):
  s_l += (a[i] - ave_l)**2
  s_u += (a[i] - ave_u)**2

ans = min(s_l, s_u)
print(ans)

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

mean = int( sum( x ) / len( x ) + 0.5 + ( 10 ** -10 ) )

var = 0
for x_i in x:
    var += ( x_i - mean ) ** 2

print( var )

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort()
Y = [0] * (max(X) + 1)
for _x in X:
    for y_idx in range(len(Y)):
        Y[y_idx] += (_x - y_idx)**2
print(min(Y))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X.sort()
Y = [0] * (max(X) + 1)
for _x in X:
    for y_idx in range(len(Y)):
        Y[y_idx] += (_x - y_idx)**2
print(min(Y))

Solution (Python):
def f(x):
    return (x - p) ** 2


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

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


X = list(map(f, X))

print(sum(X))

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

start=min(X)
end=max(X)
ans=10**10
for p in range(start,end+1):
    point=0
    for x in X:
        point=point+(p-x)**2
    ans=min(ans,point)

print(ans)

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    X = NLI()
    ans = 10**20
    for i in range(100):
        sq = 0
        for x in X:
            sq += (i-x)**2
        ans = min(ans, sq)
    print(ans)


if __name__ == "__main__":
    main()

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

for p in range(1, max(x) + 1):
    temp = 0
    for q in range(len(x)):
        temp += (x[q] - p) ** 2
    ans = min(ans, temp)
print(ans)

Solution (Python):
R=0
N=int(input())
L=list(map(int,input().split()))
maxa=max(L)
mina=min(L)
minb=10**10
for i in range(mina,maxa+1):
  for j in range(N):
    R+=(L[j]-i)**2
  minb=min(minb,R)
  R=0
print(minb)

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

xav = sum(x) / n
if xav % 1 >= 0.5:
    xav = xav//1 +1
else:
    xav = xav//1
    
ans = 0

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

print(int(ans))

Solution (Python):



def main():
    number_of_human = int(input())
    position_list = list(map(int,input().split()))
    
    start_position = min(position_list)
    end_position = max(position_list)
    max_answear = sum([(item - start_position)**2 for item in position_list])
    while True:
        answear = sum([(item - start_position)**2 for item in position_list])
        if start_position == end_position:
            break
        start_position += 1
        if answear < max_answear:
            max_answear = answear
    
    print(max_answear)
if __name__ == "__main__":
    main()

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

st = min(x)
en = max(x)
n = len(x)

min_energy = 10**10

for p in range(st,en+1):
    energy = 0
    for i in range(n):
        energy += (x[i] - p )**2

    min_energy = min(min_energy,energy)

print(min_energy)

Solution (Python):
import numpy as np
n=int(input())
ar=np.array(list(map(int,input().split())))
m=np.inf

for i in range(1,100):
    s=np.sum(np.square(ar-i))
    if s<m:
        m=s
print(m)

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

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

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

print(min(sum((x-(n+1))**2 for x in X) for n in range(max(X))))

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

P = []
for i in range(min(X), max(X) + 1):
    HP = [(a - i)**2 for a in X]
    P.append(sum(HP))

print(min(P))

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

for i in range(min(x),max(x)+1):
    sum=0
    for k in range(len(x)):
        sum+=(x[k]-i)**2
    sum_list.append(sum)

min_sum=min(sum_list)
print(min_sum)

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

tot = 0
for x in l:
    tot+=x

ag = int(round(tot/n))

ans = 0
for x in l:
    ans+=(x-ag)**2
print(ans)

Solution (Python):

N = int(input())


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

ans_list = []



for i in range(100):
  ans = 0
  for j in range(N):
    ans += (X_list[j]-(i+1))**2
  ans_list.append(ans)
print(min(ans_list))

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

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

Solution (Python):
from math import ceil, floor


def tai(X, p) -> int:
    return sum((X[i] - p) ** 2 for i in range(len(X)))


if __name__ == "__main__":
    N = int(input())
    X = [int(x) for x in input().split(" ")]
    print(min(tai(X, p) for p in range(-1, len(X) + 1000)))

Solution (Python):


def solve(N ,Xs):
    ans = float('inf')
    for i in range(100):
        _sum = sum([(x - i) ** 2 for x in Xs])
        ans = min(ans, _sum)

    print(ans)


if __name__ == '__main__':
    N = int(input())
    Xs = [int(i) for i in input().split()]
    solve(N, Xs)

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

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

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

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

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

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

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP

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

ans = 0
X_mean = Decimal(str(sum(X) / N))
X_mean = X_mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)

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

print(ans)

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

Solution (Python):
N = int( input())
X = list( map( int, input().split()))
 
v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

Solution (Python):
N = int( input())
X = list( map( int, input().split()))
 
v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

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

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

print(ans)

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

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

print(min(sum_list))

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

sum_list = []
start = min(x)
stop = max(x)
for i in range(1, 100):
    sum = 0
    for j in x:
        sum += (i - j) ** 2
    sum_list.append(sum)

print(min(sum_list))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans = 10000000000
temp = 0

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

print(ans)

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

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

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

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

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

m = min( X )
M = max( X )

v_min = 10 ** 18
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

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

m = min( X )
M = max( X )
v_min = 10 ** 18
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_min = min( v, v_min )
print( v_min )

Solution (Python):
N = int(input())
X = []
X = input().split(' ')
Z = []
for i in range(N):
   Z.append(int(X[i]))
P = round(sum(Z) / N)
result = 0
for i in range(N):
  result += (Z[i] - P) ** 2
print(int(result))

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

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

v_max = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_max = min( v, v_max )
print( v_max )

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

y = round(sum(X)/N)

ans = sum([(y-i)**2 for i in X])

print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=float("Inf")
for i in range(x[0],x[n-1]+1):
  temp=i
  cal=0
  for j in range(0,n):
    cal=cal+(x[j]-temp)**2
  ans=min(ans,cal)
print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
sm = sum(x)
p = sm//n
p1 = p+1

b = []
for i in range(n):
    b.append((x[i]-p)**2)


c = []
for i in range(n):
    c.append((x[i]-p1)**2)
print(min(sum(c),sum(b)))

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

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

a=[]
cal=0

for i in range(100):
    for j in range(len(x)):
        cal+=(x[j]-i)**2

    a.append(cal)
    cal=0


print(min(a))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ave = sum(x) / n
ave_int = int(ave)
if (ave - ave_int) < (ave_int+1-ave):
  p = ave_int
else:
  p = ave_int+1

r = sum([ abs(i-p)**2 for i in x ])
print(r)

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

for P in range(1, 101):
    total = 0
    for position in X:
        total += (position - P) ** 2
    ans = min(ans, total)
    
print(ans)

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

minval = 100000000000
for x in range(1,101):
  minval = min(sum([(x-i)**2 for i in xxx]),minval)
print(minval)

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

def dist(a, X):
	l = 0
	for i in X:
		l += (a-i)**2
	return l

ans = 10000000
for i in range(min(X), max(X)+1):
	if ans > dist(i,X):
		ans = dist(i,X)

print(ans)

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

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

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
t=max(x)
lsum=[]
for i in range(1,t+1):
  sum_x=0
  
  for x_ in x:
    sum_x+=(x_-i)**2
  lsum.append(sum_x)
  

print(min(lsum))

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

ave = sum(x) // n

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

print(min(ans))

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

ans = 10 ** 9
for i in range(0, 101):
    s = 0
    for xx in x:
        s +=(i - xx) ** 2
    ans = min(ans, s)
print(ans)

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

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

ans = 10**16
for p in range(1,101):
    hp = 0
    for x in X:
        hp += (x-p)**2
    ans = min(ans,hp)
print(ans)

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

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main(n,x)
    print(ans)

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

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main2(n,x)
    print(ans)

Solution (Python):
def main():
    n = int(input())
    xs = list(map(int, input().split()))
    x_min = min(xs)
    x_max = max(xs)

    ans = float("inf")
    for i in range(x_min, x_max+1):
        ans_temp = 0
        for x in xs:
            ans_temp += (x - i)**2
        ans = min(ans, ans_temp)

    print(ans)


if __name__ == "__main__":
    main()

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

ans = 1000000
for p in range(101):
  cost = 0
  for i in range(N):
    cost += (x[i] - p) ** 2
  ans = min(cost, ans)

print(ans)

Solution (Python):






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





ave = sum(X)//len(X)
ans_1 = sum([(x-ave)**2 for x in X])
ans_2 = sum([(x-(ave+1))**2 for x in X])
print(min(ans_1, ans_2))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans2 = 99999999999999
for i in range(100):
    ans1=0
    for j in range(n):
        ans1 += pow(x[j]-i,2)
    ans2 = min(ans2,ans1)
print(ans2)

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

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

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

Solution (Python):
N = int(input())
tmp = input().split()
X = [0]*N
for n in range(N):
    X[n] = int(tmp[n])

souwa = [0]*100
for p in range(100):
    tairyoku = 0
    for n in range(N):
        tairyoku += (X[n]-p+1)**2
    souwa[p] = tairyoku

min_value = min(souwa)
min_index = souwa.index(min_value)

print(souwa[min_index])

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

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

Solution (Python):

from statistics import mean
 
N = int(input())
X = list(map(int, input().split()))
 
mean_X = int(mean(X) + 0.5)
 
 
print(int(sum([(x - mean_X)**2 for x in X])))

Solution (Python):
import numpy as np

N = int(input())
X = list(map(int, input().split()))
A = [0]*101

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

answer = min(np.abs(A))

print(answer)

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

import numpy as np

np.array(A)

lis = list()

for i in range(1,max(A)+1):
    life = (A - np.array([i]*N))**2
    lis.append(sum(life))

print(min(lis))

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

ans = float("inf")

l = []
for i in range(1, N+101):
    pow = 0
    for j in range(N):
        
        
        
        pow += (x[j]-i)**2
    
    if ans > pow:
        ans = min(ans, pow)
        l.append(i)

print(ans)

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

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

ans = 999999999
for i in range(200):
    hp_sum = 0
    for regi in regis:
        hp_sum += (regi - i)**2
    ans = min(ans , hp_sum)

print(ans)

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

print(min(sum([(xi-sum(X)//N)**2 for xi in X]),sum([(xi-sum(X)//N-1)**2 for xi in X])))

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mean=round(sum(a)/n)
print(sum([(v-mean)**2 for v in a]))

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

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

min_a = min(a)
max_a = max(a)
ans_lst = []

for i in range(min_a, max_a + 1):
  sum_ans = 0
  for j in a:
    sum_ans += (i - j) ** 2
  ans_lst.append(sum_ans)
print(min(ans_lst))

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


minx = min(x)
maxx = max(x)


total = -1


def square(i, x):
  return ((x-i)**2)


for i in range(minx, maxx+1):
  list_i = [i] * n
  tmp = sum(map(square, list_i, x))
  
  if total == -1:
    total = tmp
  else:
    if total > tmp:
      total = tmp

print(total)

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

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
m = min(X)
M = max(X)

ans = float("inf")
for p in range(m, M + 1):
    cnt = 0
    for i in range(n):
        cnt += (X[i] - p) ** 2

    ans = min(ans, cnt)
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
ans = 10**10
for p in range(min(X), max(X)+1):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 10**10
for p in range(min(X), max(X)+1):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 10**10
for p in range(100):
    tmp = 0
    for x in X:
        tmp += pow(x-p, 2)
    ans = min(ans, tmp)
print(ans)

Solution (Python):

N = int(input())
X = list(map(int, input().split()))
mn = 10**9
for p in range(min(X), max(X)+1):
    c = 0
    for x in X:
        c += (p-x)**2
    mn = min(c, mn)
print(mn)

Solution (Python):
N=int(input())
X=list(map(int, input().split()))
g=sum(X)/N
if g-int(g)>=0.5:
  g=int(g)+1
else:
  g=int(g)   
ans=0
for x in X:
  ans+=(x-g)**2

print(ans)

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

min = 100 * 100 ** 2

for p in range(1, 101, 1):
    ttl = 0
    for i in x:
       ttl += (i - p) ** 2
    if ttl <= min:
        min = ttl

print(min)

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

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

h = [(i - P)**2 for i in X]
print(sum(h))

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

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

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

ans = 10 ** 18
for i in range(1, 101):
    tmp = 0
    for x in X:
        tmp += (x - i) ** 2
    ans = min(ans, tmp)

print (ans)

Solution (Python):

import sys


def solve(N: int, X: "List[int]"):
    
    import math

    ans = 999999999
    for p in range(1, 100 + 1):
        vit = 0
        for x in X:
            vit += pow((x - p), 2)
        ans = min(ans, vit)
    print(ans)
    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())
Data = list(map(int,input().split()))
mind = min(Data)
maxd = max(Data)
ans = -1
for pos in range(mind,maxd+1):
    sum1 = 0
    for d in Data:
        sum1 += (pos-d)**2
    if ans == -1:
        ans = sum1
    else:
        ans = min(ans,sum1)
print(ans)

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


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

P = round(B/N)
energy = 0
for i in range(N):
  energy += (X[i] - P)**2
  
print(energy)

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

Solution (Python):

class abc_156:
    
    def __init__(self):
        pass
    
    def A(self):
       pass
    def B(self):
        pass
        
    def C(self):
        N=int(input())
        X=list(map(int,input().split()))
        
        ans=[]
        sum_data=0
        
        X.sort()
        L=X[0]
        R=X[len(X)-1]
        
        for i in range(L,R+1):
            sum_data=0
            for j in range(len(X)):
                sum_data+=(X[j]-i)**2
            ans.append(sum_data)
        
        ans.sort()
        print(ans[0])
      
    def D(self):
        pass
        
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_156()
    obj.C()

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

sq = [xi ** 2 for xi in x]

sum_sq = sum(sq)
sum_x = sum(x)

hp = []

for p in range(min(x), max(x)+1):
    hp.append(sum_sq - 2*p*sum_x + n* (p **2))

print(min(hp))

Solution (Python):













INF = 1001001001001



def main():

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

    point = INF
    for p in range(1, 101):
        s = 0
        for x in X:
            s += (x - p)**2
        point = min(point, s)

    print(point)


if __name__ == '__main__':
    main()

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

Solution (Python):
N=int(input())
X = list(map(int, input().split()))
ans=10**7
for i in range(1, max(X)+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()))
a=min(X)
b=max(X)
ans=[]
for i in range(a,b+1):
    tmp=0
    for j in X:
        tmp+=(j-i)**2
    ans.append(tmp)
print(min(ans))

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


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

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

print(ans)

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

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

min_e = 10 ** 9
for p in range(X[0], X[-1] + 1):
    e = sum([(x - p) ** 2 for x in X])
    min_e = min(min_e, e)

print(min_e)

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

Solution (Python):
N = int(input())
Xs = list(map(int, input().split()))
s = sum(Xs)
s2 = sum([X*X for X in Xs])
rs = []
for P in range(1, 100+1):
  r = N*P*P-2*s*P+s2
  rs.append(r)
r = min(rs)
print(r)

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

s = sum(x)//n
s1 = s+1
tairyoku1=0
tairyoku2=0

for i in range(n):
  tairyoku1 += (x[i]-s)**2
  tairyoku2 += (x[i]-s1)**2
  
print(min(tairyoku1,tairyoku2))

Solution (Python):
def main():
    N = int(input())
    X = list(map(int, input().split()))
    Xmin = min(X)
    Xmax = max(X)
    ans = 1000000000000
    for i in range(Xmin-1, Xmax+2):
        tmp = 0
        for p in X:
            tmp += (p-i)*(p-i)
        ans = min(ans, tmp)
    print(ans)

main()

Solution (Python):
n=int(input())
li = list(map(int,input().split()))
ans = [-1,10**7]

for i in range(1,101):
    a = 0
    for j in range (len(li)):
        a += (li[j]-i)**2
    if a <= ans[1]:
        ans[0] = i
        ans[1] = a
    
print(ans[1])

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

m = min(s)
M = max(s)

lis = []
ans = 0

for i in range(m,M + 1):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))

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

m = s[0]
M = s[N-1]

lis = []
ans = 0

for i in range(1000):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))

Solution (Python):
def main():
    n = int(input())
    x = list(map(int, input().split()))
    
    t = []
    for p in range(max(x)+1):
        t.append(sum((i-p)**2 for i in x))
    print(min(t))
    
if __name__ == '__main__':
    main()