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):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']
Yn=['Yes','No']

mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase


input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo


show_flg=False
show_flg=True

ans=0

n=I()
x=LI()
s,m=0,0
for i in x:
    s+=i**2
    m+=i


z=int(m/n)
def en(z):
    return s-2*m*z+n*z**2

ans=min(en(z-1),en(z),en(z+1))
print(ans)

Solution (Python):


import sys


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

    p_results = []
    for p in range(0, 100):
        p_sum = 0
        for _, x in enumerate(X):
            p_sum += (x - p) ** 2
        p_results.append(p_sum)
    print(min(p_results))


if __name__ == "__main__":
    main()

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

ave = sum(X)/len(X)
ave_N = sum(X)//len(X)
if( (ave - ave_N) >= (ave_N + 1 - ave)):
  ave = ave_N + 1
else:
  ave = ave_N

total = 0
for i in range(len(X)):
  total += (X[i]-ave)*(X[i]-ave)
print(total)

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

def cost(p):
    res = 0
    for x in xl:
        res += (x-p)**2
    return res

res = 10**9
for p in range(xl[0],xl[-1]+1):
    res = min(res, cost(p))

print(res)

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

Solution (Python):
import sys
stdin = sys.stdin
import numpy as np

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

n = ni()
x = na()
inf = 10**10
cnt = [0] * 100
for xi in x:
    for p in range(1, 101):
        cnt[p-1] = cnt[p-1] + (xi - p)**2

print(min(cnt))

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

for val in X:
  A = A + val
  
a = int(A / N + 0.5)

for val in X:
  sumA = sumA + (a - val) ** 2
  
print(sumA)

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

a = min(l)
b = max(l)
res = 250000

for p in range(a,b+1):
    ires = sum([(x-p)**2 for x in l])
    res = min(ires,res)
    
print(res)

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
INF = pow(10,10)
_min = INF

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):
N = int(input())
X = list(map(int,input().split()))
ans = 10000000000000000000000000000000000000
for i in range (-201,202):
  p = 0
  for j in range (0,N):
    p = p + (X[j] - i - 1) ** 2
  ans = min(ans,p)

print(ans)

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

p = round(sum(X) / N)

print(sum([(X[i] - p) ** 2 for i in range(N)]))

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

Solution (Python):
n=int(input())
x=sorted(list(map(int,input().split())))
mi=int(x[0])
ma=int(x[n-1])
l=[]
a=0
mp=999999
for i in range(mi,ma+1):
    for j in range(n):
        a+=(x[j]-i)**2
    if a<mp:
        mp=a
        a=0
print(mp)

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

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

total=0
p=0
ans=0

for i in range(len(X)):
  total += X[i]

p=round(total/N)

for i in range(len(X)):
  ans += (X[i]-p)*(X[i]-p)


print(ans)

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

x.sort()
m = 1000000
for i in range(1, 101):
    tm = 0
    for xi in x:
        tm += (xi - i) ** 2
    if tm < m:
        m = tm
print(m)

Solution (Python):


from collections import defaultdict

n = int(input())
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(s[0], s[-1] + 1):
    l = sum([pow(x - p, 2) for x in s])

    if l < ans:
        ans = l

print(ans)

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

min_power = 1000001

for p in range(1, 100+1):
    total = 0

    for value in X:
       total += (value - p) ** 2

    if total < min_power:
        min_power = total

print(min_power)

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

ave = math.ceil(sum(a) / len(a))

print(min(sum([(i-ave)**2 for i in a]),sum([(i-(ave-1))**2 for i in a])))

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

Solution (Python):
n=int(input())
x=[int(i) for i in input().split(" ")]
x=sorted(x)
mind=-1
for i in range(x[0],x[len(x)-1]+1):
    sum=0
    for j in x:
        sum+=(j-i)**2
    if mind>sum or mind==-1:
        mind=sum

print(mind)

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

x_max = max(X)
x_min = min(X)
x_mid = (x_max + x_min)//2

def get_dist(X, a):
    ans = 0
    for xi in X:
        ans += (xi - a)**2
    return ans


direction = 1 

x = x_mid
dist1 = get_dist(X, x)
dist2 = get_dist(X, x + 1)

if dist1 > dist2:
    direction = 1
else:
    direction = -1


ans = 0
while True:
    dist2 = get_dist(X, x + direction)

    if dist1 <= dist2:
        ans = dist1
        break

    dist1 = dist2
    x = x + direction
print(ans)

Solution (Python):
def A():
    N, R = map(int, input().split())
    if N >= 10:
        print(R)
    else:
        print(R + 100*(10-N))

def B():
    N, K = map(int, input().split())
    n = N
    ans = 1
    while n >= K:
        q, r = divmod(n, K)
        ans += 1
        n = q
    print(ans)

import math
def C():
    N = int(input())
    X = [int(i) for i in input().split()]
    X.sort()
    l = 1
    r = 100
    ans = float('-inf')
    while l<r:
        
        temp_l = 0
        temp_r = 0
        for i in X:
            temp_l += (i-l)**2
            temp_r += (i-r)**2
        ans = min(temp_l, temp_r)
        if temp_l < temp_r:
            r = int(math.floor((l+r)/2.0))
        else:
            l = int(math.ceil((l+r)/2.0))
    
    print(ans)
C()

Solution (Python):
def main():
    n = int(input())
    x = list(map(int, input().split()))
    result = 0
    for x_i in x:
        result += (x_i - 1) ** 2
    for i in range(2, 100):
        tmp_result = 0
        for x_i in x:
            tmp_result += (x_i - i) ** 2
        result = min(result, tmp_result)
    print(result)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n=int(input())
list = list(map(int,input().split()))
ave=sum(list)/len(list)
k=(Decimal(str(ave)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
sum=0
for i in range(n):
	sum+=(k-list[i])**2
print(sum)

Solution (Python):
import math

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

mean1 = math.floor(sum(x)/n)
mean2 = math.ceil(sum(x)/n)

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

print(min(ans1, ans2))

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

def vital(P,Xi):
    return (Xi -P)**2

l.sort()
a, b = l[0],l[-1]


x = []
y = 0
for i in range(a,b+1):
    for j in range(n):
        y += (l[j] - i)**2
    x.append(y)
    y = 0
print(min(x))

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

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

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

minv = min(a)
maxv = max(a)

val = minv

min_d = 100000000
for i in range(maxv-minv+1):
  d=0
  val = minv + i
  for j in range(len(a)):
    d += (a[j] - val)**2
  if d<min_d:
    mindv = val
    min_d = d

print(min_d)

Solution (Python):
n_regident = int(input())
address = list(map(int, input().split()))

min_total_dis = 100000000
for i in range(min(address), max(address)+1):
    total_dis = sum(map(lambda x:(x-i)**2, address))
    min_total_dis = min(min_total_dis, total_dis)

print(min_total_dis)

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

ans = float("inf")
for pos in range(x[0], x[-1]+1):
    tmp = 0
    for elm in x:
        tmp += (elm - pos) ** 2
    ans = min(ans, tmp)

print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
M = round(sum(X)/N)
answer = 0
for i in X:
    answer += (i-M)**2
print(answer)

Solution (Python):
n=int(input())
L=list(map(int,input().split()))
r=0
for i in range(2*max(L)):
    b=0
    for j in range(n):
        b+=(L[j]-i)**2
    if i==0 or b<r:
        r=b
print(r)

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

y = max(x)
z = min(x)

s = 10**6
for test in range(z,y+1):
  case = list(map(lambda ex: (ex - test) ** 2 , x))
  t = sum(case)
  if t <= s:
    s = t
print(s)

Solution (Python):


from collections import defaultdict

n = int(input())
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(1, 101):
    l = sum([pow(x - p, 2) for x in s])

    if l < ans:
        ans = l

print(ans)

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

ave = sum(X)//N
sum0 = 0
sum1 = 0

for i in range(N):
  sum0 += (X[i]-ave-1)**2
  sum1 += (X[i]-ave)**2
  
print(min(sum0,sum1))

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
m=10**10
ll=list(set(X))
for P in range(min(ll),max(ll)+1):
    ans=[(x-P)**2 for x in X]
    s=sum(ans)
    if m>s:
        m=s
print(m)

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

y=sum(X)/len(X)
y=Decimal(str(y)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
ans=0
for x in X:
    ans+=(x-y)**2
print(ans)

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

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

print(ans)

Solution (Python):
import statistics
n = int(input())
x = [int(i) for i in input().split()]
p = round(statistics.mean(x))
ans = 0
for i in x:
    ans += (i - p)**2
print(ans)

Solution (Python):
import numpy as np
N =int(input())

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

co_min = min(X)
co_max = max(X)

Y =np.ones(co_max-co_min)

for i in range(len(Y)):
    start = co_min + i
    Y[i] = sum((X-start)**2)
if co_min != co_max:    
    ans = int(min(Y))
elif co_min == co_max:
    ans =0
print(ans)

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

point = round(sum(list)/N)

ans_list = []
for item in list:
  ans_list.append((point - item)**2)

print(sum(ans_list))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
cost_b = 1000000
for n in range(1,101):
  cost = 0
  for x in X:
    cost += (x-n)**2
  if cost_b > cost:
    cost_b = cost
print(cost_b)

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

L = min(X)
R = max(X)

ans = 10000000
for P in range(L, R + 1):
    tmp = 0
    for Xi in X:
        tmp += (Xi - P) ** 2
    ans = min(ans, tmp)

print(ans)

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq






def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



n = getInputInt()
data = getInputListInt()

data.sort()
min_num = sys.float_info.max

for i in range(data[0], data[len(data)-1]+1, 1):
    tmp_dis = 0
    for x in data:
        tmp_dis += float(pow(i - x, 2))
    min_num = min(min_num, tmp_dis)

print(int(min_num))

Solution (Python):
n=int(input())
import numpy as np
npi = np.array(list(map(int,input().split())))
if npi.mean()%1>0.5:
  p=npi.mean()//1 +1
else:
  p=npi.mean()//1
print(int(np.sum((npi-p)**2)))

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

ave = round(sum(X)/len(X))
count = 0
for i in range(len(X)):
    count += ((X[i]-ave)**2)
print(count)

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

ave_low = int(sum(x)/len(x))
ave_upp = int(sum(x)/len(x))+1

cout_low = 0
cout_upp = 0

for i in range(len(x)):
    cout_low = cout_low + (ave_low-x[i])*(ave_low-x[i])
    cout_upp = cout_upp + (ave_upp-x[i])*(ave_upp-x[i])

if cout_low <= cout_upp:
    print(cout_low)
else:
    print(cout_upp)

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X.sort()
min_pw = 10**30

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

print(min_pw)

Solution (Python):

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    x = list(map(int, input().split()))
    l = []
    for p in range(1, 101):
        r = 0
        for i in range(n):
            r += (x[i] - p) ** 2
        l.append(r)
    print(min(l))


if __name__ == '__main__':
    main()

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

ans = []

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

Solution (Python):
import math
N = int(input())
X = list(map(int,input().split()))
a = 100
l = []
ans = min([sum([(X[j]-(i+1))**2 for j in range(N)]) for i in range(100)])
print(ans)

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

sumXSq = sum([x*x for x in X])
sumX = sum(X)





P = int(sumX / N)
P2 = P + 1

ans = min(N*P*P - 2*sumX*P + sumXSq, N*P2*P2 - 2*sumX*P2 + sumXSq)

print(ans)

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

s = sum(x)
N = len(x)
mean = s / N
a = math.floor(mean)
b = math.ceil(mean)
ra = 0
rb = 0

for i in range(n):
    ra = ra + (x[i] - a) * (x[i] - a)

for i in range(n):
    rb = rb + (x[i] - b) * (x[i] - b)

if ra < rb:
    print(ra)
else:
    print(rb)

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

nowMinPoint = 9999999999
for chkp in range(1,100):
    tmpP = 0
    for xi in range(1,n+1):
        tmpP += abs(chkp-xList[xi-1])*abs(chkp-xList[xi-1])
    if nowMinPoint > tmpP:
        nowMinPoint = tmpP

print(nowMinPoint)

Solution (Python):

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

s=min(x)
b=max(x)

ans=100100100

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

Solution (Python):

import sys

def solve(N: int, X: "List[int]"):
    p = round(sum(X) / N)
    print(sum([(x-p)**2 for x in X]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int(next(tokens)) for _ in range(N)]  
    solve(N, X)

if __name__ == '__main__':
    main()

Solution (Python):
import math
N = int(input())
l=[int(x) for x in input().rstrip().split()]
su=sum(l)
su=su/N
su = round(su)
ans=0

for i in l:
    ans+=(i-su)*(i-su)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
X = list(map(int,input().split()))
p = round(sum(X)/N)
s = 0
for i in X:
    s += (i - p) ** 2

print (s)

Solution (Python):
import sys

N = int(input())

line = input().split(" ")
X = []

for e in line:
	X.append(int(e))

ans = sys.maxsize
for P in range(101):
	curr = 0

	for x in X:
		curr += (x - P)**2

	ans = min(ans, curr)


print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = 10**9+7
for i in range(100):
  point = 0
  for j in X:
    point += ((j-i)**2)
  if point <= ans:
    ans = point
print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
mid1=sum(X)//N+1
mid2=sum(X)//N


ans=0
ans2=0

for i in range(N):
    ans+=(X[i]-mid1)**2
    
for i in range(N):
    ans2+=(X[i]-mid2)**2
    
print(min(ans,ans2))

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

ans = float("inf")

for x in range(1, 101):
    temp = 0

    for i in range(N):
        temp += (X[i]-x)**2
    
    ans = min(temp, ans)

print(ans)

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

s=sum(L)

s1=s//len(L)
s2=math.ceil(s/len(L))

a=0
b=0
for i in L:
    a+=(s1-i)**2
    b+=(s2-i)**2

print(min(a,b))

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

INF = 10**7

def cost(x,p):
    return (x-p)**2

X.sort()
ans = INF
for p in range(X[0],X[N-1]+1):
    sum = 0
    for i in range(N):
        sum += cost(X[i],p)
    ans = min(ans,sum)

print(ans)

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

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

print(min(ans))

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

lhp = 100000000
for i in range(1, 100+1, 1):
    hp = 0
    for j in range(N):
        hp += (X[j] - i)**2
    if lhp >= hp:
        lhp = hp

print(lhp)

Solution (Python):
import sys








mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    x = list(map(int,input().split()))
    ans = [INF] * 105
    for i in range(105):
        p = 0
        for j in range(n):
            p += (x[j]-(i+1))**2
        ans[i] = min(ans[i],p)
    print(min(ans))
    return

if __name__=='__main__':
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
S = []
for base_point in range(X_min, X_max+1):
    sum_X = 0
    for X_i in X:
        sum_X += (X_i-base_point)**2
    S.append(sum_X)
print(min(S))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
re = float('Inf')
for x in range(min(X),max(X)+1):
    tmp = 0
    for xx in X:
        tmp += (x - xx)**2
    re = min(re,tmp)
print(re)

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

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

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

ave = sum(x) / len(x)
ave_x = round(ave)
count = 0
for i in x:
    count += (i - ave_x) ** 2
print(count)

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

P1 = sum(X) // len(X)
P2 = -(-sum(X) // len(X))
ans1 = 0
ans2 = 0
for i in X:
    ans1 += (i - P1) ** 2
    ans2 += (i - P2) ** 2
print(min(ans1, ans2))

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

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

Solution (Python):


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




Power_list = []
SUM = 0
for i in range(N):
    SUM += X_List[i]

Ave = round(SUM / N)


Consume = 0
for j in range(N):
    diff = (X_List[j] - Ave)
    Consume += diff * diff
    

print(Consume)

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	X = LI()
	X.sort()
	X = np.array(X)
	X2 = X ** 2
	m0 = np.sum(X) // N
	m1 = m0+1
	print(min(np.sum(X2) - 2*m0*np.sum(X) + N*m0**2, np.sum(X2) - 2*m1*np.sum(X) + N*m1**2))

if __name__ == '__main__':
	main()

Solution (Python):
n=int(input())
X=list(map(int,input().split()))
ave=sum(X)/n
a=float('inf')
d=a
for i in range(1,101):
    if abs(ave-i)<=d:
        a=i
        d=abs(ave-i)
ans=0
for x in X:
    ans+=(x-a)**2
print(ans)

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

min_d=100*10000
for P in range(1,101):
    sum_d=0
    for i in range(N):
        sum_d+=(X[i]-P)**2
    min_d=min(min_d,sum_d)

print(min_d)

Solution (Python):

import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")

INF  = float("inf") 

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

ans=INF

for b in range(102):
	a=0
	for x in X:
		a+=(x-b)**2
		
		
		
	ans=min(ans,a)
	

print(ans)

Solution (Python):
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
ans = np.sum(X**2)
for i in range(0,int(np.max(X))+1):
  l = X - i
  a = np.sum(l**2)
  if a < ans:
    L = l
    ans = a
print(ans)

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

Solution (Python):




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



avg1 = sum(X) // N
avg2 = avg1 + 1
print(min(
    sum([(x - avg1) * (x - avg1) for x in X]),
    sum([(x - avg2) * (x - avg2) for x in X])
))

Solution (Python):

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

for i in range(1, 101):
    p = i
    power = 0
    for j in range(n):
        power += (x[j] - p)*(x[j] - p)
    if power < ans:
        ans = power

print(ans)

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_max = max(X)
ans = float('inf')
for i in range(X_max + 1):
    tmp_ans = 0
    for x in X:
        tmp_ans += (x - i) ** 2
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

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

cost = []

def mt(p):
    c = 0
    for i in range(len(X)):
        c += (X[i]-p)**2
    return c

for j in range(100):
    cost.append(mt(j))

print(min(cost))

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

Solution (Python):
import sys
N = int(sys.stdin.readline()) 
L = [int(s) for s in sys.stdin.read().split()] 
S = sum(L)
x = S // N
A_1 = sum([(s-x)**2 for s in L])
A_2 = sum([(s-x-1)**2 for s in L])
print(min(A_1,A_2))

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

ave1 = sum(x) // n
ave2 = (sum(x) + n - 1) // n
print(min(sum((i - ave1)**2 for i in x), sum((i - ave2)**2 for i in x)))

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

results = []
for i in range(1, 101):
    sum = 0
    for person in x:
        sum += (person-i)**2
    results.append(sum)

print(min(results))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
a=0
b=0
for i in x:
    a=a+i
a=a/n
if a%1 < 0.5:
    a=a//1
else:
    a=(a//1)+1
for i in x:
    b=b+(i-a)*(i-a)
b=int(b//1)
print(b)

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

center = round((sum(X) / N), 0)

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

print(ans)

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

min_goukei = 2500 * 100

for i in range(100):
    goukei = 0
    for j in range(n):
        goukei += (x_list[j] - i)**2
    if goukei < min_goukei:
        min_goukei = goukei

print(min_goukei)

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

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

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

min_zyusho = min(zyusyo)
max_zyusyo = max(zyusyo)

ans = 10**9
for p in range(min_zyusho, max_zyusyo+1):
    sum = 0
    for z in zyusyo:
        sum += (z-p)**2
    if sum < ans:
        ans = sum

print(ans)

Solution (Python):
N = int(input())
X = input().split()
X = [int(s) for s in X]
if N == 1 or len(list(set(X)))==1:
    print(0)
else:
    X = sorted(X)
    range_X = X[-1] - X [0]

    E_min = 10000000000000000000000
    for p in range(range_X):
        E = 0
        for x in X:
            E += (x-p)**2
        if E < E_min:
            E_min = E
    print(E_min)

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

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

mi = min(xi)
ma = max(xi)
ans = 1000000

for i in range(mi, ma+1):
    num = 0
    for j in range(n):
        num += (xi[j]-i)**2
    ans = min(ans, num)

print(ans)

Solution (Python):
N= int(input())
X = list(map(int, input().split()))
xlim = sum(X) // N
x1 = 0
x2 = 0
for i in range(len(X)):
  x1 += (X[i]-xlim)**2
  x2 += (X[i]- xlim - 1)** 2
print(min(x1,x2))

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

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

avg = round(sum(X) / N)

ans = 0

for i in X:
    a = (i - avg)**2
    ans += a
    
print(ans)

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x.sort()
res=100000000
for i in range(x[0],x[-1]+1):
    f=0
    for j in x:
        f+=(j-i)**2
    if res>f:
        ind=i
        res=f
print(res)

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

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



minv = float('inf')
for p in range(0, 101):
  minv = min(minv, sum([
    (p - x) ** 2
  	for x in xi
  ]))
print(minv)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
import numpy as np

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

    minpower = np.inf
    for P in range(1, max(X)+1):
        minpower = min(sum([(x-P)**2 for x in X]), minpower)

    print(minpower)

if __name__ == '__main__':
    resolve()