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

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
dist = float("inf")
d = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin, xmax + 1):
	d = 0
	for x in X:
		d += (x - i) ** 2
	if d < dist:
		dist = d
print(dist)

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))
xs_min = min(xs)
xs_max = max(xs)

fatigue_min = float("inf")

for i in range(xs_min, xs_max + 1):
  fatigue = 0
  for x in xs:
    fatigue += (x - i) ** 2
  if fatigue < fatigue_min:
    fatigue_min = fatigue
  else:
    print(fatigue_min)
    exit()
else:
  print("0")

Solution (Python):

from collections import Counter
def inputlist(): return [int(j) for j in input().split()]

N = int(input())
X = inputlist()
ans = 10**9+7
for i in range(110):
    k = 0
    for j in range(N):
        k += (X[j] - i)**2
    ans = min(ans,k)
print(ans)

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

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

Solution (Python):
def solution():
    n = int(input())
    x = list(map(int, input().split()))
    aida = round(sum(x) / n)
    ans = [(i-aida)**2 for i in x]
    print(sum(ans))

solution()

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
T = 10000000
for p in range(1,101):
    t = 0
    for x in X:
        t += (x-p)**2
    T = min(t,T)
print(T)

Solution (Python):
import numpy as np

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

p = [int(np.mean(x)), int(np.mean(x)) + 1]
xnp = np.array(x)

min_xp = -1
for pi in p:
    if min_xp == -1:
        min_xp = np.square(xnp - pi).sum()
    elif min_xp > np.square(xnp - pi).sum():
        min_xp = np.square(xnp - pi).sum()
print(min_xp)

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

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

HP = [0] * 100

for k in range(1, 101):
    for i in range(N):
        HP[k-1] += (X[i] - k) ** 2

print(min(HP))

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

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect




from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  x = list(map(int, readline().split()))
  ave = int(sum(x)/n+0.5)
  ans = 0
  for i in range(n):
    ans += (x[i]-ave)**2
  print(ans)
  
if __name__ == '__main__':
  main()

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

ans = 10 ** 9

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

print(ans)

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

zahyo = 10**15

for i in range(101):
    tmp = 0
    for j in range(N):
        tmp += (X[j]-i)**2
    zahyo = min(zahyo, tmp)
print(zahyo)

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


mean = math.floor(sum(x)/len(x))
mean2 = mean + 1
ans = 0
ans2 = 0
for i in x:
    ans += (i - mean) ** 2
    ans2 += (i - mean2) ** 2

if ans <= ans2:
    print(ans)
    exit()
else:
    print(ans2)
    exit()

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

for i in range(len(x)):
    sum = sum + x[i]

point = round(sum/n)

cost = 0
for j in range(len(x)):
    cost = cost + (x[j] - point) ** 2

print(cost)

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

	ans = 10000000

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

		if ans > s:
			ans = s

	print(ans)

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 range(len(x)):
    s=s+(x[j]-i)**2
  ans=min(ans,s)
print(ans)

Solution (Python):
N=int(input())
x=input().split()
x=[int(s) for s in x]
b=sum(x)/N
if b>int(b)+0.5:
    b=int(b)+1
else:
    b=int(b)
d=0
for i in x:
    c=(i-b)**2
    d+=c
print(d)

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

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

x.sort()
cnt = 0
minimum = 0
for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2

    if i == x[0]:
        minimum = cnt

    minimum = min([minimum, cnt])
    cnt = 0

print(minimum)

Solution (Python):
import numpy as np
N = int(input())
X = np.array(input().split(),np.int64)
ls = []
for i in range(101):
    ls.append(np.sum((X - i) ** 2))

print(min(ls))

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

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

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

print(minimum)

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
X = iil()
ti = 100*100*100
for i in range(1,101):
    cal = 0
    for item in X:
        cal += (item-i)**2
    ti = min(cal,ti)

print(ti)

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

for p in range(1,101):
    total = 0
    for i in range(N):
        total += (X[i] - p) ** 2
    if p == 1:
        result = total
    elif total < result:
        result = total
print(result)

Solution (Python):
N = int(input())
X = [0]*N
sum = 0
P = 0
P1 = 0
T = 0
T1 = 0
X = [int(N) for N in input().split()]
for i in range(N):
    sum +=X[i]
P = int(sum/N)
P1 = int((sum/N)+1)
for i in range(N):
    T += (X[i]-P)*(X[i]-P)
    T1 += (X[i]-P1)*(X[i]-P1)
if T>T1:
    print(T1)
else:
    print(T)

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

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

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

Solution (Python):
import math

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

sX = sum(X)
kouho1 = math.ceil(sX / N)
kouho2 = sX // N
kouho3 = math.floor(sX / N)


ans1, ans2, ans3 = 0, 0, 0
for p in X:
    ans1 += (p - kouho1) ** 2
    ans2 += (p - kouho2) ** 2
    ans3 += (p - kouho3) ** 2

print(min(ans1, ans2, ans3))

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

tairyokus = []
for p in range(1, 101):
    tairyoku = 0
    for x in X:
        tairyoku += (x - p) ** 2
    tairyokus.append(tairyoku)
print(min(tairyokus))

Solution (Python):
import sys
n = int(input())
x = [int(i) for i in input().split()]
m = sys.maxsize
for i in range(min(x), max(x) + 1):
    sum = 0
    for j in x: sum += (j - i) ** 2
    if sum < m: m = sum
print(m)

Solution (Python):
N = input()
Xi = list(map(int,input().split()))
num = 0
temp = []
for P in range(min(Xi),max(Xi)+1):
    num = 0
    for X in Xi:
        num += (X - P)**2
    temp.append(num)
print(min(temp))

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

print(ans)

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
total = 0
mini = 100**9
for p in range(1,101):
  for i in A:
    total += (i-p)**2
  if total < mini:
    mini = total
  total = 0
print(mini)

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

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

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

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

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    else:
        break
        
print(p)

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    
    
        
print(p)

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
p = [0]*100
for i in range(100):
    for j in range(n):
        p[i] += (x[j]-(i+1))**2
print(min(p))

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

Solution (Python):
import sys
def solve():
    readline=sys.stdin.buffer.readline
    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()

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

mn=10**18

for p in range(1,101):
    sm=0
    for x in X:
        sm+=(x-p)**2
    
    mn=min(sm,mn)
print(mn)
'''

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

mn=10**18

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

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

mn=10**18

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

Solution (Python):
N=int(input())
X=[int(i) for i in input().split(" ")]
sp=lambda P:sum([(Xi-P)**2 for Xi in X])
print(min([sp(p) for p in range(0,102)]))

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

ave = sum(x)/n
ans1 = sum([(i - int(ave))**2 for i in x])
ans2 = sum([(i - int(ave + 1))**2 for i in x])

print(min(ans1, ans2))

Solution (Python):
n=int(input())
M=list(map(int,input().split()))
m=sorted(M)
l=[]
for p in range(m[0],m[n-1]+1):
  L=0
  for i in range(n):
    L+=(m[i]-p)**2
  l.append(L)
print(min(l))

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

d = [0] * 100

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

print( min( d ) )

Solution (Python):
import sys

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


def cal(number):
    an = 0
    for X in Xn:
        an += (X - number)**2
    return an

ans = sys.maxsize
for i in range(min(Xn), max(Xn)+1, 1):
    ans = min(ans, cal(i))

print(ans)

Solution (Python):
import numpy as np

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

mins = x.min()
maxs = x.max()

dis = np.inf
for p in range(mins, maxs+1):
  temp = np.sum((x - p) ** 2)
  if dis > temp:
    dis = temp
    
print(dis)

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

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

X.sort()
min_cost = float('inf')
sum_cost = 0
m = X[N-1]
for i  in range(m):
  i += 1
  for xi in X:
    sum_cost +=  (i-xi)**2
  if min_cost > sum_cost:
    min_cost = sum_cost
  sum_cost = 0
    
print(int(min_cost))

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

l = []

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

print(min(l))

Solution (Python):

import math


def calc_energy_sum(x_list, p):
    energy_list = [(x - p) ** 2 for x in x_list]
    energy_sum = sum(energy_list)
    return energy_sum


N = int(input())
X_list = [int(s) for s in input().split()]

p = sum(X_list) / len(X_list)


p_l = math.floor(p)

energy_sum_l = calc_energy_sum(X_list, p_l)


p_u = math.ceil(p)

energy_sum_u = calc_energy_sum(X_list, p_u)


energy_sum = min([energy_sum_l, energy_sum_u])
print(energy_sum)

Solution (Python):
N = int(input())
X = list(map(int, input().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 = tmp

print(ans)

Solution (Python):
n = int(input())
ls =list(map(int, input().split()))
t = len(ls)
a=[]
b=[]
for i in range(1,101):
    for j in range(t):
        p = (ls[j]-i)**2
        a.append(p)
    b.append(sum(a))
    a=[]
b.sort()
print(b[0])

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

ans = float("inf")
for P in range(1, 100+1):
  power_sum = 0
  for i in range(N):
    power_sum += (X[i]-P)**2
  if power_sum < ans:
    ans = power_sum

print(ans)

Solution (Python):
min_hp = 10 ** 7
n = int(input())
xs = list(map(int, input().split()))
for i in range(1, 101):
    min_hp = min(sum((x-i)**2 for x in xs), min_hp)
print(min_hp)

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

min_dis = 1e10
for p in range(min(x),max(x)+1):
    dis = 0
    for y in x:
        dis += (p-y)*(p-y)
    min_dis = min(dis, min_dis)
print(min_dis)

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

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

Solution (Python):
import numpy as np

n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / len(x))
x_arr = np.array(x)
print(sum((x_arr - p) ** 2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
HP1 = 0
HP2 = 0
P1 = sum(X) // N
P2 = sum(X) // N + 1

for Xi in X:
    HP1 = HP1 + (Xi - P1) ** 2
    HP2 = HP2 + (Xi - P2) ** 2

print(min(HP1, HP2))

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

mn = 1000000
for p in range(1, 100):
  sum = 0
  for q in x:
    sum += (q-p)**2
  mn = min(mn, sum)

print(mn)

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

s = round(sum(li)/len(li))

ans = 0
for i in li:
    ans += (i-s)**2
    
print(ans)

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

for i in range(100):
    L0=0
    for ii in range(N):
        L0+=(i+1-X[ii])**2
    
    if i==0:
        L=L0
    else:
        L=min(L,L0)
print(L)

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

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

ave = sum(x) // n
ans = 10 ** 18
for i in range(ave, ave + 2):
    s = 0
    for y in x:
        s += (y - i) ** 2
    ans = min(ans, s)
print(ans)

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

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

b=int(round(sum(x)/a))

count=0
for i in x:
  count=count+(i-b)*(i-b)
  
print(count)

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

    
    
    
    AVG = int(sum(X)/len(X))    
    AVG1 = int(sum(X)/len(X)) + 1    

    total = 0
    total1 = 0
    for i in X:
        total += (AVG - i)**2

    for i in X:
        total1 += (AVG1 - i)**2

    if total >= total1:
        print(total1)
    else:
        print(total)

main()

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

for n in range(1,101):
    s = 0
    for x in X:
            s = s + ((x-n)*(x-n))
    sum.append(s)

print(min(sum))

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

sum=0
Ans=0
count=0
Xmax=sorted(X)[N-1]
Xmax2=sorted(X)[N-2]

for i in range(2*Xmax):
    sum=0
    for j in range(N):
        sum+=(X[j]-i)**2
    count+=1
    if count==1:
        Ans=sum
    Ans=min(Ans,sum)
    

print(Ans)

Solution (Python):
def get_x(arr):
  pass


def main():
  input()
  X = list(map(int,input().split()))
  ans = 10 ** 8
  for i in range(min(X), max(X)+1):
    nums = [(x-i)**2 for x in X]  
    if sum(nums) < ans:
      ans = sum(nums)
  print(ans)

    
if __name__ == "__main__":
  main()

Solution (Python):

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

HPlist = []

for num in range(100):
    tmp = 0
    for pnum in x:
        tmp += (pnum - num) ** 2
    HPlist.append(tmp)

print(min(HPlist))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
a = max(x)
b = min(x)
y = 0
ans = 10000000

for i in range (b,a+1): 
  y = 0 
  for j in x: 
    y = y + (j-i)**2
  if y < ans:
    ans = y

print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
p=sum(X)/N
if p-int(p)>=0.5:
    P=int(p)+1
else:
    P=int(p)
S=0
for i in range(N):
    S+=(X[i]-P)**2
print(S)

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

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

print(mini)

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

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

maxX=max(x)
minX=min(x)

mindis=0

for i in range(minX,maxX+1):
  dis=0
  for j in x:
    dis+=(j-i)*(j-i)

  if mindis==0 or mindis>dis:
    mindis=dis

print(mindis)

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

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

mean_x = sum(x) / len(x)

cost = 0
for i in range(len(x)):
    cost += (x[i] - round(mean_x)) ** 2
print(cost)

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

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

Solution (Python):

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

P = []

for i in range(1,101):
    sa = list(map(lambda x:x-i, X))
    nizyo = list(map(lambda x:x**2, sa))
    summ = sum(nizyo)
    P.append(summ)

print(min(P))

Solution (Python):
import sys

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

ret = sys.maxsize

for i in range(min(X) , max(X) + 1):
    pow = 0
    for x in X:
        pow += (x - i) ** 2
    if pow < ret:
        ret = pow

print(ret)

Solution (Python):
import sys

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

ret = sys.maxsize


for i in range(1, 100):
    pow = 0
    for x in X:
        pow += (x - i) ** 2
    if pow < ret:
        ret = pow

print(ret)

Solution (Python):
n = int(input())
x_n = list(map(int, input().split()))
ave = sum(x_n)//n
res = 0
for x_i in x_n:
    res += x_i**2
for p in range(ave - 2, ave + 3):
    point = 0
    for x_i in x_n:
        point += (x_i - p)**2
    res = min(res, point)
print(res)

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

cost = 1e9
for pos in range(1, 101):
    tmp_cost = 0
    for xi in X:
        tmp_cost += (pos - xi)**2
    if tmp_cost < cost:
        cost = tmp_cost
print(cost)

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
cost=0
for i in range(len(X)):
    cost=cost+X[i]**2

for i in range(1,101):
    cost2=0
    for j in range(len(X)):
        cost2=cost2+(X[j]-i)**2
    cost=min(cost,cost2)

print(cost)

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

k = round(sum(l) / n)
ans = 0
for i in l:
    ans += (k - i) ** 2

print(ans)

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

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

Solution (Python):
import numpy as np
N = int(input())
X = list(map(int, input().split()))
p1 = int(np.mean(X))
S1 = np.sum([(x-p1)**2 for x in X])
p2 = p1 + 1
S2 = np.sum([(x-p2)**2 for x in X])
print(min(S1, S2))

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

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

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

ANS = float("inf")

for i in range(0, 101):
    tmp = 0
    for j in X:
        tmp += abs(i - j) ** 2

    if tmp < ANS:
        ANS = tmp

print(ANS)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
p = sum(x) // n
a1 = sum((xi - p)**2 for xi in x)
a2 = sum((xi - -~p)**2 for xi in x)
print(min(a1, a2))

Solution (Python):
num = int(input())
member = list(map(int, input().split()))
min_num = min(member)
max_num = max(member)
min_hp = 10000000
for i in range(min_num, max_num + 1):
    hp = 0
    for j in member:
        hp += (j - i) ** 2
    
    if hp < min_hp:
        min_hp = hp
print(min_hp)

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

Solution (Python):
def main():
    a = int(input())
    n = list(map(int, input().split()))
    sum_dists = []
    for i in range(1, 101):
        sum_dists.append(sum([(d - i)**2 for d in n]))

    print(min(sum_dists))

if __name__ == "__main__":
    main()

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

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

Solution (Python):

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

tairyoku =[]

for P in range(X_min,X_max + 1): 
    tairyoku.append([(x_j - P)**2 for x_j in X ])
tairyoku_sum = [sum(i) for i in tairyoku ]


print(min(tairyoku_sum))

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

X = input().split()

i = 0
sum = 0

while i < N:
  x = int(X[i])
  sum += x
  i += 1

P = round(sum / N)

dis = 0
i = 0


while i < N:
  z = int(X[i])
  dis += (P - z) ** 2
  i += 1

print(dis)

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

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
L, R = min(X), max(X)

ans = 10**1000
for i in range(L, R+1):
    box = 0
    for j in range(N):
        box += (X[j] - i)**2
    if ans > box:
        ans = box

print(ans)

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

sum=0
for i in range(n):
  sum=sum+x[i]

if (sum/n)%1<=0.5:
  p=int((sum/n))
else:
  p=int((sum/n))+1
  
answer=0
for i in range(n):
  answer=answer+(x[i]-p)**2

print(answer)

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

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

Solution (Python):
n = int(input())
d = list(map(int,input().split()))
ret = 1145141919
for i in range(101):
  minid = 0
  for x in d: minid += (x-i)**2
  ret = min(ret,minid)
print(ret)

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

min_ans = 1e9
for i in range(100):
    ans = sum([(i + 1 - j) ** 2 for j in x])
    min_ans = min(ans, min_ans)

print(min_ans)

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


main()

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
if sum(X)//N <= sum(X)/N <= sum(X)//N+0.5:
  A = sum(X)//N
else:
  A = sum(X)//N+1
B = []
for i in range(N):
  B.append((X[i]-A)**2)
print(sum(B))

Solution (Python):
import numpy as np
N=int(input())
x=list(map(int,input().split()))
m=int(round(np.mean(x),0))
x_mean=[(y-m)**2 for y in x]
print(sum(x_mean))

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
x = list(map(int, input().split()))

p = Decimal(str(sum(x)/n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

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

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


ave = int(sum(x) / n * 10)
round = ave / 10 - int(ave / 10)
if round - int(round) < 0.5:
    p = int(ave / 10)
else:
    p = int(ave / 10) + 1


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

print(ans)

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 range(n) :
    s += (i-x[j])**2
  ans = min(ans,s)
  
print(ans)

Solution (Python):
n = int(input())
xi = list(map(int, input().split()))
def f(xi, i):
    e = 0
    for x in xi:
        e += abs(x - i) ** 2
    return e
minxi = min(xi)
mine = f(xi, minxi)
for i in range(minxi + 1, max(xi) + 1):
    e = f(xi, i)
    if mine > e : mine = e
    else: break
print(mine)

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

m = int(sum(A)/N+0.5)
cost = sum([(a-m)**2 for a in A])
print(cost)

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
min_num = min(lst)
max_num = max(lst)
cost = float('inf')
for i in range(min_num, max_num + 1):
    tmp = 0
    for x in lst:
        tmp += (i - x) ** 2
    if tmp < cost:
        cost = tmp

print(cost)

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

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

A = []

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

print(min(A))

Solution (Python):
N = int(input())
x = tuple(map(int, input().split()))
mid = (max(x) + min(x)) // 2
curr_sum = 0
dp = [10**9] * 101
for i in range(1, 101):
  dp[i] = 0
  for num in x:
    dp[i] += (num - i) ** 2
print(min(dp))

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

ans = 100*100*100

for P in range(100):
    power = 0
    for i in range(N):
        power += (X[i] - P)**2
    ans = min(ans, power)

print(ans)

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

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

print(min)

Solution (Python):
N = int(input())
li = list(map(int,input().split()))	
Sum = 0
for i in range(len(li)):
    Sum += li[i]
ave = int((Sum / len(li)) + 0.5)

S = 0
for i in range(len(li)):
    S += (li[i] - ave) ** 2
print(S)

Solution (Python):
n = int(input())
*l, = map(int,input().split())
suml = sum(l)
suml2 = sum([i**2 for i in l])
ave1 = suml//n 
ave2 = -(-suml//n)
ans1 = suml2 - 2*suml*ave1 + n*ave1*ave1
ans2 = suml2 - 2*suml*ave2 + n*ave2*ave2
print(min([ans1,ans2]))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
x=[]
maxx=max(X)
sum=0
for p in range(maxx+10):
  for j in X:
    sum+=(j-p)**2
  x.append(sum)
  sum=0
ans=min(x)
print(ans)

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

def resolve():
    n = int(input())
    x = list(map(int, input().split()))
    p1 = int(sum(x)/n)
    p2 = p1 + 1

    ans1 = [(x_-p1)**2 for x_ in x]
    ans2 = [(x_-p2)**2 for x_ in x]

    print(min(sum(ans1), sum(ans2)))
    


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

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

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


if __name__ == "__main__":
    
    resolve()