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())
input_zahyo = []
goukei = 0
tairyoku = 0

input_zahyo = input().split()
zahyo = [int(s) for s in input_zahyo]


for i in range(n):
    goukei += zahyo[i]

ave = round(goukei/n)

for i in range(n):
    tairyoku += (zahyo[i]-ave)**2

print(tairyoku)

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

f = lambda x, y: (x-y)*(x-y)
temp = []
for i in range(min(l), max(l)+1):
    aaa = sum([f(m, i) for m in l])
    temp.append(aaa)
print(min(temp))

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

P = 0
min_sum = 100 ** 2 * 100
while(True):
  sum = 0
  for x in range(N):
    sum += (X_list[x]- P) ** 2
  if(sum <= min_sum):
    min_sum = sum
    P += 1
    continue
  else:
    break

print(min_sum)

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

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

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

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

print(ans)

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

ret = 10 ** 9
for i in range(1, 1000):
    ret = min(ret, sum([(x-i)**2 for x in X]))
print(ret)

Solution (Python):
import math

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

def min_p(x,n):
  return round(sum(x)/n)

def fsum(x,p):
  return sum([(i-p)**2 for i in x])

p=min_p(x,n)
print(fsum(x,p))

Solution (Python):
import math
N = int(input())
X = list(map(int, input().split()))
 
def sutamina(P, X):
    return (X-P)**2
  
sutamina_min = float('inf')
for i in range(100):
    sutamina_souwa = 0
    for k in X:
        sutamina_souwa += sutamina(i, k)
    if sutamina_souwa < sutamina_min:
        sutamina_min = sutamina_souwa

print(sutamina_min)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    X = list(map(int, input().split()))
    ans = float('inf')
    for p in range(1, 101):
        total = 0
        for x in X:
            total += (x - p) ** 2
        ans = min(total, ans)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

average_x = np.mean(x)
p = round(average_x)

l = np.square(x-p)
print(int(sum(l)))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
c=[]
for p in range(1,101):
    sum1=0
    for i in x:
        r= abs(i-p)
        sum1 = sum1+r**2
    c.append(sum1)
print(min(c))

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


ans1 = 0
ans2 = 0
  
med = sum(X)//N
for n in range(N):
  ans1 += (X[n]-med)**2

med += 1
for n in range(N):
  ans2 += (X[n]-med)**2
  
ans = min(ans1,ans2)
  

print(ans)

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

Solution (Python):
N = int(input())
Xs = input().split()
X_i = []
for i in range(N):
  X_i.append(int(Xs[i]))

x0 = 1
Ps = []
for k in range(100):
  P = 0
  for i in range(N):
    P+= (X_i[i]-x0)**2
  Ps.append(P)
  x0+=1
print(min(Ps))

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
a = 10000000
for p in range(100):
    a_i = sum([(x_i - p)**2 for x_i in x])
    if a < a_i: break
    else: a = a_i
print(a)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

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

Solution (Python):
n = int(input())
seq = [int(x) for x in input().split()]
d = round(sum(seq) / len(seq))
print(sum([(x-d)**2 for x in seq]))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
s=sum(x)
mini=100000*10000
cand=s//n
sum=0
for i in x:
  sum+=((i-cand)**2)
mini=min(mini,sum)
cand+=1
sum=0
for i in x:
  sum+=((i-cand)**2)
mini=min(mini,sum)
cand-=2
sum=0
for i in x:
  sum+=((i-cand)**2)
mini=min(mini,sum)
print(mini)

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
m=10**9
for i in range(1,101):
  t=0
  for j in x:
    t+=(j-i)**2
  m=min(t,m)
print(m)

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

    minimum = float("inf")
    for i in range(1,101):
        hpmin = 0
        for j in X:
            hpmin += (i-j)**2
        minimum = min(hpmin, minimum)
    print(minimum)
    
if __name__ == '__main__':
    main()

Solution (Python):
import math

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

def f(P,X):
    if len(X)==1:
        return (P-X[0])**2
    else:
        return (P-X[0])**2 + f(P,X[1:])

avg = sum(X) / N
max = math.ceil(avg)
min  = math.floor(avg)

if max-avg < avg-min:
    print (f(max,X))
else:
    print (f(min,X))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
c = sum([x**2 for x in X])

ans = 100 * (100) ** 2
for i in range(1, 101):
    c += 2 * sum([i-x for x in X]) - N
    ans = min(c, ans)

print(ans)

Solution (Python):
import numpy as np


def main():
    _ = input()
    x = np.asarray(list(map(int, input().split())))
    p = int(np.round(np.average(x)))
    print(np.sum((x - p) ** 2))


if __name__ == "__main__":
    main()

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

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

print(min)

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

li = [[0]*101 for _ in range(n)]

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

ans = 10 ** 10

for i in range(101):
    tmp = 0
    for j in range(n):
        tmp += li[j][i]
    ans = min(ans,tmp)

print(ans)

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

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

s = sum(x)
p = s // n if 2 * (s % n) <= n else s // n + 1
ans = sum([(i - p) ** 2 for i in x]) 
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):





def cost(X, p):
    c = 0
    for x in X:
        d = x - p
        c += d * d
    return c


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

    total = sum(X) // N

    c1 = cost(X, total)
    c2 = cost(X, total + 1)

    if c1 > c2:
        print(c2)
    else:
        print(c1)


main()

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

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

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

Solution (Python):
engAll = []
eng = 0

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

for i in range(min(live), max(live) + 1):
    for j in live:
        eng += (j - i)**2
    engAll.append(eng)
    eng = 0

print(min(engAll))

Solution (Python):

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

ans = []
for i in range(100):
    tmp = 0
    for j in range(len(X)):
        tmp += (i - X[j])**2
    ans.append(tmp)

print(min(ans))

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

S = 0
S_min = 100000000000000

for i in range(101):
    for j in X:
        S += (j - i)**2
        
    if S < S_min:
        S_min = S
        S = 0
    else:
        S = 0
print(S_min)

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

S = 0
S_min = 100000000000000

for i in range(min(X), max(X)+1):
    for j in X:
        S += (j - i)**2
        
    if S < S_min:
        S_min = S
        S = 0
    else:
        S = 0
print(S_min)

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

s = round(sum(x)/n)
ans = [(a-s)**2 for a in x]

print(sum(ans))

Solution (Python):
import sys
n = int(input())
xLst = list(map(int, input().split()))
sm = 0
ans = int(sys.maxsize)


for i in range(101):
    
    sm = sum((xLst[ii] - i)**2 for ii in range(n))
    if ans > sm:
        ans = sm        
print(ans)

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

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

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

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

ans=float("inf")
for P in range(1,101):
    num=0
    for x in X:
        num+=(x-P)**2
    ans=min(ans,num)
print(ans)

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

Solution (Python):
N=int(input())
a=[int(x) for x in input().split()]
import math
import statistics
mean=statistics.mean(a)
m=round(mean,0)

sum=0
for x in a:
    t=(x-m)**2
    sum+=t
int_sum=int(sum)
print(int_sum)

Solution (Python):
n = int(input())
x = list(map(int,(input().split())))
hp = 0
ans = []
for j in range(1,100+1):

  for i in x:
    hp_temp = ( i -j )**2 

    hp +=  hp_temp
  ans.append(hp)

  hp = 0
 
print(min(ans))

Solution (Python):
import numpy as np

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

shouhiHP = 1001001001000
for k in range(min(x),max(x)+1):
    xHP = x - k
    xHP2jou = xHP ** 2
    sum_xHP = sum(xHP2jou)
    if sum_xHP < shouhiHP:
        shouhiHP = sum_xHP
    else:
        pass

print(shouhiHP)

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

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

Solution (Python):
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0

for n_ in range(max(temp) + 1):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Solution (Python):
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
for n_ in range(100):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
s = sum(x)
p = float(s/n)
q = int(10*p)
if q%10 < 5:
    p = int(s/n)
else:
    p = int(s/n)+1
r = 0
for y in x:
    r += (y - p)**2
print(r)

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

P = int(sum(X) / N + 0.5)
print(sum((x - P) * (x - P) for x in X))

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


ans = 10**9
for p in range(1,101):
    a = 0
    for k in x:
        a+=(k-p)**2
    ans = min(ans,a)

print(ans)

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

ans = 10**9
for i in range(max(X)+1):
    tmp = 0
    i += 1
    for j in range(N):
        tmp += pow(X[j] - i, 2)
        
    
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):

N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = float("inf")
for p in range(X[0], X[-1] + 1):
    tmp = 0
    for i in range(N):
        tmp += (p - X[i]) ** 2
    ans = min(ans, tmp)
print(ans)

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

Solution (Python):
n = int(input())
x_lst = list(map(int,input().split()))
average1 = sum(x_lst) // n
average2 = sum(x_lst) // n + 1

answer1 = 0
for i in range(n):
    x = x_lst[i]
    answer1 += (x-average1) ** 2

answer2 = 0
for i in range(n):
    x = x_lst[i]
    answer2 += (x-average2) ** 2

answer = min(answer1,answer2)
print(answer)

Solution (Python):
from statistics import mean
from decimal import Decimal, ROUND_HALF_UP

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

m = Decimal(str(mean(X))).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

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

print(ans)

Solution (Python):
n = int(input())
X = [int(i) for i in input().split()]
r = min(X)
l = max(X)
ans = float("INF")
num = 0
for i in range(r, l+1):
  for x in X:
    num += (x-i)**2
  ans = min(ans, num)
  num = 0
print(ans)

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

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

s = sum(X_list)

p = round(s/N)


ans = 0

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

print(ans)

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

hito = list(map(int, input().split()))
hito.sort()

a = min(hito)
b = max(hito)

res = []

for i in range(a,b + 1):
  s = 0
  for j in hito:
    s += (i - j) * (i - j)
  res.append(s)
print(min(res))

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

ans=0
ans1=0
ans2=0
for i in L:
    ans+=pow(i-x,2)
    ans1+=pow(i-x-1,2)
    ans2+=pow(i-x+1,2)

print(min(ans,ans1,ans2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
l = sum(X)
p = l // N
q = l // N + 1
s = 0
t = 0
for x in X:
  s += (x - p) ** 2
  t += (x - q) ** 2
print(min(s, t))

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


N = ii()

X = li()

import numpy as np

X = np.sort(X)

x_st = X[0]
x_ed = X[-1]

all_min = np.inf

for i in range(x_st,x_ed+1):
    itr_min = np.sum(np.abs(X-i)**2)
    


    if(all_min > itr_min):
        all_min = itr_min


print(all_min)

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

hp = 0
for i in b:
    hp += (i - p) ** 2

print(hp)

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

ma=max(x)
mi=min(x)

ans=10**9
for i in range(mi,ma+1):
  t_ans=0
  for j in x:
   t_ans+=(i-j)**2
  ans=min(ans,t_ans)
print(ans)

Solution (Python):


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

a = round(sum(X)/N)
s = sum((x - a)**2 for x in X)
print(s)

Solution (Python):
n = int(input())
x_list = list(map(int, input().split()))
ans_list = [sum([(x - p) ** 2 for x in x_list]) for p in range(min(x_list), max(x_list) + 1)]
print(sorted(ans_list)[0])

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

ans = float('inf')
for i in range(min(Xn),max(Xn)+1):
    pos = 0
    for j in Xn:
        pos += (j-i)**2
    ans = min(ans, pos)
print(ans)

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

print(  min( sum( (xx-p)**2 for xx in x ) for p in range(max(x)+2) ) )

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

ans = 10 ** 9
for p in range(min(x), max(x) + 1):
    cost = 0
    for xi in x:
        cost += (xi - p) ** 2
    ans = min(ans, cost)
print(ans)

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

m=10**9+7
for i in range(0,100):
  p=i+1
  a=0
  for j in range(0,N):
    a=a+(huga[j]-p)**2
  m=min(a,m)
  
print(m)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = (100**2)*100
total = 0
for i in range(min(X),max(X)+1):
    for i2 in range(N):
        total += (X[i2] - i)**2
    if total <= ans:
        ans = total
    total = 0

print(ans)

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

ans = None
for p in range(min(x), max(x) + 1):
    cost = 0
    for xi in x:
        cost += (xi - p) ** 2
    ans = min(ans, cost) if ans is not None else cost
print(ans)

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

xx = []
for i in range(min(x), max(x)+1):
    wa = 0
    for j in x:
        wa += (j-i)**2
    xx.append(wa)
print(min(xx))

Solution (Python):


N=int(input())
X=list(map(int, input().split()))
s=sum(list(map(lambda x: (x-min(X))**2, X)))
for i in range(min(X),max(X)+1):
    s_i=sum(list(map(lambda x: (x-i)**2, X)))
    if s_i<=s:
        s=s_i
print(s)

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

tminm = 0
for k in range(N):
  tminm += (A[k] - 1)**2

ma = max(A)
for i in range(1,ma+1):
  minm = 0
  for j in range(N):
    minm += (A[j] - i)**2
  
  if minm < tminm:
    tminm = minm

print(tminm)

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

X.sort()

MIN=10**10
for p in range(102):
    ans=0
    for g in range(N):
        ans+=(p-X[g])**2
    MIN=min(ans,MIN)
print(MIN)

Solution (Python):





n = int(input().rstrip())
x_list = [int(x) for x in 
          input().rstrip().split(" ")]
p1 = sum(x_list)//n
if sum(x_list)%n == 0:
  print(sum((x-p1)**2 for x in x_list))
else:
  p2 = p1 + 1
  print(min(sum((x-p1)**2 for x in x_list),
            sum((x-p2)**2 for x in x_list)))

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


def score(p):
    sc = 0
    for x in X:
        sc += (x - p) ** 2
    return sc


scores = [score(p) for p in range(1, 101)]
print(min(scores))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
b=a+1

A,B=0,0
for i in x:
  A+=(a-i)**2
  B+=(b-i)**2
  
print(min(A,B))

Solution (Python):
N=int(input())
X =list(map(int,input().split()))
sum=0
ans=float("inf")

for p in range(1,101):
  sum=0
  for i in X:
    sum += (i-p)**2
  ans=min(ans,sum)
  
print(ans)

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

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

Solution (Python):


from sys import stdin, stderr

def main():
   N = int(stdin.readline())
   A = map(int, stdin.readline().split())

   res = 10000000000000
   for x in xrange(1, 101):
      cost = sum([ (a-x)**2 for a in A  ])
      res = min(res, cost)

   print(res)

   return 0

if __name__ == '__main__': main()

Solution (Python):
import math

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

p = sum(x) / n
p = [math.floor(p), math.ceil(p)]

min = 10000000

for a in p:
    y = list(map(lambda x: math.pow(x-a, 2), x))
    if sum(y) < min:
        min = sum(y)

print(int(min))

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

print(sum([(a-p)**2 for a in A]))

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

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

print(ans)

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

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

answer = 10 ** 15
for p in range(1, 101):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    answer = min(answer, tmp)

print(answer)

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

min_hp = -1
for i in range(min(x),max(x)+1):
    hp = 0
    for j in x:
        hp += (j - i) ** 2
    if min_hp < 0:
        min_hp = hp
    min_hp = min(min_hp,hp)

print(min_hp)

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

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

print(ans)

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

ans = (100**2) * 100
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)

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

Solution (Python):
def solve():
    N, *X = map(int, open(0).read().split())
    
    ans = 10 ** 8
    for p in range(1, 101):
        sm = 0
        for xi in X:
            sm += (xi - p) ** 2
        ans = min(ans, sm)
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r + 1):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2
 
        ans = min(hp, ans)
    print(ans)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    x = list(map(int, readline().split()))
    x.sort()
    mt = 10 ** 10
    for i in range(x[0], x[-1] + 1):
        t = 0
        for v in x:
            t += (v - i) ** 2
        mt = min(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
x = sorted(list(map(int,input().split())))
li = []
cost = 0
for i in range(x[0],x[-1]+1,1):
    cost = 0
    for b in x:
        cost += (b-i)**2
    li.append(cost)
print(min(li))

Solution (Python):
n,*X = map(int, open(0).read().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()))

ans = 10 ** 6
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)

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

p = sum(x)/n

h = 0
for i in x:
  h += abs(i - round(p))**2
  
print(math.ceil(h))

Solution (Python):
import math

N = int(input())

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

m1 = math.ceil(sum(X) / N)
m2 = math.floor(sum(X) / N)

res1 = 0
res2 = 0

for i in range(N):
    res1 += (X[i] - m1) ** 2
    res2 += (X[i] - m2) ** 2
    
print(min(res1, res2))

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

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

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

Solution (Python):
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r + 1):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2

        ans = min(hp, ans)

    print(ans)

Solution (Python):
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
cost = float("inf")
for i in range(max(X) - min(X) + 1):
    p = min(X) + i
    cost = min(np.sum((X - p) ** 2), cost)
print(cost)

Solution (Python):
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
cost = float("inf")
for i in range(101):
    cost = min(np.sum((X - i) ** 2), cost)
print(cost)

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

p = round(sum(X)/N)

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

print(ans)

Solution (Python):
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
costs = []
for i in range(101):
    costs.append(np.sum((X - i) ** 2))
print(min(costs))

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


_min = pow(10,9)

for p in range(min(x), max(x)+1):
  total = 0
  for xi in x:
    total += pow(xi - p, 2)
  if total < _min:
    _min = total
print(_min)

Solution (Python):






import math
import statistics
import numpy as np
import queue
import itertools

n = int(input())
x = np.array(list(int(i) for i in input().split()))

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

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

ans = 1000000000
for p in range(1,101):
  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()))
ans = 1000000000
for p in range(1,101):
    s = 0
    for x in X:
        s += (x-p)**2
    ans = min(ans, s)
print(ans)

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

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

Solution (Python):

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

ans = 100 * 100 * 100
tmp = 0
for i in range(-1000, 1001): 
    for j in range(n):
        tmp += pow(x[j] - i, 2)
    if ans > tmp:
        ans = tmp
    tmp = 0
print(ans)

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

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n = I()
x = LI()

mx = max(x)
mn = min(x)

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

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

wk = 0
jyuusin = round(sum(a)/len(a))
for i in a:
    wk += (i-jyuusin)**2
print(wk)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
X = LI()

ans = mod
for i in range(1, 101):
    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 = 0
for i in range(N):
    a += X[i]

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

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

X = [int(i) for i in input().split()]
 
s = 10**9  
for i in range(1,100):
  a = []
  for j in range(N):
    a.append((X[j]-i)**2)
     
  s = min(s,sum(a))  

print(s)

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

arr=[]
for p in range(101):
  distance=0
  for xi in x:
    distance+=(xi-p)**2
  arr.append(distance)

print(min(arr))

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

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

Solution (Python):
n = int(input())
places = list(map(int, input().split()))
def cost(point):
    res = 0
    for i in places:
        res += ((i-point) * (i-point))
    return res
ans = float('inf')
for i in range(1, 101):
    ans = min(ans, cost(i))
print(ans)

Solution (Python):
n = int(input())
xlist = [int(i) for i in input().split()]
k = 0
dm = (100**2)*100
while k <= max(xlist):
    d = 0
    for j in range(n):
        d += (xlist[j]-k)**2
    k += 1
    if d < dm:
        dm = d
        xm = k
print(dm)

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

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

d = 0
for p in range(min(x), max(x) + 1):
    c = 0
    for xi in x:
        c += (xi - p) ** 2

    d = c if not d else min(d, c)

print(d)

Solution (Python):

def main():
    N, *X = map(int, open(0).read().split())
    calc = lambda x, p: (x - p) ** 2
    P = sum(X) // N
    ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *X = map(int, open(0).read().split())
    left, right = min(X), max(X)
    ans = min(sum(map(lambda x: (x - p) ** 2, X)) for p in range(left, right + 1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *X = map(int, open(0).read().split())
    calc = lambda x, p: (x - p) ** 2
    left, right = min(X), max(X)
    ans = min(sum(calc(x, p) for x in X) for p in range(left, right + 1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):



from math import *
from copy import *
from string import *				
from random import *				
from sys import stdin
from sys import maxsize
from operator import *				
from itertools import *
from collections import Counter		
from collections import defaultdict 

'''

'''

def solve(l):
	n = len(l)
	minn = 999999999999
	for spot in range(min(l),max(l)+1):
		curr = 0
		for i in range(n):
			curr += (l[i] - spot)**2
		minn = min(minn,curr)
	return minn


N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)