Problem:
 Score : 300 points    Problem Statement There are N people living on a number line.  The i -th person lives at coordinate X_i .  You are going to hold a meeting that all N people have to attend.  The meeting can be held at any integer coordinate . If you choose to hold the meeting at coordinate P , the i -th person will spend (X_i - P)^2 points of stamina to attend the meeting.  Find the minimum total points of stamina the N people have to spend.      Constraints  All values in input are integers.  1 \leq N \leq 100  1 \leq X_i \leq 100         Input Input is given from Standard Input in the following format:  N  X_1  X_2  ...  X_N       Output Print the minimum total stamina the N people have to spend.        Sample Input 1 2
1 4      Sample Output 1 5  Assume the meeting is held at coordinate 2 . In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.  Note that you can hold the meeting only at an integer coordinate.       Sample Input 2 7
14 14 2 13 56 2 37      Sample Output 2 2354

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

X = input().split()
X2 = [0 for _ in range(N)]
for i in range(N):
    X[i]=int(X[i])
    X2[i]=int(X[i])**2
sigma_X = sum(X)
sigma_X2 = sum(X2)
ans = []
    
for P in range(101):
    ans.append(sigma_X2 + N*P**2 - 2*P*sigma_X)
    
print(min(ans))

Solution (Python):
n = int(input())
X = sorted(map(int,input().split()))
ans = 10**6

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

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

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

ave = sum(X) // len(X)

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

print(min(ans1, ans2))

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

X.sort()
tairyoku = 0
HP = []
for p in range(100):
    
    for i in range(N):
        tairyoku += (X[i] - p)**2

    HP.append(tairyoku)
    tairyoku = 0

print(min(HP))

Solution (Python):


def main():
    *N, = map(int, open(0).read().split())
    X = N[1:]
    N = N[0]

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


main()

Solution (Python):

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
X = np.array(lr())

answer = 10 ** 6
for x in range(101):
    temp = ((X-x) ** 2).sum()
    if temp < answer:
        answer = temp

print(answer)

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

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

Solution (Python):

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

cost = []
for p in range(-1000,1001):
    tmp = 0
    for i in xi:
        tmp += pow((p - i), 2)
    cost.append(tmp)

print(min(cost))

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

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

ans = 0

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

print(ans)

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

for i in range(100):
    sum = 0
    for j in range(len(x)):
        sum += (x[j] - i)**2
    if i == 0:
        ans = sum
    else:
        ans = min(ans, sum)
print(ans)

Solution (Python):
n=int(input())
xlist=list(map(int,input().split(" ")))
count=100000000000

for kaisai in range(101):
    sum=0
    for hito in xlist:
        sum+=(hito-kaisai)**2
    
    if sum<count:
        count=sum
print(count)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
s=[]
for i in range(max(a)+1):
  m=0  
  for j in range(0,len(a)):
    m+=(a[j]-i)**2
  s.append(m)
print(min(s))

Solution (Python):
def II(): return int(input())
def MI(): return map(int,input().split())
def LMI(): return list(map(int,input().split()))
def LIIN(n): return list(int(input()) for _ in range(n))
def LMIN(n): return [list(map(int, input().split())) for _ in range(n)]
def IS(): return input()
def MS(): return map(str,input().split())
def LMS(): return list(map(str,input().split()))
def LISN(n): return list(input() for _ in range(n))
def LMSN(n): return [input().split() for _ in range(n)]
MOD = 10**9+7
INF = 10**18

def main():
    n = II()
    x = LMI()
    a = sum(x) // len(x)
    a2 = a + 1
    print(min(sum([(i-a)**2 for i in x]),sum([(i-a2)**2 for i in x])))

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
min_sum = float('inf')
for i in range(X_min, X_max+1):
    sum = 0
    for j in X:
        sum += (j-i)**2
    min_sum = min(min_sum, sum)
print(min_sum)

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

Solution (Python):
N=int(input())
A=[int(x) for x in input().rstrip().split()]
ave=sum(A)//len(A)
ans=0

if N/2<(sum(A)%len(A)):
  ave+=1

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

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

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

ans = float('inf')

for i in range(100):
  tmp = 0
  for x in X:
    tmp += (x-i) ** 2

  ans = min(ans,tmp)

print(ans)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
ans = 100**3
for i in range(-1000,1001):
    sum = 0
    for j in range(n):
        sum += (a[j]-i)**2
    if ans > sum:
        ans = sum

print(ans)

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 x:
        temp+=(j-i)**2
    ans=min(ans,temp)

print(ans)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
middle = int(s/n + 0.5)
ans = 0
for i in range(n):
	ans += (l[i] - middle) * (l[i] - middle)
print(ans)

Solution (Python):
n = int(input())
x = input().split()
sumd = 0
for i in x:
  sumd += int(i)
p = int(sumd/n)+(sumd%n>=n/2)
sums = 0
for i in x:
  sums += (int(i)-p)*(int(i)-p)
print(sums)

Solution (Python):
import numpy as np

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

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

print(dis)

Solution (Python):
import numpy as np

N = int(input())
X = [int(_) for _ in input().split()]
X = np.array(X)

sumlist = []
for i in range(1, max(X)+1):
    minus = np.array([i] * N)
    res = X - minus
    vlist = map(lambda x: x**2, res)
    sumlist.append(sum(vlist))

print(min(sumlist))

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

x = [0] * n

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

x.sort()
sum = 0
min_sum = 100 * 10000
for i in list(range(x[0], x[-1] + 1)):
    sum = 0
    for j in x:
        sum += (j - i) * (j - i)
    if sum < min_sum:
        min_sum = sum
print(min_sum)

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

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))

Solution (Python):

def main():
  n = int(input())
  X = tuple(map(int, input().split(" ")))

  mx = max(X)
  mn = min(X)

  ans = float("inf")

  for p in range(mn, mx + 1):
    ans = min(ans, sum([(x - p) ** 2 for x in X]))

  print(ans)


main()

Solution (Python):
n,*x=map(int,open(0).read().split())
ans=10**9
for p in range(1,101):
  tmp=0
  for i in range(n):
    tmp+=(x[i]-p)**2
  if tmp<ans:
    ans=min(ans,tmp)
print(ans)

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

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

Solution (Python):


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


ans = 0
for i in range(1, 101, 1):
    sub_life = sum([(j - i) ** 2 for j in X])

    if i == 1 or ans > sub_life:
        ans = sub_life

print(ans)

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

X.sort()
X_min = X[0]
X_max = X[N-1]

result = -1
total = 0
for P in range(X_min, X_max+1):
    for x in X:
        total = total + (x-P)**2
    if (total < result or result < 0):
        result = total
    elif (total > result):
        break
    total = 0
print(result)

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

cost_list = []

for p in range(min(zyunin_list), max(zyunin_list) + 1):
    cost = 0
    for zahyo in zyunin_list:
        cost += (zahyo - p) ** 2
    cost_list.append(cost)

print(min(cost_list))

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

Solution (Python):

n = int(input())
x = list(map(int, input().split()))
t = []
for p in range(1, 101):
    q = 0
    for j in x:
        q += (j-p)**2
    t.append(q)
print(min(t))

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

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

Solution (Python):
N = int(input()) 
x = list(map(int, input().split()))
sumx = 0
ans = 0
ans1 = 0
ans2 = 0
for i in x:
  sumx += i

if sumx % N == 0:
  for i in x:
    ans += (i-sumx//N)**2
else:
  for i in x:
    ans1 += (i-sumx//N)**2
    ans2 += (i-sumx//N-1)**2
  ans = min(ans1, ans2)
    
print(ans)

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

tmp_m = 10 ** 10
for i in range(1, max(X)+1):
    tmp = 0
    for j in range(N):
        tmp += (X[j] - i) ** 2

    tmp_m = min(tmp_m, tmp)

print(tmp_m)

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

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

print(min(answers))

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

Solution (Python):
N=int(input())
X=[int(i) for i in input().split()]
avg=round(sum(X)/len(X))
summy=0
for i in X:
    summy+=(i-avg)**2
print(summy)

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

Solution (Python):
from statistics import mean 
from math import ceil,floor 
n=int(input())
arr=[int(x) for x in input().split()]
a1=ceil(mean(arr))
a2=floor(mean(arr))
s1=0
s2=0
for i in range(n):
    s1+=((arr[i]-a1)**2)
    s2+=((arr[i]-a2)**2)

print(min(s1,s2))

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

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

def calc_energy(i, X):
    X = np.array(X)
    return sum((X-i)**2)

min_energy = 1000000000
min_ind = min(X)
max_ind = max(X)
for i in range(min_ind, max_ind+1):
   energy = calc_energy(i, X) 
   if energy < min_energy:
       min_energy = energy
print(min_energy)

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

ans = 0

ave = round(sum(x)/n)

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

print(ans)

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

ave=round(sum(X_)/N)
ans=[]
for x_ in X_:
  ans.append((x_-ave)**2)

  
print(sum(ans))

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

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    N = II()
    X = LI()
    min = 10**9


    for p in range(1,100):
        S = 0
        for i in range(N):
            S = S + (X[i]-p)**2
        
        if min > S:
            min = S


    print(min)



if __name__ == "__main__":
	main()

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0

for i in range(min(X), max(X) + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
if len(hp) == 1:
  print(0)
else:
  hp.remove(0)
  print(min(hp))

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

Solution (Python):
n = int(input())
s = input().split()
s_int = sorted([int(a) for a in s])
total = 0
for num in s_int:
  total += num
a = round(total/n)
ans = 0
for num1 in s_int:
  ans += (num1 - a)**2
print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
m=int(sum(a)/n)
m1=m-1
m2=m+1
s=0
s1=0
s2=0
for i in range(n):
    s+=(a[i]-m)**2
    s1+=(a[i]-m1)**2
    s2+=(a[i]-m2)**2
print(min(s,s1,s2))

Solution (Python):
import math

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

mean = math.ceil(sum(x) / n)

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

if sum(x) % n != 0:
	mean -= 1
	ans2 = 0
	for i in range(n):
		ans2 += (x[i]-mean) ** 2

	print(min(ans1,ans2))
else:
	print(ans1)

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

syukai = sum(x)//n
ans=0
ans1=0
ans2=0
for i in range(n):
    ans += pow(x[i]-syukai-1,2)
    ans1 += pow(x[i]-syukai,2)
    ans2 += pow(x[i]-syukai+1,2)
print(min(ans,ans1,ans2))

Solution (Python):
import math
def I():
  return input()
def II():
  return int(input())
def MII():
  return map(int, input().split())
def LMII():
  return list(map(int, input().split()))

n = II()
a = LMII()
ans = 99999999999999999
for i in range(1, 101):
  count = 0
  for j in range(n):
    count += (i-a[j])**2
  if count < ans:
    ans = count
print(ans)

Solution (Python):
def main():
    N = int(input())
    X = [int(x) for x in input().split()]
    ans = []
    mini = min(X)
    maxi = max(X)
    if mini != maxi:
        for i in range(mini, maxi):
            a = map(lambda x: (x-i)**2, X)
            ans.append(sum(a))
    else:
        ans.append(0)
    return print(min(ans))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
p.sort()
min = -1
sum = -1

for i in range(p[0], p[-1] + 1):
    tmp_sum = 0
    for j in range(len(p)):
        tmp_sum += (p[j] - i)** 2
    if sum == -1 or sum > tmp_sum:
        sum = tmp_sum

print(sum)

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

l=[]

for p in range(1,101):
  sum=0
  
  for i in range(N):
    sum += (x[i]-p)**2
  
  l.append(sum)
  
print(sorted(l)[0])

Solution (Python):
if __name__ == '__main__':
    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):
import numpy as np
N=int(input())
X=list(map(int, input().split()))
X.sort()
Y=sum(X)/N
if Y-int(Y)>0.5:
    Y=int(Y)+1
else:
    Y=int(Y)
X=[(i-Y)**2 for i in X]
print(sum(X))

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

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

res = 10 ** 15
for p in range(1, 100):
    cnt = 0
    for i in range(N):
        cnt += (X[i] - p) ** 2
    res = min(res, cnt)

print(res)

Solution (Python):
N=int(input())
x=list(map(int, input().split()))
a=0
b=0
for i in range(N):
  a+=x[i]**2
for j in range(N):
  b+=x[j]
def func(p):
  return a-2*p*b+(p**2)*N

q=b//N

print(min(func(q),func(q+1)))

Solution (Python):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
x = readints()
ans = INF
for i in range(1, 101):
    tmp = 0
    for j in range(N):
        tmp += (x[j]-i)*(x[j]-i)
    ans = min(ans, tmp)
print(ans)

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


from decimal import Decimal, ROUND_HALF_UP

y = Decimal(str(sum(Xlist)/N))

P = y.quantize(Decimal('0'), rounding=ROUND_HALF_UP)


num=0
for i in range(len(Xlist)):
    num += (Xlist[i]-P)**2

print(num)

Solution (Python):
import numpy as np
import math


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

X_s = np.array(X_s)
P=np.sum(X_s)/N

P_floor = math.floor(P)
P_ceil = math.ceil(P)

A=np.sum((X_s-P_floor)**2)
B=np.sum((X_s-P_ceil)**2)

print(min(A,B))

Solution (Python):

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

s = sum(X)
l = len(X)
ave = s/l

if ave - float(int(ave)) <= 0.5:
  avei = int(s/l)
else:
  avei = int(s/l) + 1

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

print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
s = sum(X)
l = len(X)
ave = s/l
if ave - float(int(ave)) <= 0.5:
  avei = int(s/l)
else:
  avei = int(s/l) + 1
ans = 0
for i in range(N):
  ans += (X[i] - avei)**2
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
s = []
for i in range(1,101):
    b = sum((a[j]-i)**2 for j in range(N))
    s.append(b) 
print(min(s))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = 10**6
for i in range(1,101):
    b = sum((a[j]-i)**2 for j in range(0,N))
    ans = min(ans,b)
print(ans)

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

p = round(sum(x)/n) 

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

print(ans)

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

if average%1<=0.5:
  average=int(average)
else:
  average=int(average)+1

ans=0

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

print(ans)

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

def sg(li):
    be = sum(li) / len(li)
    if be >= int(be) + 0.5:
        return int(be) + 1
    else:
        return int(be)

P = sg(X)
cnt = 0
for x in X:
    cnt += (x - P)**2
    
print(cnt)

Solution (Python):
n = int(input())
hp = list(map(int,input().split()))
a = []
for i in range(0,101):
  s = sum((hp[j]-i-1)**2 for j in range(0,n))
  a.append(s)

print(min(a))

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

Solution (Python):
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
min = 0
for k in li:
    min += (k-1) ** 2
i = 2
while i <= 100:
  s = 0
  for k in li:
    s += (k-i) ** 2
  if s < min:
    min = s
  i += 1
print(min)

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

Solution (Python):
import numpy as np

N = int(input())

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

hp_sum = []
for i in range(1, 101):
  tmp = abs(coordinate - i)
  hp_sum.append(sum(tmp ** 2))

print(min(hp_sum))

Solution (Python):
n = int(input())
s = list(map(int,input().split(" ")))
sum_st = 10000000000
for p in range(1,max(s)+1):
  sum_sti = 0
  for x in s:
    sum_sti += (x-p)**2
  if sum_sti < sum_st:
    sum_st = sum_sti
print(sum_st)

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

candidates = []
for p in range(min(X), max(X)+1):
    
    
    c = sum([(x - p)**2 for x in X])
    candidates.append(c)

print(min(candidates))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
mi = min(X)
ma = max(X)
A = []
for i in range(mi,ma+1):
  B = 0
  for j in X:
    B += (j - i)**2
  A.append(B)
print(min(A))

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

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

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

min_P = 0
min_cost = float('inf')
for P in range(1, 101):
    cost = 0
    for Xi in X:
        cost += (Xi-P)**2
    if min_cost > cost:
        min_cost = cost
        min_P = P
print(min_cost)

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

hp = 0
hp2 = 0

p = sum(x)//n
for i in range(n):
    hp += (x[i-1]-p)**2
    hp2 += (x[i-1]-(p+1))**2

print(min(hp,hp2))

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

print(m)

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

min = 1000001

for i in range(1,101):
    damage = 0
    for j in x_list:
        damage += (j - i)**2
    if damage < min:
        min = damage
print(min)

Solution (Python):
N, *X = map(int, open(0).read().split())

m = sum(X) // N
v1 = sum((v - m) ** 2 for v in X)
v2 = sum((v - m - 1) ** 2 for v in X)
print(min(v1, v2))

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

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

head = min(X)
tail = max(X)

min_score = float('inf')
for p in range(head, tail+1):
    min_score = min(sum(map(lambda x: (x - p)**2, X)), min_score)

print(min_score)

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

ave = 0
for i in range(n):
    ave += x[i]
ave /= n
ave = int(ave+0.5)

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

print(ans)

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

line = [0]*(100)

for i in s:
    for j in range(1,101):
        line[j-1] += (i-j)**2

print(min(line))

Solution (Python):


n=int(input())
x=list(map(int, input().split()))
x.sort()
minimum=10**23
for i in range(x[0],x[-1]+1):
    sum=0
    for l in x:
        sum+=(l-i)**2
    minimum=min(sum,minimum)
print(minimum)

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

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

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

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

print(r)

Solution (Python):


N = int(input())
X = list(map(int, input().split()))
X_max = max(X)
X_min = min(X)
tes_min = 10000000

for i in range(X_min, X_max + 1):
    tes = 0
    for j in X:
        tes += (j - i)**2
    if tes_min > tes:
        tes_min = tes
print(tes_min)

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




su = 0
P = round(sum(Xn) / N)
for x in Xn:
  su += (x-P) ** 2
print(int(su))

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

p0 = math.floor(x.sum()/n)
p1 = math.ceil(x.sum()/n)
cost0 = np.sum((x-p0)**2)
cost1 = np.sum((x-p1)**2)
print(min(cost0, cost1))

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

Solution (Python):
import numpy as np

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

mean_x = int(sum(x_s)/n)
a_s = [(x - mean_x)**2 for x in x_s]
a = sum(a_s)
b_s = [(x - mean_x - 1)**2 for x in x_s]
b = sum(b_s)

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

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))
A = math.ceil(sum(X)/N)
B = math.floor(sum(X)/N)
ans_1 = 0
ans_2 = 0
for i in range(N):
    ans_1 += (X[i]-A)**2
for j in range(N):
    ans_2 += (X[j]-B)**2
print(min(ans_1,ans_2))

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

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

p=round(sum(X)/n)
ans=0
for i in range(n):
	ans+=(X[i]-p)**2

print(ans)

Solution (Python):
import math

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

ave = sum(X) / len(X)

m = math.floor(ave)
M = math.ceil(ave)

def f(x):
  ans = 0
  for i in X:
    ans += (x - i)**2
  return ans  

print(min(f(m), f(M)))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
M = max(x)
s = [0]*(10*M)

for j in range(10*M):
	for i in range(n):
		s[j] += pow(x[i]-(j-5*M),2)
print(min(s))

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

mid = round(sum(X)/N)
ans = 0
for i in range(N):
    Q = X[i] - mid
    ans += Q*Q
print(ans)

Solution (Python):
import math
n = int(input())
data = input().split(' ')
x_list = list(map(lambda x: int(x), data))
opt_p_center = sum(x_list) / n  
opt_p_left = math.floor(opt_p_center)
opt_p_right = math.ceil(opt_p_center)
opt_p = opt_p_left if opt_p_center < (opt_p_left + opt_p_right) / 2 else opt_p_right
ans = sum(list(map(lambda x: (x - opt_p)**2, x_list)))
print(ans)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
ans = 10 ** 10
for i in range(min(l), max(l) + 1):
    can = 0
    for j in l:
        can += (j - i) ** 2
    if can < ans:
        ans = can
print(int(ans))

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

P = int(round(sum(X)/N,0))
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())))
k = round(sum(x) / n)
print(int(sum((x - k)**2)))

Solution (Python):
import numpy as np
n = int(input())
x = np.array(list(map(int, input().split())))
k = sum(x) // n
x1 = (x - k) ** 2
x2 = (x - k - 1) ** 2
print(min(sum(x1), sum(x2)))

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

mean = np.mean(X)
p = int(mean) if mean % 1 < 0.5 else int(mean) + 1
stamina = 0
for x in X:
    stamina += (x - p)**2
print(stamina)

Solution (Python):
import numpy as np
n = int(input())
x = np.array([int(i) for i in input().split()])
p = min(sum((x - np.floor(x.mean())) ** 2), sum((x - np.ceil(x.mean())) ** 2))
print(int(p))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
pdlist = []
for i in range(max(x) + 1):
  p = i
  dlist = []
  for j in x:
    dlist.append(int((int(j) - int(p)) ** 2))
  sumd = sum(dlist)
  pdlist.append(sumd)
minpdlist = min(pdlist)
print(minpdlist)

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

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


P = 0.0
for xn in X:
    P += xn/N
P = round(P)
    
ans = 0
for xn in X:
    ans += (xn - P)**2
    
print( int(ans) )

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

Solution (Python):
import numpy as np
n=int(input())
x=list(map(int,input().split()))
s=int(sum(x)/n)
t=s+1
X=np.array(x)
P=np.ones(n)*s
Q=P+np.ones(n)
ans=min(sum((X-Q)**2),sum((X-P)**2))
print(int(ans))

Solution (Python):
from functools import reduce
a=int(input())
b=list(map(int,input().split()))
c=reduce(lambda a,b:a+b,b)
d=int(c/a)
def x(a,b,c):
    t=a.copy()
    c=[c]*b
    t=list(map(lambda x,y:x-y,t,c))
    return reduce(lambda a,b:a+b*b,t,0)
ans=min(x(b,a,d),x(b,a,d+1),x(b,a,d-1))
print(ans)

Solution (Python):
import math
def main():
  N=int(input())
  X=list(map(int,input().split()))
  x_mean=round(sum(X)/len(X))
  sumX=0
  for i in range(len(X)):
    sumX=sumX+(X[i]-x_mean)**2
  print(sumX)

if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
mn = 10**9
for p in range(101):
    sum_mn = 0
    for i in range(n):
        sum_mn += (p-x[i])**2
    if mn > sum_mn:
        mn = sum_mn
print(mn)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
A = 0
B = 0
for i in range(N):
	A += (X[i])**2
	B += X[i]
def ans(A,B,n,x):
	return A-2*x*B+n*(x**2)
	
res = 99999999999
for i in range(1,101):
	res = min(res,ans(A,B,N,i))
	
print(res)

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

ans = 10**20 
for i in range(1,101): 
    dis = 0
    for j in x:
        dis += (i-j)**2
    ans = min(ans,dis)

print(ans)

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

average = sum(A) // N
ans1 = 0
for i in A:
    ans1 += (i-average)**2
ans2 = 0
for i in A:
    ans2 += (i-average-1)**2
ans = min(ans1, ans2)

print(ans)

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

ave = sum(X) // N
E1 = []
E2 = []

for i in X:
    E1.append((i - ave-1) ** 2)
    E2.append((i - ave) ** 2)
    
print(min(sum(E1), sum(E2)))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
min_x=sum(x)/n
int_x=int(min_x)
if min_x-int_x <= int_x+1-min_x:
    mp=int_x
else:
    mp=int_x+1
ans=0
for i in range(n):
    ans+=(x[i]-mp)**2
print(ans)

Solution (Python):
import numpy as np

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

small = x.min()
big = x.max()

min_cost = 1e10

for i in range(small, big+1):
    cost = ((x - i)**2).sum()
    min_cost = np.minimum(cost, min_cost)

print(int(min_cost))

Solution (Python):
N = int(input())
Xi= list(map(int,input().split()))
ans = 0
for i in range(1,max(Xi)+1):
	total_energy =0
	for n in range(N):
		energy = (Xi[n]-i)**2
		total_energy = total_energy + energy
	if i == 1:
		ans = total_energy
	elif ans > total_energy:
		ans = total_energy
print(ans)