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

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)

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)

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

print(ans)

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

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

if n==1:
    print('0')
    sys.exit()

if x.count(x[0])==n:
    print('0')
    sys.exit()

a=sum(x)/len(x)
d=[]
for i in range(min(x),max(x)):
    c=0
    for j in x:
        c+=(i-j)**2
    d.append(c)

print(min(d))

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

ans = 10**8+1

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

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

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

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

Solution (Python):
N = int(input(""))
X = input("").split(" ")
X = [int(b) for b in X]
ans = 0
xb = int(round(sum(X) / len(X)))
for a in X:
    ans += (a-xb)**2
print(ans)

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

Solution (Python):
def main():
    n = int(input())
    x_lst = list(map(int, input().split()))
    ans = 10 ** 12

    for p in range(1, 101):
        sum_hp = 0
        for x in x_lst:
            sum_hp += (x - p) ** 2
        if sum_hp < ans:
            ans = sum_hp

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math
n = input()
arr = list(map(int, input().split()))
a = sum(arr) // len(arr)
b = a + 1
'''
arr.sort()
if len(arr) % 2 == 0:
    mid = len(arr) // 2
    avg = (arr[mid] + arr[mid-1]) // 2
else:
    mid = len(arr) // 2
    avg = arr[mid]

print(avg)
'''
ans = 0
ans2 = 0
for p in arr:
    ans += (a - p)**2
    ans2  += (b - p)**2
print(min(ans, ans2))

Solution (Python):
import math
n = input()
arr = list(map(int, input().split()))
a = sum(arr) // len(arr)
b = a + 1
'''
arr.sort()
if len(arr) % 2 == 0:
    mid = len(arr) // 2
    avg = (arr[mid] + arr[mid-1]) // 2
else:
    mid = len(arr) // 2
    avg = arr[mid]

print(avg)
'''
ans = 0
ans2 = 0
for p in arr:
    ans += (a - p)**2
    ans2  += (b - p)**2
print(min(ans, ans2))

Solution (Python):

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

ans=float('inf')

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

Solution (Python):
a = int(input())
n = list(map(int, input().split()))
m = round(sum(n) / len(n))
print(sum((i-m) ** 2 for i in n))

Solution (Python):

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

ans = float('inf')

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

    ans = min(ans, cost)

print(ans)

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

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

Solution (Python):
n = int(input())
x = [int(y.strip()) for y in input().split()]
lower = min(x)
upper = max(x)
i = lower
ans = 10000*100
for i in range(upper+1):
  ttl = 0
  for j in x:
    dist = (j - i)**2
    ttl = ttl + dist
  if ttl < ans:
    ans = ttl
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
P = sum(X) // N
result1 = 0
result2 = 0

for x in X:
  result1 += (x - P)**2
  result2 += (x - P - 1)**2

if result1 <= result2:
  result = result1
elif result1 > result2:
  result = result2


print(result)

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

INF = 10**6 + 1
mintotal = INF
for p in range(1, 101):
    total = 0
    for x in X:
        total += (x-p)**2
    mintotal = min(mintotal, total)
print(mintotal)

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def main():
    N = I()
    X = LI()

    ans = INF

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

    print(ans)


if __name__ == '__main__':
    main()

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

def average(a):
  return sum(a) / len(a)

avg = average(X)

res = 0
if avg - int(avg) >= 0.5:
  for i in X:
    res += (i - math.ceil(avg)) **2
else:
  for i in X:
    res += (i - math.floor(avg)) ** 2
print(res)

Solution (Python):
n= int(input())
x= list(map(int,input().split()))
m= sum(x)/len(x)
g= int(m)
ans=0
if m-g<g+1-m:
  ans=g
else:
  ans=g+1
aaa=0
for i in x:
  aaa+= (ans-i)**2
print(aaa)

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    xs = i_list()

    min_list = []
    for i in range(1, 101):
        tmp = 0
        for x in xs:
            tmp += (i - x)**2
        min_list.append(tmp)

    print(min(min_list))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum([x * x for x in X])
if a / N - a // N < 0.5:
  c = a // N
else:
  c = a // N + 1
print(N * c * c - 2 * a * c + b)

Solution (Python):



n=int(input())
x=list(map(int,input().split()))
cost_min=1000000000
for i in range(1,101):
    cost=0
    for j in x:
        cost+=(j-i)**2
    if cost>=cost_min:
        continue
    cost_min=cost
print(cost_min)

Solution (Python):
from sys import stdin
from math import ceil, floor
n = stdin.readline().rstrip()
data = [int(x) for x in stdin.readline().rstrip().split()]
m = sum(data) / len(data)
cm = ceil(m)
fm = floor(m)
ceil_m = floor_m = 0
for i in data:
    ceil_m += (i-cm)**2
    floor_m += (i-fm)**2
print(min(ceil_m, floor_m))

Solution (Python):
from sys import stdin
from math import ceil, floor
n = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
m = sum(data) / len(data)
ceil_m = sum([(x-ceil(m))**2 for x in data])
floor_m = sum([(x-floor(m))**2 for x in data])
print(min(ceil_m, floor_m))

Solution (Python):
n = int(input())
xi = list(map(int,input().split()))
tairyoku = []
for p in range(100):
  tmp = 0
  for x in xi:
    tmp += (p+1-x)**2
  tairyoku.append(tmp)
print(min(tairyoku))

Solution (Python):

def main():
    _ = int(input())
    X = [int(x) for x in input().split()]

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


if __name__ == '__main__':
    main()

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

li = list(map(int, input().split()))
Ave1=sum(li)//N
Ave2=sum(li)//N+1
S1=0
S2=0
for i in range(N):
  S1=S1+(Ave1-li[i])**2
for i in range(N):
  S2=S2+(Ave2-li[i])**2

if S1>S2:
  print(S2)
else:
  print(S1)

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

li = list(map(int, input().split()))
Ave1=sum(li)//N
Ave2=sum(li)//N+1
S1=0
S2=0
for i in range(N):
  S1=S1+(Ave1-li[i])**2
for i in range(N):
  S2=S2+(Ave2-li[i])**2

if S1>S2:
  print(S2)
else:
  print(S1)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
m=10**15
for i in range(101):
    t=x[:]
    s=sum(list(map(lambda x:(x-i)**2,t)))
    m=min(m,s)
print(m)

Solution (Python):
import math

N = input()
XS = [int(i) for i in input().split()]

m = 9999999999
for i in range(1, 101):
	c = sum([(x - i) ** 2 for x in XS])
	if m > c:
		m = c

print(m)

Solution (Python):
n = int(input())
a = sorted(map(int, input().split()))
ans = 10000000000
for p in range(1,101):
  tmp = 0
  for j in a:
    tmp += (p-j)**2
  ans = min(tmp,ans)
print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
sum1 = 100*100**2
for i in range(101):
    sum2 = 0
    for j in range(len(x)):
        sum2 += (x[j] - i)**2
    if sum2 < sum1:
        sum1 = sum2
print(sum1)

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

for p in range(1, 100):
    sum_energy = 0
    for i in range(len(x)):
        sum_energy += (x[i] - p) ** 2
    sum_energy_list.append(sum_energy)

answer = min(sum_energy_list)

print(answer)

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

Solution (Python):
N = int(input())
X = list(map (int, input().split()))
av = round(sum(X)/len(X))
ans = 0

for x in X:
  ans = ans + (av-x)**2
  
print(ans)

Solution (Python):
def abc156c_rally():
    n = int(input())
    x = list(map(int, input().split()))
    min_x, max_x = min(x), max(x)
    best = float('inf')
    for i in range(min_x, max_x + 1):
        total = 0
        for v in x:
            total += (v - i) * (v - i)
        if best > total:
            best = total
    print(best)

abc156c_rally()

Solution (Python):
n=int(input())
x=[int(x) for x in input().split()]
ave1=sum(x)//n
ave2=ave1+1
a=0
b=0
for j in x:
  a+=(j-ave1)**2
  b+=(j-ave2)**2
print(min(a,b))

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

import math

X_min = math.floor(min(X))
X_max = math.ceil(max(X))

c = [0] * (X_max - X_min + 1)

for i in range(X_min, X_max+1):
  for j in range(N):
    c[int(i)-X_min] += (X[j] - i)**2
    
d = min(c)
print(d)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
mean_L = sum(X)//n
mean_R = mean_L+1
ans = min(sum(map(lambda x: (x-mean_L)**2, X)),
          sum(map(lambda x: (x-mean_R)**2, X)))
print(ans)

Solution (Python):
n = int(input())
line = list(map(int, input().split()))
min_dist = 10**9
for i in range(max(line)+1):
  sum_dist = 0
  for j in range(n):
    sum_dist += (line[j] - i)**2
  if sum_dist < min_dist:
    min_dist = sum_dist
print(min_dist)

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

costs = [0] * 100
for x in X:
    for i in range(100):
        costs[i] += (x - (i + 1)) * (x - (i + 1))
print(min(costs))

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

power_min = 1e8
for P in range(1,101):
    power = 0
    for i in range(N):
        power += (X[i]-P)**2
    if power < power_min:
        power_min = power

print(power_min)

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

ans=10**9
for p in range(-200, 200):
  ref=0
  for x in X:
    ref+=(x-p)**2
  
  ans=min(ans, ref)
  
print(ans)

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


avg = sum(X) / N
avgi = int(avg + 0.5)

ans = 0
for i in X:

    ans += (i-avgi)**2

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
k = []
def kyori(p):
  m = 0
  for i in range(n):
    m += (p-x[i])**2
  return m
for i in range(1,101):
  k.append(kyori(i))

print(min(k))

Solution (Python):
import numpy as np
N = int(input())
N_List = list(map(int,input().split()))
ans = (100**2)*100
for i in range(1,101):
    ca = sum(map(lambda x:(x-i)**2,N_List))
    if ca < ans:
        ans = ca

print(ans)

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

Solution (Python):
import math

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

min_hp = math.inf

for i in range(1, 101):
	hp = sum(map(lambda x: (x - i) ** 2, address))
	if hp < min_hp:
		min_hp = hp
		
print(min_hp)

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

Solution (Python):
a=int(input())
b=list(map(int,input().split()))
c=int(sum(b)/len(b)+0.5)
total=0
for i in range(a):
    total+=(b[i]-c)**2
print(total)

Solution (Python):
import statistics

n=int(input())
x=list(map(int,input().split()))
p1 = int(statistics.mean(x))
p2=p1+1
s1=0
s2=0
for i in range(n):
    s1+=(x[i]-p1)**2
    s2+=(x[i]-p2)**2
print(min(s1,s2))

Solution (Python):
import numpy as np

N = int(input())
x_list = list(map(lambda x: int(x), input().split(" ")))
M = np.sum(x_list)
L = np.sum(list(map(lambda x: int(x)**2, x_list)))

if M % N == 0:
    print(int(L - M**2 / N))
else:
    rest = M % N
    if rest <= N / 2:
        print(int(rest**2 / N - M**2 / N + L))
    else:
        print(int(N * (1 - rest / N)**2 - M**2 / N + L))

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

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

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

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

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
a = int(sum(X) / N)
b = a + 1
A, B = 0, 0
for x in X:
    A += (x - a) ** 2
    B += (x - b) ** 2
ans = min(A, B)
print(ans)

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

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

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

print(str(ans))

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

min_n = min(lst)
max_n = max(lst)
min_count = 1000000000
for i in range(min_n, max_n + 1):
  count = 0
  for j in range(n):
    count += (lst[j] - i) ** 2
  if count < min_count:
    min_count = count
print(min_count)

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

X.sort()

if N%2==0:
    ans=10**10
    for i in range(1,100):
        a=0
        for j in range(N):
            a+=(X[j]-i)**2
        ans=min(ans,a)
else:
    ans=10**10
    for i in range(1,100):
        a=0
        for j in range(N):
            a+=(X[j]-i)**2
        ans=min(ans,a)

print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math












import sys
sys.setrecursionlimit(10000000)


mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = float('inf')
for i in range(1,101):
    diff = 0
    for j in range(n):
        diff += pow(A[j]-i,2)
    ans = min(ans,diff)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
avg = sum(X)//N
aa = []
for i in range(2):
  avg = avg + i
  a = 0
  for j in range(N):
    a += (X[j] - avg)**2
  aa.append(a)
print(min(aa))

Solution (Python):
N, *X = map(int, open(0).read().split())
ans = float("inf")
for x in range(min(X), max(X) + 1):
    cur = 0
    for j in range(N):
        cur += (X[j] - x) ** 2
    ans = min(ans, cur)
print(ans)

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = 10**9
for k in range(min(X),max(X)+1):
    temp = 0
    for e in X:
        temp += (k-e)**2
    ans = min(temp,ans)
print(ans)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
cmin = 10**6+10
for i in range(101):
    cnt = 0
    for j in range(N):
        cnt += (i-X[j])**2
    cmin = min(cmin,cnt)
print(cmin)

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

ans = float('inf')
for p in range(101):
    temp = 0
    for x in X:
        temp += (x-p)**2
    ans = min(ans, temp)
print(ans)

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

print(sum([abs(i-y)**2 for i in x]))

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

ans = 10**10
for i in range(101):
    t = 0
    for x in X:
        t += (x-i)**2
    ans = min(ans, t)
print(ans)

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

print(ans)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
num = 10**10
for p in range(100):
    cnt = 0
    for i in range(n):
        cnt += (x[i] - p)**2
    num = min(num, cnt)
print(num)

Solution (Python):
n, *x = map(int, open(0).read().split())
print(min([sum([(a - i) ** 2 for a in x]) for i in range(1, 101)]))

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

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

ans = 10000000000000000

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

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
ans = float("inf")
for loc in range(-100,101):
  temp = 0
  for x in X:
    temp += (loc-x)**2
  ans = min(temp,ans)
print(ans)

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

Solution (Python):
n = int(input())    
xl = list(map(int, input().split()))    
ans = 10**9

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

print(ans)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
ans_min = 10**8
 
for i in range(min(A), max(A)+1):
    ans = 0
    for j in range(N):
        ans += (A[j] - i) ** 2
    
    if ans < ans_min:
        ans_min = ans
 
print(ans_min)

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

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

m = sum(X) // N
print(min(cost(m), cost(m+1)))

Solution (Python):
import math
import statistics
from decimal import Decimal, ROUND_HALF_UP
a = int(input())
b = list(map(int, input().split()))
c = statistics.mean(b)
d = Decimal(c).quantize(Decimal('1'), ROUND_HALF_UP)
ans = 0
for i in range(a):
  ans += (d - b[i])**2
print(ans)

Solution (Python):
n=int(input())
lis=list(map(int,input().split()))
       
f_ans=100000000000000
for i in range(min(lis),max(lis)+1):
  ans=0
  for l in lis:
    ans+=(i-l)**2
  f_ans=min(ans,f_ans)
    
print(f_ans)

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

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

ans = 10**18
ans_ = 0

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

print(ans)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans,count=[],0

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

Solution (Python):
import statistics

N = int(input())
X = list(map(int,input().split()))
P = round( statistics.mean(X) )

ans = sum([(i-P)**2 for i in X])
print(ans)

Solution (Python):
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

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

Sum_round_down=0
Sum_round_up=0
for i in range(len(X)):
    Sum_round_down+=(P-X[i])**2
    Sum_round_up+=(P+1-X[i])**2
if(Sum_round_down>=Sum_round_up):
    Sum=Sum_round_up
else:
    Sum=Sum=Sum_round_down
print(int(Sum))

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

health = 10**9
p_min = min(x)
p_max = max(x)
for p in range(p_min,p_max+1):
  tmp = 0
  for i in range(n):
    tmp += (x[i]-p)**2
    
  health = min(health, tmp)
print(health)

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

ave = sum(X) / float(N)
my_round_int = lambda x: int((x * 2 + 1) // 2)
t = my_round_int(ave)
val = 0
for x in X:
  val += (t - x)**2
print(val)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
hp_total = 10**7

for p in range(min(x),max(x)+1):
    hp = []
    for i in x:
        hp.append((i - p)**2)
    if hp_total > sum(hp):
        hp_total = sum(hp)
        
print(hp_total)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
m = 10**9
for i in range(min(x),max(x)+1):
    t = 0
    for h in x:
        t += (h-i)**2
    if t < m:
        m = t
print(m)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans = 100**2 * n

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

print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
ans = 100**2 * n

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

print(ans)

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

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

minimum = math.inf
for i in range(101):
    stamina = 0
    for j in range(N):
        stamina += (x[j]-i)**2
    minimum = min(minimum,stamina)

print(minimum)

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

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

av = sum(l)/n
af = math.floor(av)
ac = math.ceil(av)

sf = 0
sc = 0

for i in l:
    sf += (abs(i-af))**2
    sc += (abs(i-ac))**2

print(min(sf,sc))

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

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

print(sum_min)

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

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

Solution (Python):
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = sum(a) // n
ans = 0
for i in a:
    ans += (i - x) * (i - x)
x = math.ceil(sum(a) / n)
ans2 = 0
for i in a:
    ans2 += (i - x) * (i - x)
print(min(ans, ans2))

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

cnt = 0
mini = float('inf')

P = max(X) + 1

for i in range(P):
    for j in range(len(X)):
        cnt += (X[j] - i)**2
    if cnt < mini:
        mini = cnt
    cnt = 0

print(mini)

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

costs = []
for p in range(100):
  costs.append(sum(map(lambda x: (x - p)**2, X)))

print(min(costs))

Solution (Python):
N = int(input())
cc = list(map(int,input().split()))
min_sum = float('inf')
for i in range(1,101):
  count = 0
  for j in cc:
    count += (i-j)**2
  min_sum = min(min_sum,count)
print(min_sum)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
avex=sum(x)//n
ansl=0
ansr=0
for i in x:
  ansl+=(avex-i)**2
  ansr+=(avex+1-i)**2

  
print(min(ansl,ansr))

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

sum = 0
for i in points:
  sum += i

mean = sum/len(points)
if mean%2 != 0:
    mean = int(round(mean,0))

ans = 0
for i in points:
  ans += (i - mean)**2

print(ans)

Solution (Python):








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

mix_x = min(x)
max_x = max(x)

ans = 10000000000000
for i in range(mix_x, max_x+1):
    power = 0
    for j in range(n):
        power += (x[j] - i)**2
    ans = min(ans, power)
print(ans)

Solution (Python):
def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost)

if __name__ == "__main__":
  resolve()

Solution (Python):
import math



n = input();

x_list = list(map(int, input().split()));


sum_p = 0;
for i in x_list:
    sum_p = sum_p + i;


round_ave = lambda x:(x*2+1)//2;

p = round_ave(sum_p/len(x_list));


result = 0;
for i in x_list:
    result = result + (i - p)**2


print(math.floor(result))