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

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

x_max = max(x)
x_min = min(x)
hp_min = 10000*100

for p in range(x_min, x_max + 1):
    hp = 0
    for x_i in x:
        hp += (x_i - p)**2
    if hp < hp_min:
        hp_min = hp
    
print(hp_min)

Solution (Python):
def calc_tairyoku(x, p):
    return (x - p) ** 2

N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
min_x = X[0]
max_x = X[N-1]

result = 10 ** 6
for x in range(min_x, max_x+1):
    s = sum([calc_tairyoku(x, i) for i in X])
    result = min(result, s)

print(result)

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





def sum_power(y):
  return sum([(x - y) * (x - y) for x in X])

import sys
minimum = sys.maxsize
for y in range(min(X), max(X)+1):
  minimum = min(minimum, sum_power(y))
print(minimum)

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

min = 2**50

for p in range(100):
    min_i = 0
    if p in x:
        continue
    for i in x:
        min_i = min_i + (int(i) - p)**2
    if min_i <= min:
        min = min_i
print(min)

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

min = 2**20

for p in range(100):
    min_i = 0
    if p in x:
        continue
    for i in x:
        min_i = min_i + (int(i) - p)**2
    if min_i <= min:
        min = min_i
print(min)

Solution (Python):
import math
N = int(input())
lst = list(map(int, input().split()))
X = math.floor(sum(lst)/N + 0.5)
ans = 0
for i in lst:
    ans = ans + (X - i)**2

print(ans)

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

ans=n * 100**2
for p in range(101):
    ans=min(ans,sum([(xi-p)**2 for xi in x]))
print(ans)

Solution (Python):
N = int(input())
ans = 10**8
array = list(map(int,input().split()))
for i in range(0,101):
  energy = 0
  for t in array:
    energy += ( t - i ) ** 2
  ans = min(ans,energy)
print(ans)

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

ans = float("inf")
for p in range(1,101):
    hp = 0
    for i in x:
        hp += (i-p)**2
    ans = min(ans, hp)
print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
mi=min(x)
ma=max(x)
ans = sum(x)**2
for i in range (mi,ma+1):
  hp=0
  for j in x:
    hp+= (i-j)**2
  ans = min(hp,ans)
print(ans)

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

Solution (Python):
import sys
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 = 10 ** 9 + 7
import math
import statistics
n = I()
xl = LI()







xl_ceil_mean = math.ceil(statistics.mean(xl))
xl_floor_mean =math.floor(statistics.mean(xl))

sigma_pow1 = sum([(x-xl_ceil_mean)**2 for x in xl])
sigma_pow2 = sum([(x-xl_floor_mean)**2 for x in xl])

if sigma_pow1 > sigma_pow2:
    print(sigma_pow2)
else:
    print(sigma_pow1)

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

min =10**5
meandown = math.floor(sum(Xlist)/N)
meanup = math.ceil(sum(Xlist)/N)
sumdown=0
sumup = 0
for i in range(len(Xlist)):
  sumdown+= (Xlist[i]-meandown)**2
  sumup+= (Xlist[i]-meanup)**2
  
if sumdown<sumup:
  print(sumdown)
else:
  print (sumup)

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

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

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

for p in range(min(x), max(x)+1):
    sum = 0
    for i in x:
        sum = sum + (i-p)**2 
    hp.append(sum)
    
print(min(hp))

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

ans=10**1000
for p in range(X[0],X[-1]+1):
    tmp=0
    for x in X:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
x = l()
a = sum(x)//n
b = sum(x)//n + 1

for i in x:
  ans += pow(i-a,2)
  cnt += pow(i-b, 2)

print(min(ans,cnt))

Solution (Python):
a = 0
b = 0

N = int(input())
X = list(map(int, input().split()))
avg = sum(X) // N
for tai in X:
  a += (tai - avg) ** 2
for tai in X:
  b += (tai - (avg + 1)) ** 2
if a > b :
  print(b)
else :
  print(a)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
P = round(sum(X)/N)
ans = sum(list(map(lambda x: (x-P)**2, X)))
print(ans)

Solution (Python):
input()
x=list(map(int,input().split()))
r=10**10
for i in range(min(x),max(x)+1):
	s=0
	for j in x:
		s+=(i-j)**2
	r=min(r,s)
print(r)

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

print(int(ans))

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

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

h = round(sum(x) / n)

ans = 0

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

print(ans)

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

dp=[0 for i in range(100)]
i=1
for j in range(N):
    dp[0]+=(X[j]-0)**2

while True:
    for j in range(N):
        dp[i]+=(X[j]-i)**2
    if dp[i]>=dp[i-1]:
        break
    i+=1

ans=dp[i-1]
print(ans)

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
ave = sum(x) // n
ansl = 0
ansr = 0

for i in x:
    ansl += pow(i - ave, 2)
    ansr += pow(i - ave - 1, 2)

print(min([ansl, ansr]))

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
l,r,ans = min(L),max(L),10**18

for i in range(l,r+1):
  total = 0
  for l in L:
    total += (l-i)**2
  ans = min(ans, total)
print(ans)

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

list1.sort()
x=list1[0]
y=list1[-1]

s=0
list2=[]
while x+s<=y:
    list2.append(x+s)
    s=s+1

list3=[]
for j in list2:
    w=0
    for i in list1:
        w=w+(i-j)*(i-j)
    list3.append(w)

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    X=LI()
    
    ans=10**10
    
    for i in range(1,101):
        temp=0
        for j in range(N):
            temp+=abs(i-X[j])**2
        ans=min(ans,temp)
        
    print(ans)
        

main()

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

total = 0
m = round(sum(X) / N)

for i in X:
    total += (m - i) ** 2
print(total)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
x_min = min(X)
x_max = max(X)

min_val = 10**6 + 1

for i in range(x_min, x_max + 1):
    min_val = min(min_val, sum(map(lambda x: (x-i)**2, X)))

print(min_val)

Solution (Python):
import os, sys, re, math

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

d = [i ** 2 for i in range(101)]

min_v = 100 ** 2 * 100
for i in range(1, 101):
    min_v = min(min_v, sum(d[abs(x - i)] for x in X))

print(min_v)

Solution (Python):
n = int(input())
aaa = list(map(int, input().split(' ')))
center = sum(aaa) // n
ans = 99999999999999999
for i in [-1, 0, 1]:
  ans = min(ans, sum([(a - center + i) ** 2 for a in aaa]))
  
print(ans)

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

Solution (Python):
n = int(input())
a = sorted(map(int, input().split()))
ret = float('inf')
for p in range(1, 101):
    dist = 0
    for v in a:
        dist += (v - p) ** 2
    ret = min(ret, dist)
print(ret)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
avg = sum(X)//N
sums_1 = 0
sums_2 = 0
for i in X:
    sums_1 += (avg - i)**2

for j in X:
    sums_2 += (avg+1 - j)**2


print(min(sums_1,sums_2))

Solution (Python):
a = int(input())
b = input().split()
b = [int(j) for j in b]
x = round(sum(b) / a)
y = []
for i in range(a):
    y.append((x - b[i])**2)
print(sum(y))

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

distance = 0
min_distance = float('Inf')

for i in range(1,101):
    for j in range(N):
        distance += (int(X[j]) - i) ** 2

    min_distance = min(min_distance, distance)
    distance = 0

print(min_distance)

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()))
small = 10000000
temp = 0
p_max = max(X)

for p in range(1, p_max + 1):
  for i in range(N):
    temp += (X[i] - p)**2
    
  if temp < small:
    small = temp
  
  temp = 0
  
print(small)

Solution (Python):
n = int(input())
x = sorted(list(map(int, input().split())), reverse = True)
x_2 = list(map(lambda x:x ** 2, x))
ichi = sum(x)
jijou = sum(x_2)
re = 10 ** 100






for p in range(1, x[0] + 1):
    second = n * (p ** 2)
    third = -2 * p * ichi
    summ = jijou + second + third

    if re > summ:
        re = summ

print(re)

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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ave = sum(x) // len(x)
ans_list = []
ans_list2 = []
for i in x:
    ans = (i - ave)**2
    ans_list.append(ans)
ans1 = sum(ans_list)

ave2 = ave + 1
for i in x:
    ans = (i - ave2)**2
    ans_list2.append(ans)
ans2 = sum(ans_list2)
if ans1 < ans2:
    print(ans1)
else:
    print(ans2)

Solution (Python):


import math

def power(P, X):
    ans = 0
    for x in X:
        ans += (x-P)**2
    return ans

N = int(input())
X = list(map(int, input().split()))
ave = sum(X)/N
candP = (math.ceil(ave), math.floor(ave))
power = min(map(lambda P: power(P, X), candP))

print(power)

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

min_x = 100 * 100 * 100 + 1
for p in range(1, 100+1, 1):
  total = 0
  for xi in x:
    total += (xi - p) ** 2

  min_x = min([min_x, total])

print(min_x)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans = []
if len(set(x)) == 1:
    print(0)
else: 
    for p in range(min(x), max(x)):
        meter = 0
        for xi in x:
            meter += pow((xi-p),2)
        ans.append(meter)
    print(min(ans))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
MIN = 100**3

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

print(MIN)

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

ans = 10**7+9

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

X = len(x)

for i in range(100):
    total = 0
    for j in range(X):
        total += (x[j]-i)**2
    else:
        ans = min(ans,total)

print(ans)

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

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

Solution (Python):

import sys
import math


def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    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 numpy as np
N = int(input()) 
X_ls = np.array(list(map(int, input().split())))




ans = 0
for p in range(max(X_ls)+1):
    sub = X_ls-p
    ans_1 = sum(sub**2)
    if ans_1 <= ans or ans ==0:
        ans = ans_1
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
sum= 1000000000000000
for p in range(1,101):

    tmp=0
    
    for i in range(len(x)):
        tmp += (x[i] - p)**2
        
    sum = min(sum,tmp)
    
print(sum)

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

lst.sort()
M = lst[-1]
m = lst[0]
total = float('inf')

for i in range(m,M+1):
  s = sum([(x-i)**2 for x in lst])
  if s < total:
    total = s
    
print(total)

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Solution (Python):
def stamina(x, p):
    return (x - p) ** 2


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

    min_sum = 10 ** 10
    for p in range(1, 101):
        s_sum = 0
        for p_x in Xs:
            s_sum += stamina(p_x, p)

        min_sum = min(min_sum, s_sum)

    print(min_sum)
resolve()

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
_min = min(X)
_max = max(X)
_sum = 1000000000
for i in range(_min, _max+1):
    temp = 0
    for x in X:
        temp += (x - i) * (x - i)
    if temp < _sum:
        _sum = temp
print(_sum)

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

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

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

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

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

for p in range(X[N-1] + 1):
    sum = 0
    for i in range(len(X)):
         sum += (X[i]-p)**2
         ans = sum
    p += 1
    data.append(ans)

print(min(data))

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Solution (Python):


a=int(input())





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

f.sort()
ans=0
ma = []
for i in range(f[0],f[-1]+1):
    for k in f:
        ans+=((k-i)**2)
    ma.append(ans)
    ans=0
print(min(ma))

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

tairyoku = []
for x in range(min(p),max(p)+1):
  a = 0
  for y in p:
    a += (x-y)**2
  tairyoku.append(a)
  
print(min(tairyoku))

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val +=  (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Solution (Python):
n = int(input())
lst = list(map(int,input().split()))
for j in range(101):
    if (j == 0):
        ans = 0
        for i in range(n):
            ans = ans + lst[i]**2
    else:
        x = 0
        for i in range(n):
            x = x + (lst[i] - j)**2
        if (x < ans):
            ans = x

print(ans)

Solution (Python):
N=int(input())
Xlist=list(map(int,input().split()))
ans=10**18
for p in range(1,101):
    ans=min(ans,sum(list(map(lambda x:(p-x)**2,Xlist))))
print(ans)

Solution (Python):
import sys
N = int(input())
X = [int(c) for c in input().split()]
l = [10**10]
for i in range(1,101):
    l.append(0)
    for j in range(len(X)):
        l[i] += (X[j]-i)**2
    
    if l[i-1] < l[i]:
        print(l[i-1])
        sys.exit(0)

Solution (Python):


def main():
    N = input()
    X = list(map(int, input().split()))
    ans = 1000001

    for i in range(1, 101):
        tmp = sum([(x - i) ** 2 for x in X])
        if tmp < ans:
            ans = tmp

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
SUM = 0
DIF = 0
for i in range(N):
    SUM = SUM + X[i]

AVG = round((SUM / N))



for i in range(N):
    DIF = DIF + (abs(X[i] - AVG))**2
print(DIF)

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

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

ans = float("inf")

for p in range(min(x),max(x)+1):
	t = 0
	for i in x:
		t+=(i-p)**2
	ans = min(ans, t)

print(ans)

Solution (Python):


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

c = []
x_ave = int(sum(x)/n)
s = 0
for i in range(n):
    s += (x[i]-x_ave)**2
c.append(s)
s = 0
for i in range(n):
    s += (x[i]-x_ave-1)**2
c.append(s)


print(min(c))

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

print(m)

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

for p in range(100):
    S =0
    for x in X:
        S += (x-p)**2
    ans = min(ans,S)

print(ans)

Solution (Python):
import sys

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



for i in range(min(x),max(x)+1,1):
    tmp = sum(map(lambda p: (p-i)**2,x))
    if ans > tmp:
        ans = tmp
    
print(ans)

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

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

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

print(min(ans))

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

G = int(sum(X)/N + 0.5)

ans = sum((x-G)**2 for x in X)

print(ans)

Solution (Python):
N = int(input())
s = list(map(int , input().split()))
list.sort(s , reverse = True)
L = [10**10]
for p in range(min(s) , max(s) + 1):
  a = 0
  b = L[0]
  for i in range(N):
    if a < b:
      a += (s[i] - p) ** 2
  if a < b:
    L[0] = a
print(L[0])

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

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

a = min(X)
b = max(X)

s = 10**6
for i in range(a, b+1):
    t = 0
    for j in range(N):
        t += (X[j] - i)**2
    if t < s:
        s = t

print(s)

Solution (Python):
n = int(input())
x = [int(x) for x in input().split()]
res = 10 ** 10
for i in range(101):
  c = 0
  for j in range(n):
    c += (i - x[j]) ** 2
  res = min(res,c)
print(res)

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Solution (Python):

import sys
import math
input=sys.stdin.readline

def main():
    maps=[]
    n = int(input())
    maps=list(map(int,input().split()))
    ans=0
    answers=[]

    for i in range(1,101):
        for data in maps:
            ans+=abs(i-data)**2
        answers.append(ans)
        ans=0
    print(min(answers))

if __name__=="__main__":
    main()

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



a = sorted(a)
minsum = float('inf')
for i in range(a[0], a[-1]+1):
  cnt = 0
  for ai in a:
    cnt += (ai - i)**2
  if cnt <= minsum:
    minsum = cnt
print(minsum)

Solution (Python):

def main():
    n = int(input())
    x = list(map(int, input().split(" ")))
    min = 1e9
    for i in range(1,101):
        na = 0
        for j in x:
            na += (j - i)**2
        if na < min:
            min = na
    print(min)
        



if __name__ == "__main__":
    main()

Solution (Python):
num = int(input())
pos = list(map(int,input().split()))
maxpos = max(pos)
minhealth = 1e9
count = 0
for i in range(maxpos+1):
    for j in pos:
        count += (j-i)**2
    minhealth = min(minhealth, count)
    count = 0
print(minhealth)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
import bisect
def main():
    N = I()
    X = LI()
    Ans_list = []
    for i in range(1, 101):
        cnt = 0
        for x in X:
            cnt += (x - i) ** 2
        Ans_list.append(cnt)
    print(min(Ans_list))

if __name__ == "__main__":
    main()

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

x.sort()

ans = 1000000000

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

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

for i in range(100):
	P=i+1
	a=0
	for x in X:
		a+=(x-P)**2
	ans[i]=a

print(min(ans))

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

m = sum(x)/len(x)
m = int(round(m))
power = sum([(i - m)**2 for i in x])
print(power)

Solution (Python):
N = int(input())
nums = list(map(int, input().split()))
answer = 10**8
for p in range(1, 100):
  power = 0
  for j in range(N):
    power += (p-nums[j])**2
  answer = min(answer, power)
print(answer)

Solution (Python):

N = int(input())
X = list(map(int,input().split()))
ans = 10**10
for p in range(1,101):
    tmp = 0
    for x in X:
        tmp += (x-p)**2
    ans = min(ans,tmp)
print(ans)

Solution (Python):
n=int(input())
x = list(map(int,input().split()))
y =[]
b = sum(x)
for i in range(n):
        y.append((x[i])**2)
a = sum(y)

p = round(b/(n))
ans = (n)*p**2-2*p*b+a
print(ans)

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

ans = float('inf')
for i in range(1, 101):
    h = 0
    for j in x:
        h += (i-j)**2
    ans = min(ans, h)
print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n = int(input())
    p = np.array(read().split(), np.int32)
    r = float('inf')
    for i1 in range(101):
        r = min(r, sum((p - i1)**2))
    print(r)

if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

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

mid = sum(x)//len(x)

ans = float('inf')
for i in [-1, 0, 1]:
    temp = sum([(i+j-mid)**2 for j in x])
    ans = min(temp, ans)
print(ans)

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

ans = 999999

for i in range(100):
    x = 0
    for a in A:
        x += (a-i)**2
    ans = min(ans,x)

print(ans)

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

X.sort()
dist = float("inf")
for i in range(X[0],X[-1]+1):
  d = 0
  for j in range(N):
    d += (i - X[j]) ** 2
  dist = min(dist,d)
  
print(dist)

Solution (Python):
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
x = li()

ave = sum(x) //n

ans1=0
for i in range(n):
    ans1 += (x[i]-ave) ** 2
ans2=0
for i in range(n):
    ans2 += (x[i]-(ave+1)) ** 2
print(min(ans1,ans2))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
 
def calc_power(p):
  P = list(map(lambda x: (x-p)**2, X))
  return sum(P)
 
power = []
_min = min(X)
_max = max(X)

if _min != _max:
  for p in range(_min, _max):
    power.append(calc_power(p))
  print(min(power))
  
else:
  power = calc_power(_min)
  print(power)

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

avg1 = sum(x)//n
avg2 = avg1+1

ans1 = int(sum([(i - avg1)**2 for i in x]))
ans2 = int(sum([(i - avg2)**2 for i in x]))

print(min(ans1,ans2))

Solution (Python):

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

P=round(sum(X)/N,0)
vital_sum=0
for i in X:
    vital_sum+=(i-P)**2
print(int(vital_sum))

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

m = min(x)
M = max(x)
ans = 10**9
for i in range(m,M+1):
  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()))
 
ans = 10**9
m = min(X)
M = max(X)
for i in range(m, M+1):
  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()))
 
ans = 10**9
m = min(X)
M = max(X)
for i in range(m, M+1):
  s = 0
  for j in range(N):
    s += (X[j]-i)**2
  ans = min(ans, s)
  
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):
  count = 0
  for j in X:
    count += (j - i) ** 2
  ans = min(ans, count)
print(ans)

Solution (Python):
from sys import stdin
from decimal import Decimal, ROUND_HALF_UP

n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))
p = sum(data) / n


p_int = (Decimal(p).quantize(Decimal('1'), ROUND_HALF_UP))

Sum = 0
for i in data:
	Sum  += (i - p_int) ** 2 
print(Sum)

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

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

Solution (Python):
import numpy as np
 
N = input()
X = list(map(int, input().split()))
ans=9999999
for P in range(0, 101):
  sum = np.sum(list(map(lambda x: (x-P)**2, X)))
  ans = min(ans, sum)
    
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    X = list(map(int, readline().split()))
    ans = INF

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

    print(ans)


if __name__ == '__main__':
    main()

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

lc=[]
for i in range(1,101):
    c = 0
    for x in lx:
        c += (i-x)**2
    lc.append(c)

print(min(lc))

Solution (Python):

n = int(input())

PosList = []
TempSum = 0
ReturnSum = 0

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


for pos in range(1,101):
    TempSum = 0
    for nPos in range(n):
        TempSum += (pos - PosList[nPos])**2
    if pos == 1:
        ReturnSum = TempSum
    elif ReturnSum > TempSum:
        ReturnSum = TempSum
    """
    print("Position = "+str(pos))
    print("TempSum = "+ str(TempSum))
    print("ReturnSum = " + str(ReturnSum))
    print("----------------------------")
    """

print(ReturnSum)