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):

import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)


import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)

def main():
    n=int(input())
    X=list(map(int,input().split()))
    ans=inf
    for p in range(min(X),max(X)+1):
        ans=min(ans,sum(list(map(lambda x:(x-p)**2,X))))
    print(ans)




main()

Solution (Python):
from statistics import mean
N = int(input())
X = [int(x) for x in input().split()]
sum = 0
goal = round(mean(X))
for i in range(len(X)):
    sum += (X[i] - goal) ** 2
print(sum)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


def main():
	N = int(input())
	X = getlist()
	ans = 10000000000
	for i in range(1, 101):
		var = 0
		for j in range(N):
			var += (X[j] - i) ** 2

		ans = min(ans, var)

	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
INT_MAX=10**18+7
x=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
GETA=123

import math as M
n=int(input())
A=INPUT()
sum=0
for ele in A:
    sum+=ele
ans=sum/n

ans1=int(ans)+1
sum1=0
sum2=0
ans2=int(ans)
for ele in A:
    sum1+=(ele-ans1)**2
for ele in A:
    sum2+=(ele-ans2)**2
print(min(sum1,sum2))

Solution (Python):



import sys
input = sys.stdin.readline

def main():
    N = int(input())
    X = list(map(int, input().split()))
    x2 = sum([i*i for i in X])
    x = sum(X)
    ret = 100100100
    for p in range(min(X), max(X)+1):
        ret = min(ret, x2 - 2*x*p + N*p*p)
    print(ret)

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
ans = 0

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

P = int(round(np.average(X)))

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

print(ans)

Solution (Python):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
import math
N = int(input())
arr = list(map(int,input().split()))
add = sum(arr)
avg = int(round(add/N)) 
ans = 0
for i in range(N):
	ans += (avg-arr[i])*(avg-arr[i])
print(int(ans))

Solution (Python):
n=int(input())
x=sorted(list(map(int, input().split())))
ans=10**7
for i in range(x[0],x[n-1]+1):
    hp=0
    for j in range(n):
        hp+=(x[j]-i)**2
    if hp<ans:
        ans=hp
print(ans)

Solution (Python):
import math
N = int(input())
X = list(map(int, input().split()))
P1, P2 = math.ceil(sum(X) / N), int(sum(X) / N)
work1, work2 = 0, 0
for x in X:
    work1 += (x - P1)**2
    work2 += (x - P2)**2
print(min(work1, work2))

Solution (Python):


n=int(input())
nums=list(map(int, input().split()))
ave=round(sum(nums)/n)

ans=0
for i in nums:
    ans+=(i-ave)**2

print(ans)

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


hp_old = 10**6


for p in range(1, 101, 1):
    hp_new = 0
    for xi in x:
        
        hp_new += (xi - p) ** 2
    
    hp = min(hp_new, hp_old)
    
    hp_old = hp

print(hp)

Solution (Python):
def custom_round(number, ndigits=0):
    if type(number) == int:
        return number
    d_point = len(str(number).split('.')[1])
    if ndigits >= d_point:
        return number
    c = (10 ** d_point) * 2
    return round((number * c + 1) / c, ndigits)

N=int(input())
A=list(map(int,input().split()))
ave=custom_round(sum(A)/N,0)
total=0
for i in range(N):
    total+=(A[i]-ave)**2
print(int(total))

Solution (Python):
import numpy as np

def solve():
    opt = np.round(np.sum(x)/len(x))
    ans = int(np.sum((x-opt)**2))
    return ans


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

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

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

ave_down = sum(x) // n 
ave_up = -(-sum(x) // n) 

distance1 = []
distance2 = []

for i in range(n):
  distance1.append(( ave_down - x[i] ) ** 2)

for i in range(n):
  distance2.append(( ave_up - x[i] ) ** 2)

if sum(distance1) <= sum(distance2):
  print(sum(distance1))
else:
  print(sum(distance2))

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

dis2 = [0]*100
for p in range(100):
    dis = 0
    for i in range(a):
        dis += (li[i]-(p+1))**2
    dis2[p] = dis
print(min(dis2))

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

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

p = sum(X) / N

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

s = min(f(math.floor(p)), f(math.ceil(p)))
print(s)

Solution (Python):
import math
import statistics

n = int(input())

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

my_mean = sum(li) / len(li)
ll = math.floor(my_mean)
lll = math.ceil(my_mean)

c = 0
for i in range(len(li)):
  c += (li[i] - ll)**2
  
cc = 0
for i in range(len(li)):
  cc += (li[i] - lll)**2
  
  
if c < cc:
  print(c)
else:
  print(cc)

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x=sorted(x)
ans=10**8
count=0
for i in range(x[0],x[-1]+1):
  count=0
  for j in range(n):
    count+=(x[j]-i)**2
  if ans>count:
    ans=count
    
print(ans)

Solution (Python):
N = int(input())
X_list = list(map(int, input().split()))
min_strength = sum(list(map(lambda x: (x - max(X_list)) ** 2, X_list)))
for i in range(min(X_list), max(X_list)):
    strength = sum(list(map(lambda x: (x - i) ** 2, X_list)))
    if min_strength > strength:
        min_strength = strength
print(min_strength)

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

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

Solution (Python):
n=int(int(input()))
c=list(map(int,input().split()))
mi=10**20
x=0
for i in range(100):
 for j in range(n):
  x+=(c[j]-(i+1))**2
 if mi>x:
  mi=x
 x=0 
print(mi)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
def D(x,a):
	ans=0
	for i in range(len(a)):
		ans+=(x-a[i])**2
	return ans
for i in range(0,101):
	if D(i,X)<D(i+1,X):
		print(D(i,X))
		break

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

mi = min(xi)
ma = max(xi)
ans = 10**18
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())
a=list(map(int,input().split()))

average = round(sum(a)/n)

ans=0

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

Solution (Python):
import numpy as np
def f(n, x):
    mean =  np.mean(x)
    s1 = sum((x-np.floor(mean))**2)
    s2 = sum((x-np.ceil(mean))**2)
    print(int(min(s1, s2)))

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

Solution (Python):
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
ans = 10000000
for p in range(min(X), max(X) + 1):
    Y = np.sum((X - p)**2)
    ans = min(ans, Y)

print(ans)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
def D(x,a):
	ans=0
	for i in range(len(a)):
		ans+=(x-a[i])**2
	return ans
for i in range(0,101):
	if D(i,X)<D(i+1,X):
		print(D(i,X))
		break

Solution (Python):
n = int(input())
x = [int(x) for x in input().split()]
center = sum(x)//len(x)
center2 = center+1
ans, ans2 =0, 0
for i in x:
    ans += (i-center)**2
    ans2 += (i-center2)**2

print(ans) if ans<ans2 else print(ans2)

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

ex = sum(xn)/len(xn)
if ex-round(ex) < ex-round(ex)+1:
  ex = round(ex)
else:
  ex = round(ex)+1
varx = [(i-ex)**2 for i in xn]

print(int(sum(varx)))

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

average = round(sum(X) / N)

ans = 0

for i in X:
    ans += (i-average)**2

print(ans)

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

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

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

l = min(x)
r = max(x)

ans = 10000000000

for i in range(l, r+1):
    ansi = 0
    for a in x:
        ansi += abs(a - i) ** 2
    ans = min(ans, ansi)

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
x = list(map(int, readline().split()))
v = [0] * 100
cnt = 0
for i in range(100):
    for xx in x:
        cnt += (xx - i) ** 2
    v[i] = cnt
    cnt = 0
print(min(v))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
ans1, ans2 = 0, 0
p1 = -(-sum(X)//N)
p2 = sum(X)//N

for i in range(N):
    ans1 += abs((X[i]-p1)**2)
    ans2 += abs((X[i]-p2)**2)
print(min(ans1, ans2))

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

res = float('inf')

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

    res = min(tmp, res)

print(res)

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

res = float('inf')

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

    res = min(tmp, res)

print(res)

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

ans=1000000000
for p in range(1,101):
    temp=0
    for i in range(N):
        temp+=(X[i]-p)**2
    if ans>temp:
        ans=temp

print(ans)

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

P=sum(X)/N
if P%1 < 0.5:
    P=P//1
else:
    P=P//1+1
L=0
for i in range(N):
    L += X[i]**2
print(int(L-2*P*sum(X)+N*P**2))

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

    ans = 10 ** 8
    x_min = min(x)
    x_max = max(x)
    for i in range(x_min, x_max+1):
        tmp = 0
        for j in range(n):
            tmp += (x[j] - i) ** 2
        if tmp < ans:
            ans = tmp

    print(ans)

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

total = []
for i in range(1,100+1):
  cost = 0
  for j in x:
    cost += (i-j)**2

  total.append(cost)
print(min(total))

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

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

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

Solution (Python):
n = int(input())
xn = list(map(int, input().split()))
xn = sorted(xn)
min_x = xn[0]
max_x = xn[-1]
min_total = float('inf')
for i in range(min_x, max_x+1):
    total = 0
    for x in xn:
        total += abs(x-i)**2
    min_total = min(min_total, total)

print(min_total)

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

print(min(cand))

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

MaxX = max(X)
MinX = min(X)

ListP = []

for i in range(MinX, MaxX+1):
    P = 0
    for j in range(N):
        P += (X[j]-i)**2
    
    ListP.append(P)

print(min(ListP))

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

distance = lambda Xi, P: (Xi - P) ** 2
all_distance = lambda X, P: sum([distance(Xi, P) for Xi in X])

X_min = min(X)
X_max = max(X)

answer = min([all_distance(X, P) for P in range(X_min, X_max + 1)])

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2
all_distance = lambda X, P: sum([distance(Xi, P) for Xi in X])

X_min = min(X)
X_max = max(X)

answer = None
for P in range(X_min, X_max + 1):
    total = all_distance(X, P)
    answer = min(total, answer) if answer is not None else total

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2

X_min = min(X)
X_max = max(X)

answer = None
for P in range(X_min, X_max + 1):
    total = sum([distance(Xi, P) for Xi in X])
    answer = min(total, answer) if answer is not None else total

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2

X_min = min(X)
X_max = max(X)

answer = None
for P in range(X_min, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer) if answer is not None else total

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2

X_min = min(X)
X_max = max(X)

answer = None
for P in range(X_min, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer) if answer is not None else total

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2

X_max = max(X)

answer = None
for P in range(1, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer) if answer is not None else total

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2

X_max = max(X)

answer = None
for P in range(1, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer) if answer is not None else total

print(answer)

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

distance = lambda Xi, P: (Xi - P) ** 2

X_max = max(X)

answer = 99999999999
for P in range(1, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer)

print(answer)

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

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

min_ans = 100000000

for p in range(101):
    ans_cand = 0
    for i in range(N):
        ans_cand += (p-X_l[i])**2
    if ans_cand < min_ans:
        min_ans = ans_cand

print(min_ans)

Solution (Python):

def test_coordinates(arr, coord):
    return sum([(x - coord) * (x - coord) for x in arr])


N = int(input())

coordinates = input().strip().split()
coordinates = [int(x) for x in coordinates]
costs = []

for i in range(1, max(coordinates)+1):
    costs.append(test_coordinates(coordinates, i))
print(min(costs))

Solution (Python):


N = int(input())


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


final_ans = 100000000000000000000
for p in range(1,101):
    ans = 0
    for x in X:
        ans += (x-p)**2
    if final_ans > ans:
        final_ans = ans
print(final_ans)

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

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

  
  A.append(ans)
  ans = 0
  
print(min(A))

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

sum = 0
ans = 0

round=lambda x:(x*2+1)//2

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

avg = round(sum/n)

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

print(int(ans))

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = 1000000
for p in range(x[0], x[-1]+1):
    tmp = 0
    for i in x:
        tmp += (i-p) ** 2
    if tmp < ans:
        ans = tmp
print(ans)

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

Solution (Python):
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    if max(spot)==min(spot):
        ans.append(0)
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    ans.sort(reverse=False)
    print(ans[0])

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    X=[int(_) for _ in input().split()]
    sum_x=sum(X)
    ans=0
    if sum_x/n-sum_x//n<0.5:p=sum_x//n
    else:p=sum_x//n+1
    for i in range(n):
        ans+=(X[i]-p)**2
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    X=[int(_) for _ in input().split()]
    sum_x=sum(X)
    ans=0
    if sum_x/n-sum_x//n<0.5:p=sum_x//n
    else:p=sum_x//n+1
    for i in range(n):
        ans+=(X[i]-p)**2
    print(ans)

if __name__=='__main__':
    main()

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

Solution (Python):
a=int(input())
b=list(map(int,input().split()))
min,max=1000000,0
for i in range(101):
  for ii in range(a):
    max+=(b[ii]-i)*(b[ii]-i)
  if(max<min):
    min=max
    max=0
print(min)

Solution (Python):
a=int(input())
b=list(map(int,input().split()))
min,max=1000000,0
for i in range(101):
  for ii in range(a):
    max+=(b[ii]-i)*(b[ii]-i)
  if(max<min):
    min=max
    max=0
print(min)

Solution (Python):
import numpy as np
n=int(input())
x=list(map(int, input().split()))
x=np.array(x)
fatigue=[]
for i in range(1,max(x)+1):
    y=(x-i)**2
    fatigue.append(sum(y))

print(min(fatigue))

Solution (Python):


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

import numpy as np

X = np.array(list(X))

min_cost = np.inf
for n in range(1, 101):
  cost = np.sum(np.square(X-n))
  if cost < min_cost:
    min_cost = cost
print(min_cost)

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

Solution (Python):
N = int(input())
l = list(map(int, input().split()))
ans = 0
ave = round(sum(l)/N)

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

print(ans)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N = int(readline().rstrip())
X = list(map(int, readline().split()))

lower = min(X)
upper = max(X)

ans = float("inf")
for P in range(lower, upper+1):
    dis = 0
    for x in X:
        dis += abs(P - x) ** 2
    ans = min(ans, dis)
print(ans)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
X = LIST()
SUM = np.zeros(max(X)-min(X)+1)
SUM = list(SUM)

for i in range(N):
  for j in range(min(X), max(X)+1):
    SUM[j-min(X)] += (j-X[i])**2
    
print(int(min(SUM)))

Solution (Python):
n=int(input())
a=input().split(" ")
num=[]
sum_list=[]
for i in range(n):
    num.append(int(a[i]))

num=sorted(num)

for i in range(num[0],num[n-1]+1):
    sum=0
    for j in range(n):
        dis=(num[j]-i)**2
        sum+=dis
    sum_list.append(sum)
sum_list=sorted(sum_list)
print(sum_list[0])

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
x = LIST()
ans = inf
for p in range(1, 101):
    tmp2 = 0
    for xx in x:
        tmp2 += (xx - p) ** 2
    if ans > tmp2:
        ans = tmp2
print(ans)

Solution (Python):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
X = LI()

ma = max(X)
mi = min(X)

ans = 10000000000
for i in range(mi, ma+1):
    p = i

    sum = 0
    for x in X:
        sum += pow(x-p, 2)

    if ans > sum:
        ans = sum

print(ans)

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

print(min(p))

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

from statistics import mean
M = round(mean(X))

ans = 0
for i in range(len(X)):
    ans += (X[i]-M)**2
    
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = 1000000
for p in range(x[0], x[-1]+1):
    tmp = 0
    for i in x:
        tmp += (i-p) ** 2
    if tmp < ans:
        ans = tmp
print(ans)

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

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

ans = 10 ** 19
for i in range(1, 101):
  ans = min(ans, sum((x - i) ** 2 for x in X))

print(ans)

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


for i in range(101):
  sumX = 0
  for x in XList:
    sumX = sumX + (x - i)**2
 
  sumList.append(sumX)

print(min(sumList))

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

z=[]
for i in range(10**6):
    y=0
    for j in range(n):
        y+=abs(x[j]-i)**2
    z.append(y)

z=sorted(z)
print(z[0])

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