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):
a=input()
b=input().split()
c=[int(n) for n in b]
d=sum(c)
e=round(d/int(a))

f=[(f-e)*(f-e) for f in c]
g=sum(f)
print(g)

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

lis_X_sorted = sorted(lis_X)

def calc_dif_sq(a,b):
    return (a-b)**2

if N == 1:
    ans = 0
elif min(lis_X_sorted)==max(lis_X_sorted):
    ans = 0
else :
    res = []
    for p in range(lis_X_sorted[0],lis_X_sorted[-1]):
        tmp = sum(list(map(lambda x:calc_dif_sq(x, p), lis_X_sorted)))
        res.append(tmp)
    ans = min(res)
print(ans)

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

def damage_all(X,P):
  damage = 0
  for i in X:
    damage += (i - P)**2
  return damage

P = round(sum(X) / len(X))
distance = damage_all(X,P)

print(distance)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    s=s+a[i]
m=s/n
mi=round(m)
s=0
for i in range(n):
    s=s+int(pow(a[i]-mi,2))
print(s)

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

def hitpoint(n, xs):
    acc = 0
    for x in xs:
        r = (x - n) ** 2
        acc += r
    return acc

ans = hitpoint(1, XS)
tmp = ans
for i in range(2, 100):
    ans = hitpoint(i, XS)
    if ans >= tmp:
        break
    tmp = ans

print(tmp)

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

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

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

def mainB():
	N,K=map(int,input().split())
	
	
	
	
	res = 0
	while N:
		N //= K
		res += 1
	
	print(res)

def mainC():
	
	N=input().rstrip()
	
	vA=list(map(int,input().split()))
	
	res = float("inf")
	for i in range(1, 101):
		t = sum((x-i)**2 for x in vA)
		res = min(res, t)
	
	print(res)




mainC()

Solution (Python):
p_num = input()
p_loc = input()
num = int(p_num)
loc_list = [int(i) for i in p_loc.split()]
value_list = []
for i in range(min(loc_list), max(loc_list)+1):
  value = 0
  for loc in loc_list:
    value += (loc-i)**2
  value_list.append(value)
    
print(min(value_list))

Solution (Python):
n = int(input())
xList = list(map(int, input().split()))
ans = 1000000
for i in range(1, 100):
    sums = 0
    for j in xList:
        sums += (j - i) ** 2
    if sums < ans:
        ans = sums
print(ans)

Solution (Python):


n = int(input())
xlist = list(map(int,input().split()))
xlist.sort()
ans = 10**9+7
st = xlist[0]
ed = xlist[-1]
for p in range(st, ed + 1):
  pp = 0
  for i in range(n):
    pp += (xlist[i] - p) ** 2
  ans = min(ans, pp)
print(ans)

Solution (Python):

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

y = len(x)
mini = min(x)
maxi = max(x)
x.sort()

ans = 0
p = 0
for valuse in range(mini,maxi):
  p=0
  for j in range(n):
    p += (x[j] -valuse) **2
  if p < ans or ans == 0 :
    ans = p

    ans1 = valuse
  else:
    break

print(ans)

Solution (Python):


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

    mu = round((sum(x)/len(x)))
    res = 0
    for i in x:
        res += (i - mu)**2

    print(int(res))

if __name__ == "__main__":
    main()

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

ans = 1e100
for p in range(101):
  cnt = 0
  for i in x:
    cnt += (p - i) ** 2
  if ans > cnt:
    ans = cnt
print(ans)

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

center = sum(lists)/n
i_part = sum(lists)//n
f_part = center - i_part

if f_part >= 0.5:
    central_int = i_part + 1
else:
    central_int = i_part

stamina = 0
for x in lists:
    stamina += (x-central_int)**2
print(stamina)

Solution (Python):


from sys import stdin

n = int(input())
x_list_str = stdin.readline().rstrip().split()
x_list = [int(i) for i in x_list_str]


sum_hp_list = []

min_x = min(x_list)
max_x = max(x_list)

if min_x == max_x:
    print(0)
    exit()

for i in range(min_x, max_x):
    sum_hp = 0
    for x in x_list:
        sum_hp += (x-i)**2
    sum_hp_list.append(sum_hp)

print(min(sum_hp_list))

Solution (Python):
import numpy as np

N = int(input())
X_list = list(map(int,input().split()))
X_array = np.array(X_list)

P = int(np.round(np.mean(X_array)))

ans = np.sum((X_array - P)**2)

print(ans)

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

A_list_str = input()
A_list_strs = A_list_str.split()
X = [int(x) for x in A_list_strs]
HP = 0
HP_b = 0

center = sum(X)//N
center_b = center + 1

for x in X:
    tmp = (x - center) ** 2
    HP = HP + tmp
    tmp1 = (x- center_b) ** 2
    HP_b = HP_b + tmp1

if HP_b < HP:
    print (HP_b)
else:
    print(HP)

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

for P in range(1,101):
 

    sum = 0
    for L in List:
        sum += pow((P - L), 2)
    if min >= sum:
        min = sum

print(min)

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

A = []
for P in range(1,101):
    for i in range(N):
        A.append((X[i]-P)**2)
    if sum(A[0:N]) <= sum(A[N:2*N]) or len(A) == N:
        A = A[0:N]
    else:
        A = A[N:2*N]
print(sum(A))

Solution (Python):
N=int(input())
list = list(map(int, input().split()))
c=100
l=len(list)
m=0
k=0
i=0
while(k<l):
  m+=(list[k]-1)**2
  k+=1
j=1
while(j<c):
  r=0
  i=0
  while(i<l):
    r+=(list[i]-j) ** 2
    i+=1
  if(r<m):
    m=r
  j+=1
print(m)

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

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

tmpans = 0
ans = float('inf')

for P in range(min(X), max(X) + 1):
    for x in X:
        tmpans += (x-P)**2

    if tmpans < ans:
        ans = tmpans
    tmpans = 0
print(ans)

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

for i in range(x[0], x[-1]+1):
    t = 0
    for q in range(n):
        t += (i - x[q]) ** 2
    else:
        if ans > t:
            ans = t

print(ans)

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

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

E = [0 for i in range(100)]

for i in range(100):
    E[i] = 0
    for x in K:
        E[i] += (x-i)**2

print(min(E))

Solution (Python):



def main():
    n = int(input())
    number_ = list(map(int, input().split(' ')))    

    max_number = max(number_)
    min_number = min(number_)
    min_sums = []
    for p in range(min_number, max_number + 1):
        sum_ = 0
        for x in number_:
            sum_ += (x - p) ** 2
        min_sums.append(sum_)

    print(min(min_sums))

    return 0


if __name__ == '__main__':
    main()

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

def num(P, X):
    number = 0
    for x in X:
        num = x-P
        
        num2 = num**2
        number += num2
    return number

nList = []
for p in range(min(X), max(X) + 1):
    nList.append(num(p, X))

n = str(min(nList))
print(n)

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

result=[]
sum=0
for i in range(min(a),max(a)+1):
    sum=0
    for j in range(len(a)):
        sum += int((a[j]-i)**2)
    result.append(sum)

print(min(result))

Solution (Python):
import sys
N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
if N == 1:
    print('0')
    sys.exit()
for i in range(min(X), max(X) + 1):
    ans = 0
    for j in X:
        ans += (j - i) ** 2
    ans_list.append(ans)

print(min(ans_list))

Solution (Python):
import numpy as np

n = int(input())
x = list(map(int,input().split()))
x2 = np.power(x,2)

p1 = sum(x)//n
p2 = -(-sum(x)//n)

w1 = n*(p1**2) -2*sum(x)*p1 +sum(x2)
w2 = n*(p2**2) -2*sum(x)*p2 +sum(x2)

print(min(w1,w2))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=int(1000000000)
for i in range(1,1000):
    now=int(0)
    for j in range(n):
        now+=(i-A[j])*(i-A[j])
    if now<ans:
        ans=now
        
print(ans)

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


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



cal = [0]*N
r = min(X)
l = max(X)
mid = (l - r) // 2
out = []

for j in range(X[0], X[-1]+1):
    for i in range(N):
        cal[i] = (X[i] - j) ** 2
    out.append(sum(cal))

out.sort()
print(out[0])

Solution (Python):
n = input()
l = input().split()
data = []
for i in range(int(min(l)), int(max(l))+1):
    sum_l = 0
    for j in range(len(l)):
        sum_l = sum_l + (int(l[j])-i)**2
    data.append(sum_l)

print(min(data))

Solution (Python):
import sys

f = sys.stdin
N = int(f.readline()[:-1])
X = list(map(int, f.readline().split(' ')))


def cost(p):
    return sum((x - p)**2 for x in X)


P1 = sum(X) // N
P2 = P1 + 1
result1 = cost(P1)
result2 = cost(P2)
if result1 >= result2:
    print(result2)
else:
    print(result1)

Solution (Python):

people = int(input())
coordinates = list(map(int, input().split()))
max_ = max(coordinates)
min_ = min(coordinates)
ans = 0


for i in range(min_, max_ + 1):
    currentMin = 0
    for j in range(people):
        currentMin += (coordinates[j] - i) ** 2
    if i == min_:
        ans = currentMin
    elif currentMin < ans:
        ans = currentMin
        
print(ans)

Solution (Python):
a=int,input()
b=list(map(int,input().split()))
c_1=sum(b)//len(b)
c_2=c_1+1
j_1=0
j_2=0
for k in b:
  j_1+=(c_1-k)**2
for k in b:
  j_2+=(c_2-k)**2
if j_1>=j_2:
  print(j_2)
else:
  print(j_1)

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

l=[]

i=1
for j in range(100):
    B=[n-i for n in A]
    C=(np.array(B))**2
    D=np.sum(C)
    l.append(D)
    i=i+1

print(min(l))

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

Solution (Python):
line1 = input('')
line2 = input('')
n = int(line1)
lst = []
max_idx = 0
min_idx = 0
for x in line2.split(' '):
  lst.append(int(x))
  if max_idx == 0:
    max_idx = int(x)
  if min_idx == 0:
    min_idx = int(x)
  if max_idx < int(x):
    max_idx = int(x)
  elif min_idx > int(x):
    min_idx = int(x)

min_sum = 0
for p in range(min_idx,max_idx):
  sum = 0
  for x in lst:
    d = (x - p)*(x - p)
    sum += d
  if min_sum == 0:
    min_sum = sum
  elif sum < min_sum:
    min_sum = sum

print(min_sum)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
s = sum(x)
xx = 0
for i in x:
    xx += i**2
def f(p):
    return n * p**2 - 2 * p * s + xx
ans = f(1)
for i in range(2, 101):
    ans = min(ans, f(i))
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
max = max(x)
min = min(x)
ans = 1000001
for i in range(min, max + 1):
    score = 0
    
    for item in x:
        score = score + ((item - i) ** 2)
    
    if score <= ans:
        ans = score

print(ans)

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

ans = []
m = max(list_score)

for i in range(1, m+1):
    c = []
    
    for j in range(n):
        a = list_score[j] - i
        b = a**2
        c.append(b)
    
    
    ans.append(sum(c))


ans.sort()

print(ans[0])

Solution (Python):
import numpy as np
n = input()
x = input().split()
n = int(n)
x = list(map(int,x))
x = np.array(x)
maxed = np.max(x)
cand = []

for p in range(1,maxed+1):
    xp = (x - p) ** 2
    cand.append(np.sum(xp))
y = np.min(cand)
print(y)

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

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

sum = []
i_sum = 0


for i in range(100):
    
    for j in range(n):
        i_sum += ((address[j] - (i + 1)) ** 2)

    sum.append(i_sum)
    i_sum = 0

print(min(sum))

Solution (Python):
def main():
    N = int(input())
    B = list(map(int, input().split()))
    
    
    l = []

    for P in range(1, 100):
        l2 = []
        for t in B:
            x = (t - P) ** 2
            l2.append(x)

        l.append(sum(l2))
    print(min(l))


main()

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

ans1 = 0
ans2 = 0
S = sum(X)//N

for x in X:
    ans1 += (x - S) ** 2
    ans2 += (x - (S + 1)) ** 2

print(min(ans1, ans2))

Solution (Python):
b=input()
b=int(b)
a = input().split()
a=[int(i) for i in a]
a.sort()
c=0
d=99999999999999999
e=a[0]
f=a[b-1]
if e==f:
    d=0

else:
    for p in range (e,f):
        for x in range (0,b):
            c = c+(a[x]-p)**2
        if d>=c:
            d=c
            c=0

print(d)

Solution (Python):
import math

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

min = 0
avg = round(sum(X) / len(X))

for x in X:
    min += (x - avg)**2

print(min)

Solution (Python):
def main():
    n = input()
    array = list(map(int, input().split(" ")))
    minX = min(array)
    maxX = max(array)
    p_sum = 0
    power_list = []
    for p in range(minX, maxX + 1):
        for x in array:
            p_sum += power(x, p)
        power_list.append(p_sum)
        p_sum = 0        
    print(min(power_list))

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

if __name__ == "__main__":
    main()

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


x_sum = sum(x)

center = round(x_sum /n)
result = 0
for x_i in x:
    result += (x_i - center)*(x_i - center)

print(result)

Solution (Python):
import statistics
n=int(input())
x=[int(_) for _ in input().split()]
mid=int(statistics.mean(x))
mmid=mid-1
pmid=mid+1
cnt=0
cntm=0
cntp=0
for i in range(len(x)):
  cnt+= (x[i]-mid)**2
  cntm+=(x[i]-mmid)**2
  cntp+=(x[i]-pmid)**2
print(min(cnt,cntm,cntp))

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

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

temp_sum = 0
ans = 10 ** 9

for p in range(100):
    for x in x_list:
        temp_sum += (x - p) ** 2
    if temp_sum < ans:
        ans = temp_sum
    temp_sum = 0

print(ans)

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

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

all_sum = []
for i in xp:
 all_sum.append(sum(i))

print(int(min(all_sum)))

Solution (Python):
import math

if __name__=="__main__":
    n = int(input())
    X = [int(a) for a in input().split()]

    sum_x = sum(X)

    sum_x2 = 0
    for x in X:
        sum_x2 += x**2
    
    z = math.floor(sum_x/n)
    r = sum_x/n - z

    if r <= 0.5:
        ans = sum_x2 + n*z**2 - 2*z*sum_x
    else:
        ans = n - 2*(1+z)*sum_x + 2*z*n + z**2*n + sum_x2

    print(ans)

Solution (Python):
N = int(input().rstrip())
Xs = [int(x) for x in map(int, input().rstrip().split())]
import sys
sum_val = sys.maxsize
for i in range(min(Xs), max(Xs)+1):
    tmp_sum_val = 0
    for j in Xs:
        tmp_sum_val += (j - i)**2
    if sum_val > tmp_sum_val:
        sum_val = tmp_sum_val
print(sum_val)

Solution (Python):
from sys import stdin
 
n = int(input())
k = [int(x) for x in stdin.readline().rstrip().split()]

k.sort()

ave = round(sum(k) / len(k) )



def calc_pow(n):
    i = pow(n - ave, 2) 
    return i
  
j = map(calc_pow, k)

print(sum(j))

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

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

print(min)

Solution (Python):
import numpy as np
 
def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    mean = int(round(np.mean(A)))
    x = np.array(A) - mean
    print(np.dot(x, x))
 
main()

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

print(min(T))

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
max_num = float('inf')
li.sort()
for i in range(1, 101):
    temp_sum = 0
    for j in li:
        temp_sum = temp_sum + ((j - i) ** 2)

    if temp_sum < max_num:
        max_num = temp_sum

print(max_num)

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

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

MX = max(X)

TP = []

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

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

b = max(K)
s = min(K)
INF = 10**18
t = [INF]*(b+1)
for i in range(s,b+1):
  a = 0
  for j in range(len(K)):
	  a += (K[j] - i)**2
  t[i] = a
print(min(t))

Solution (Python):
from statistics import mean
n = int(input())
a = list(map(int, input().strip().split()))

m = round(mean(a))


data = list(map(lambda x: (x-m)**2, a))

print(sum(data))

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

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

ans = 1 << 60
for i in range(0,101):
    ans = min(ans, cost(i))

print(ans)

Solution (Python):

INF = int(1e9) 
def main():
    n = int(input())
    xs = [int(i) for i in input().split()] 
    ans = INF
    for p in range(0, 101):
        sum = 0
        for i in xs:
            sum += (i-p)**2
        ans = min(ans, sum)
    print(ans)
main()

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
p_list = [0]
for P in range(1,101):
    power = 0
    for i in range(N):
        power += (X[i] - P)**2
    p_list.append(power)
sp_list = sorted(p_list)
print(sp_list[1])

Solution (Python):
import statistics as stat

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

Xm = int(stat.mean(X)+0.5)
power = 0
for i in range(N):
  power += (X[i]-Xm)**2
print(power)

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

min_ = min(list)
max_ = max(list)

total = []
if min_ == max_:
  print(0)
else:
  for i in range(min_, max_):
    length = 0
    for j in range(n):
  	  length += (list[j] - i)**2
    total.append(length)
  print(min(total))

Solution (Python):
def resolve():
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    xx = [0 for i in range(n)]
    for i,j in enumerate(x):
        xx[i] = j**2
    minp = 100
    for i in range(200):
        k = i*(n*i - 2*sum(x))
        if k < minp:
            minp = k
    print(sum(xx)+ minp)
if __name__ == "__main__":
    resolve()

Solution (Python):
import math
n=int(input())
x=list(map(int,input().split()))
s=sum(x)
st=s/n
if (st-math.floor(st))>0.5:
  p=math.ceil(st)
else:
  p=math.floor(st)
t=0
for m in x:
  t=t+((m-p)**2)
print(t)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
min = float('inf')

for i in range(max(x)):
    s = 0
    for j in range(n):
        s += (x[j]-(i+1))**2
    if s < min:
        min = s

print(min)

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



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

print(min_hp)

Solution (Python):


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

min = 100*100*100
for i in range(1, 101):
    sum = 0
    for j in range(N):
        val = (X[j]-i)*(X[j]-i)
        sum += val
    if min > sum:
        min = sum
print(min)

Solution (Python):
N=int(input())
X=input().split()
for i in range(len(X)):
    X[i]=int(X[i])
Xmin=min(X)
Xmax=max(X)
for P in range(Xmin,Xmax+1):
    p=0
    for xi in X:
        p+=(xi-P)**2
    if P==Xmin:
        m=p
    elif p<m:
        m=p
print(m)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
maxX =max(X)
ansmin = float('INF')
HP = 0
for i in range(1,maxX+1):
    for j in range(N):
        HP += (X[j]-i)**2
    ansmin = min(ansmin, HP)
    HP = 0
print(ansmin)

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

x.sort()

minD = 0
for x_i in x:
    minD += (x_i-1) ** 2


for i in range(2, 101):
    nowD = 0
    for x_j in x:
        nowD += (abs(x_j-i)) ** 2
    minD = min(nowD, minD)
print(minD)

Solution (Python):
def main():
    a = int(input())
    l = list(map(int, input().split()))
    temp = [0]*100

    
    for p in range(1,101):
        
        for score in l:
            temp[p-1] += (score-p)**2
    print(min(temp))
            

if __name__ == '__main__' :
    main()

Solution (Python):


import math

n = int(input())
l = list(input().split(" "))
l = [int(element) for element in l]

end = max(l)

dist = []

for i in range(1,end+1):
  s = 0
  for e in l:
    s += (e - i)**2
  dist.append(s)

print(min(dist))

Solution (Python):

N=int(input())
Y=0
s=0
X=list(map(int,input().split()))
P=0
for i in range(N):
  P+=X[i]

P/=N
D=int(P)
if (P-D)*10>=5:
  Y=int(P)+1
else:
  Y=int(P)
  


for i in range(N):
  s+=(X[i]-Y)**2
  
print(s)

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())
list = list(map(int, input().split()))

sum = 0
for i in list:
  sum += i
average = sum // len(list)


ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
ans5 = 0
for i in list:
  ans1 += (i-average+1)*(i-average+2)
  ans2 += (i-average+1)*(i-average+1)
  ans3 += (i-average)*(i-average)
  ans4 += (i-average-1)*(i-average-1)
  ans5 += (i-average-2)*(i-average-2)
answer = min(ans1,min(ans2,min(ans3,min(ans4,ans5))))
print(answer)

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

a=0
b=0

for i in range(N):
  b+=2*line[i]

j=round(b/(2*N))

for l in range(N):
  a+=(line[l]-j)**2

print(a)

Solution (Python):

N=int(input())
X=list(map(int,input().split()))
X_sum=sum(X)
ans=0
ans_ant=0
P=int(X_sum/N)
P_ant=int(X_sum/N)+1
for i in range(N):
    ans+=(X[i]-P)**2
    ans_ant+=(X[i]-P_ant)**2
print(min(ans,ans_ant))

Solution (Python):
import numpy as np
import math
N=int(input())
X=list(map(float,input().split()))
Xmin=int(math.floor(np.min(X)));Xmax=int(math.ceil(np.max(X)))
P=np.array([i for i in range (Xmin,Xmax+1)])
Sum=np.zeros(len(P),dtype=float)
for i in range(len(P)):
    Sum[i]=np.sum((np.array(X)-P[i])*(np.array(X)-P[i]))
print(int(np.min(Sum)))

Solution (Python):
from sys import stdin

def main():
    N = int(stdin.readline().rstrip())
    l = list(map(int, stdin.readline().rstrip().split()))
    result = 1000000
    for i in range(0, max(l)+1):
        sum = 0
        for x in l:
            sum += (x - i)**2
        if result > sum:
            result = sum
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):


stdin = open(0)
import numpy as np


data = np.fromstring(stdin.read(), np.int64, sep=' ')


X = data[1:]
costs = []
for p in range(101):
    costs.append(np.sum((X-p)**2))


answer = min(costs)
print(answer)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
m = sum(X)//N
def fun(X,m):
  s = 0
  for i in X:
    s += (i-m)**2
  return s

print(min(fun(X,m),fun(X,m+1)))

Solution (Python):
import numpy as np
n=int(input())
x=list(map(int,input().split()))
p=[0]*100
y=[0]*n
i=0
j=0
while i<100:
  def ppp(q):
    return (q-i)*(q-i)
  y=list(map(ppp,x))
  p[i]=np.sum(y)   
  i=i+1
r=min(p)
print(r)

Solution (Python):
N = int(input())
Xs = list(map(int, input().split()))
 
loss = 0
 
sum = 0
for X in Xs:
  sum += X
  
ave = round(sum/len(Xs))
 
for X in Xs:
  loss += (X-ave)**2
 
print(loss)

Solution (Python):
import math

n = int(input())
x = list(map(int, input().split()))
p1 = math.floor(sum(x) / n)
p2 = math.ceil(sum(x) / n)

result1 = 0
result2 = 0
for i in x:
  result1 += ((i - p1) * (i - p1))
  result2 += ((i - p2) * (i - p2))

if result1 <= result2:
  print(result1)
else:
  print(result2)

Solution (Python):
N=number=int(input())
X_list=list(map(int, input().split()))
min_pow=0
if N==1:
    print("0")
else:
    X_min=min(X_list)
    X_max=max(X_list)
    for i in range(X_min,X_max):
        sum_pow=0
        for j in range(N):
            sum_pow+=(X_list[j]-i)**2
        if i==X_min:
            min_pow=sum_pow
        if min_pow>sum_pow:
            min_pow=sum_pow
    print(min_pow)

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

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

for i in range(1, 101):
  sum=0
  for j in range(N):
    sum+=(L[j]-i)**2
  if min > sum: min=sum

print(min)

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

av1 = sum(a) // n
if sum(a) % n == 0:
    av2 = av1
else:
    av2 = av1 + 1

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (av1 - a[i]) ** 2
    ans2 += (av2 - a[i]) ** 2

print(min(ans1, ans2))

Solution (Python):
import statistics
N = int(input())
X = [int(i) for i in input().split()] 
C=0
D=int(format((statistics.mean(X)), '.0f'))
for i in range(N):
	C+=abs(D-X[i])**2
print(C)

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n = I()
X = LI()
ans = INF
for i in range(100):
    ret = 0
    for x in X:
        ret += (i - x) ** 2
    ans = min(ans, ret)


print(ans)

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

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


def short(P):
    remain = []
    for i in X:
        remain.append((P-i)**2)
    return sum(remain)

remainder = []
for i in range(1,101):
    remainder.append(short(i))

print(min(remainder))

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

ans = 100 ** 2 * N
for i in range(min(X), max(X)+1):
  a = 0
  for j in range(N):
    a += (X[j] - i) ** 2
  if ans > a:
    ans = a
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())
x = list(map(int, input().split()))

ct = sum(x) / n
ct = int(ct + 0.5)

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

Solution (Python):

N = int(input())
X = array = list(map(int, input().strip().split()))
num = 1
bor = 0
par = 0
score = 0
while par <= N-1:
        score = score + (X[par]-num)**2
        par = par +1
bor = score

while num <= 100:
    par = 0
    score = 0
    while par <= N-1:
        score = score + (X[par]-num)**2
        par = par +1
    if bor > score:
        bor = score
    num = num + 1
print (bor)

Solution (Python):
n = int(input())
cor = list(map(int, input().split()))
m = round(sum(cor)/n)
r = 0

for i in cor:
    r = r + (i-m)**2 
    
print(r)

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

Solution (Python):

def main():
    N = int(input())
    X = list(map(int,input().split()))
    ans = []
    for i in range(100):
        tmp = 0
        for j in range(N):
            tmp += (X[j]-i)**2
        ans.append(tmp)
    print(min(ans))
if __name__ == '__main__':
    main()

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

s = sum(x)
p = s / n
q = round(p)

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

print(r)

Solution (Python):
from functools import reduce
n = int(input())
X = list(map(int, input().split()))
minv =10000**2
for i in range(min(X),max(X)+1):
    minv = min(minv,sum((j-i)**2 for j in X))
print(minv)

Solution (Python):


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

X.sort()
start = X[0]
finish = X[-1]

def find_sum(x, A):
    summ = 0
    for a in A:
        summ += (a-x)**2
    return summ

res_len = n*((finish-start)**2)
for j in range(start, finish+1):
    len0 = find_sum(j, X)
    if len0 < res_len:
        res_len = len0

print(res_len)

Solution (Python):
N = int(input())
lis = list(map(int, input().split()))
P = []
for p in range(1,101,1):
  sum = 0
  for x in lis:
    sum += pow(x-p,2)
  P.append(sum)
print(min(P))

Solution (Python):
N=int(input())
Xs=[int(e) for e in input().split(' ')]

P=int(sum(Xs)/N + 0.5)

sum=0
for X in Xs:
    sum += (X-P)**2

print(sum)

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

Solution (Python):


N = int(input())
X = input().split(" ")
ans = []
for i in range(1,101):
    A = 0
    for j in X:
        x = abs(int(j) - int(i)) 
        A += x * x
    ans.append(A)
ans.sort()
print(ans[0])

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

res = 0

r = round(sum(x)/len(x))
for i in x:
    res += (i-r)**2
print(res)