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()))
s = sum(x)
ans1,ans2 = 0,0
for i in range(N):
    ans1 += (-x[i]+s//N)**2
    ans2 += (-x[i]+s//N+1)**2
print(min(ans1,ans2))

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




temp=[]
for p  in range(0,3*N):
    answer=0
    for i in X:
        answer+=((i-p)**2)
    temp.append(answer)

print(min(temp))

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

s = sum(X)
mean = round(s / N)

P = []
for i in range(N):
    P.append((X[i]-mean)**2)

print(sum(P))

Solution (Python):
import sys

INF = sys.maxsize

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

costs = [INF] * (200)

for p in range(1, 101):
  costs[p] = sum(abs(p - r) ** 2 for r in residents)

print(min(costs))

Solution (Python):
import math
n = int(input())
x_list = list(map(int,input().split()))
 
avg = sum(x_list)/ len(x_list)
avg_up = math.ceil(avg)
avg_down = math.floor(avg)
 
up_sum = 0
down_sum = 0
for i in x_list:
    up_sum += (i - avg_up)**2
    down_sum += (i - avg_down)**2
    
print(min(up_sum,down_sum))

Solution (Python):

import math

n = input()
xs = map(int, raw_input().split())




p = round(1.0 * sum(xs) / n)
mindist = math.ceil(sum((x - p) ** 2 for x in xs))

print int(mindist)

Solution (Python):
N = int(input())
x = list(map(int, input().split()))
import numpy as np
x = np.array(x)
E = 10**9 
for i in range(1, 101):
  e_tem = np.sum((x-i)**2)
  if e_tem < E:
    E = e_tem
print(E)

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

m1 = -(-sum(x) // len(x))
m2 = sum(x) // len(x)
ans1 = 0
ans2 = 0
for xi in x:
    ans1 += (xi - m1)**2
    ans2 += (xi - m2)**2

print(min(ans1, ans2))

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

sum = []
for i in range(1, 101):
    sums = 0
    for x in xs:
        s = (x-i) ** 2
        sums += s
    sum.append(sums)
print(min(sum))

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

p = round(sum(X) / len(X))

point = [0] * len(X)
for i in range(len(X)):
    point[i] = (X[i] - p)**2

print(sum(point))

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X.sort()
add = 0
mi = (X[0]-X[-1])**2*N
for i in range(X[0],X[-1]):
  for j in range(N):
    add += (X[j]-i)**2
  if add < mi:
    mi = add
    add = 0
print(mi)

Solution (Python):
import numpy as np
import math

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

guess1 = math.floor(np.mean(X))
guess2 = math.ceil(np.mean(X))

value1 = 0
value2 = 0
for i in range(N):
    value1 += (X[i] - guess1)**2
    value2 += (X[i] - guess2)**2
if value1 <= value2:
    print(value1)
else:
    print(value2)

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

P = round(sum(X) / N)
print(sum((x - P) ** 2 for x in X))

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
res = 100**100
for i in range(1, 101):
  tmp = 0
  for j in range(N):
    tmp += (i-X[j])**2
  if tmp < res:
    res = tmp

print(res)

Solution (Python):
import math

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

s = 0
for i in range(len(x)):
    s += x[i]

s /= len(x)

s = math.floor(s)

m1 = 0
m2 = 0

for i in range(len(x)):
    m1 += math.pow(x[i] - s,2)
    m2 += math.pow(x[i] - s - 1,2)

print(int(min(m1, m2)))

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

res = 10 ** 8

for p in range(1, 101):
    now = 0
    for x in Xs:
        now += (x - p)**2
    res = min(now, res)

print(res)

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

min_sum = 10000000000000000000000000000000000000

for j in range(0,100):
	tmp_sum = 0
	for i in range(N):
		tmp_sum += (X[i] - j) ** 2
	if tmp_sum < min_sum:
		min_sum = tmp_sum
	
print(min_sum)

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

for i in range(201):
    ans = sum([k ** 2 for k in X - i])
    if i > 0:
        ans_min = min(ans_min, ans)
    else:
        ans_min = ans
print(ans_min)

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

x = np.array(x)
ans = [0]*101

for i in range(101):
    y = np.full(n, i)
    z = x-y
    z = np.power(z, 2)
    ans[i] = np.sum(z)

print(int(min(ans)))

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

p = np.mean(a)

p1 = int(p)
p2 = p1 + 1

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



print(min(ans1, ans2))

Solution (Python):
import sys
N = int(input())
Xl = list(map(int, input().split()))
Xl.sort()
minx = Xl[0]
maxx = Xl[-1]
minsum = sys.maxsize
for i in range(minx, maxx+1):
    sumd = 0
    for x in Xl:
        sumd += (x - i)**2
    if sumd < minsum:
        minsum = sumd
print(minsum)

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

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

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

total = 0
for num in nums:
    total += abs((num-ave)**2)

print(total)

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

mh = 1000000000
for x in range(1,101):
    sh = 0
    for n in range(N):
        sh += (Xs[n] - x)*(Xs[n] - x)
    mh = min(mh, sh)

print(mh)

Solution (Python):
n= int(input());
ls=list(map(int,input().split()));
x=int(sum(ls)/len(ls))
y=x+1;
ans1=0;
ans2=0;
for i in ls:
    ans1+=(x-i)**2;
    ans2+=(y-i)**2;
print(min(ans1,ans2))

Solution (Python):



n = input()
X = input().rstrip().split(' ')

n = int(n)
x = [0 for _ in range(n)]

for a in range(n):
    x[a] = int(X[a])
    
x.sort()

count = 1000000
tei = 0

for a in range(100):
    tei = 0
    for b in x:
        tei += (b-a)**2
    count = min(tei,count)
print(count)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
ll = len(l)
res = 0
ans = 10000000000
 
for i in range(1, 101):
    for j in range(ll):
        res += (l[j] - i)**2
    ans = min(ans, res)
    res = 0
 
print(ans)

Solution (Python):
N= int(input())
X = list(map(int,input().split()))
def calc(n):
  ans = 0
  for x in X:
    ans += (x-n)**2
  return ans
ans = 100000000
for n in range(100):
  ans = min(ans,calc(n))
print(ans)

Solution (Python):

import sys

def solve(N: int, X: "List[int]"):
    avg = round(sum(X) / len(X))
    ans = 0
    for i in range(N):
        ans = ans + ((X[i] - avg) ** 2)

    print(ans)

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):
n = int(input())

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

sub_num = 10**10+7
for i in range(1,101):
    _max = 0
    
    for j in range(n):
        
        
        _max+=((i-x_ls[j])**2)
    sub_num = min(sub_num, _max)
print(sub_num)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
s=int(sum(x)/n+0.5)

a=0
for i in x:
    a+=(i-s)**2
print(a)

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

PP = sum(XL) / len(XL)
P = sum(XL) // len(XL)
R0= sum([(x - P - 1) ** 2 for x in XL])
R1= sum([(x - P) ** 2 for x in XL])
R2= sum([(x - P + 1) ** 2 for x in XL])

print(min(R0, R1, R2))

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

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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
X = [int(x) for x in stdin.readline().rstrip().split()]

def solve(X, i):
    Y = [(x - i) ** 2 for x in X]
    return sum(Y)

minv = 10**9
bv = minv+1
i = 0
while minv < bv:
    bv = minv
    v = solve(X, i)
    i += 1
    if minv > v:
        minv = v
print(minv)

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

p = round(sum(x_list)/n)

power = sum([(x-p)**2 for x in x_list])

print(power)

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

A={}
s=sum(X)
for i in range(1,101):
    A[i]=N*i**2-2*i*s

min_i=min(A, key=A.get)

a=0
for j in range(N):
   a+=(X[j]-min_i)**2 

print(a)

Solution (Python):
n = int(input())
x = input().split(" ")
for i in range(n):
	x[i] = int(x[i])
b = 1000000
for i in range(1, 101):
	t = 0
	for j in range(n):
		t = t + (i - x[j]) * (i - x[j])
	if t < b:
		b = t
print(b)

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

if (len(set(x)) == 1):
  print(0)
else:
  ans = []
  for p in range(min(x), max(x)):
    sigma = 0
    for i in x:
      sigma += (p-i)**2
    ans.append(sigma)
  print(min(ans))

Solution (Python):
n=map(int,input().split())
x=list(map(int,input().split()))
ans=10**10
for i in range(0,200):
    chk=0
    for j in x:
        chk+=(j-i)**2
    if chk<ans:ans=chk
print(ans)

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

ans = 1001001001
for p in range(1, 101):
	tmp = 0
	for i in range(n):
		tmp += (x[i]-p)**2
	ans = min(ans, tmp)

print(ans)

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

Solution (Python):
import math

n=int(input())
a=list(map(int,input().split()))
mean=sum(a)/n
mean_one=math.ceil(mean)
mean_two=math.floor(mean)


ans_one=0
for i in a:
    ans_one+=(i-mean_one)**2
ans_two=0
for i in a:
    ans_two+=(i-mean_two)**2
ans=min(ans_one,ans_two)
print(ans)

Solution (Python):
n=int(input())
x = list(map(int,input().split()))
x.sort()
a = sum(x)
b = []
for i in range(0,n):
    b.append(x[i]**2)
c = sum(b)
s = n -2 * a
for j in range(2,101):
    t = n * (j**2) -2 * j * a
    if t < s:
        s = t
print(s+c)

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

t = int(round(sum(A)/N,0))
c = 0

for i in A:
    c += ( i - t )**2

print(c)

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

s = sum(X)
s2 = sum(x*x for x in X)

ans = 10**15
X.sort()

for p in range(X[0], X[-1]+1):
    r = s2 - 2 * p * s + N * p * p
    ans = min(ans, r)

print(ans)

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

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

mp = 10**9
for i in range(1, 101):
    s = 0
    for j in x:
        s += (i - j)**2
    if mp > s:
        mp = s

print(mp)

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

_list = [-1 for i in range(100)]
if min(x)==max(x):
    print(0)
else:
    for i in range(min(x), max(x), 1):
        a = 0
        for j in range(n):
            a += (x[j]-i)**2
        _list[i] = a
    _list = np.array(_list)
    print(min(_list[_list>=0]))

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



anc = float('inf')
tmp = 0
for p in range(min(c),max(c)+1):
    for i in c:
        tmp += (i-p)**2
    if tmp < anc:
        anc = tmp
    tmp = 0
print(anc)

Solution (Python):
input()
li = list(map(int, input().split()))
ans = -1
for i in range(min(li), max(li)+1):
    hp = sum([(regi - i) ** 2 for regi in li])
    if ans < 0 or ans > hp: ans = hp
print(ans)

Solution (Python):

"""
Created on Sat Feb 22 20:52:29 2020

@author: H_Hoshigi
"""

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

P = sum(X_list) // N

cost_list_1 = [(Xi-P)**2 for Xi in X_list]
cost_list_2 = [(Xi-(P+1))**2 for Xi in X_list]

print(min(sum(cost_list_1),sum(cost_list_2)))

Solution (Python):
import numpy as np

N = int(input())
X = sorted(map(int, input().split())) 
P = int(round(np.mean(X)))

a = 0
for x in X:
  a += abs(P-x)**2
print(a)

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

candidate = []
for i in range(min(x), max(x)+1):
    result = 0
    for person in x:
        result += (person-i)**2
    candidate.append(result)

print(min(candidate))

Solution (Python):
import sys
import math
import itertools as it
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n = i()
x = intl()
m = []
s = 0
for i in range(-max(x),max(x)+1):
    for j in range(n):
        s += (x[j]-i)**2
    m.append(s)
    s = 0
print(min(m))

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

Solution (Python):
import math

n = int(input())
arr = sorted([int(_) for _ in input().split()])
MAX = max(arr)
MIN = min(arr)
val = 99999999999999

for i in range(MIN, MAX+1):
  for j in range(len(arr)-n+1):
    if val > sum([math.pow(i-_, 2) for _ in arr[j:j+n]]):
      val = sum([math.pow(i-_, 2) for _ in arr[j:j+n]])
print(int(val))

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

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

X=list(map(int,input().split()))
P=[]
for p in range(max(X)+1):
    a=0
    for x in X:
        a+=(p-x)**2

    P.append(a)

print(min(P))

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

ave = sum(A) // N
ave2 = sum(A) // N + 1

total = [0,0]

for i in range(N):
  total[0] += abs(A[i] - ave) ** 2
  total[1] += abs(A[i] - ave2) ** 2
  
print(min(total))

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

avex = round(sum(x)/n)

ans = 0
for i in x:
    ans += (i - avex)**2

print(ans)

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

x_sum = 0
for i in range(a):
  x_sum += b[i]

p = round(x_sum / a)


h = 0
for i in range(a):
  h += (b[i]-p)**2
  
print(h)

Solution (Python):
import numpy as np

def main():
    N = int(input())
    X = list(map(int, input().split()))
    X = np.array(X)
    m = int(np.mean(X))
    n = m + 1

    print(min(np.sum((X - m) ** 2), np.sum((X - n) ** 2)))




    return 0


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N=int(input())
X=np.array(input().split(),dtype=np.int32)

ave_point=np.average(X)

can_point=[int(ave_point),int(ave_point)+1]

s1=0
s2=0
for i in range(N):
    s1+=pow((X[i]-can_point[0]),2)
    s2+=pow((X[i]-can_point[1]),2)

if(s1>s2):
    print(s2)
else:
    print(s1)

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

powers = []
for i in range(min(points), max(points) + 1):
    power = 0
    for point in points:
        power += ((i - point) ** 2)
    powers.append(power)

print(min(powers))

Solution (Python):
import numpy as np

n = int(input())
l = np.array(list(map(int, input().split())))

print(int(sum((l - round(l.mean())) ** 2)))

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

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

def calc(p):
    global x
    ans = 0
    for xx in x:
        ans += (xx - p) * (xx - p)
    return ans

answers = []
for i in range(1, 100):
    answers.append(calc(i))

print(min(answers))

Solution (Python):

import statistics
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

n = int(input())
x_list = list(map(int, input().split(' ')))

mean = statistics.mean(x_list)
mean = Decimal(str(mean)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
result = 0


for x in x_list:
  result += (x - mean)**2
  
print(result)

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

Solution (Python):
N = int(input())
Xs = list(map(int, input().split()))
max_dis = 10**18
for i in range(max(Xs)+1):
  sum_dis = sum([(x-i)**2 for x in Xs])
  if sum_dis<max_dis:
    max_dis = sum_dis
print(max_dis)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
a = min(x) + (max(x) - min(x)) // 2
s = 1000000000000
for a in range(min(x), max(x)+1):
    s = min(s, sum(map(lambda x: (x - a) ** 2, x)))
print(s)

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

a = [None]*100
for i in range(1, 101):
    a[i-1] = sum((xi-i)**2 for xi in x)

print(min(a))

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

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

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

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

del x[n:]



now = float('inf')
new = 0

for i in range(100):
  new = 0
  for j in range(len(x)):
    new += (x[j] - (i + 1))** 2
  if new < now:
    now = new

print(now)

Solution (Python):
import numpy as np
import collections
from sys import stdin


def get_result(data):
    N, X = data[0][0], data[1:][0]
    X = np.array(X)
    max_X = max(X)
    tmp = np.zeros(max_X + 1)
    for i in range(max_X + 1):
        tmp[i] = np.sum((X - i) ** 2)
    return int(min(tmp))

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Solution (Python):
from statistics import mean
import math
n = int(input())
citizen = list(map(int,input().split()))
hostF = math.floor(mean(citizen))
hostC = math.ceil(mean(citizen))
ansF = 0
ansC = 0
for i in citizen:
    ansF += (hostF-i)**2
    ansC += (hostC-i)**2
ans = ansF if ansF<ansC else ansC
print(int(ans))

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

def main(N, lst_X):
    
    min_P1 = sum(lst_X) // N
    sum_sutamina1 = 0
    for X in lst_X:
        sum_sutamina1 += (X - min_P1) ** 2

    min_P2 = min_P1 + 1
    sum_sutamina2 = 0
    for X in lst_X:
        sum_sutamina2 += (X - min_P2) ** 2

    return min(sum_sutamina1, sum_sutamina2)
        
if __name__ == "__main__":

    answer = main(N, lst_X)
    print(answer)

Solution (Python):
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
a = int(np.mean(X))
sum1 = 0
sum2 = 0
for x in X:
    sum1 += (x - a) * (x - a)
    sum2 += (x - (a + 1)) * (x - (a + 1))
if sum1 < sum2:
    print(sum1)
else:
    print(sum2)

Solution (Python):
import numpy as np
n = int(input())
xs = list(map(int, input().split()))
xs = np.array(xs, dtype = np.int64)

res = 10000000000
for pi in range(100):
    re = xs - pi
    re = np.power(re, 2)
    re = np.sum(re)
    res = min(re, res)
print(res)

Solution (Python):
from statistics import mean

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

p = round(mean(x_list))

total = 0
for i in x_list:
  strength = (i-p)**2
  total += strength
  
print(total)

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

a = sum(x)//n

y,z = 0,0
for i in range(n):
    y += (a-x[i])**2
    z += ((a+1)-x[i])**2
print(min(y,z))

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

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

p_1 = sum(x) // n
p_2 = p_1 + 1

ans_1 = 0
ans_2 = 0

for x_i in x:
  ans_1 += (x_i - p_1) ** 2
  ans_2 += (x_i - p_2) ** 2

print(min(ans_1, ans_2))

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

Solution (Python):
size = int(input())
positions = [int(pos_str) for pos_str in input().split(' ')]

opt_pos = round(sum(positions) / size)

power_sum = 0
for pos in positions:
  power_sum += (opt_pos - pos) ** 2

print(power_sum)

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

point1 = round(sum(people)/len(people) + 0.5)
point2 = point1 - 1
point3 = point1 + 1
cost1 = 0
cost2 = 0
cost3 = 0

for person in people:
    cost1 += (person - point1)**2
for person in people:
    cost2 += (person - point2)**2
for person in people:
    cost3 += (person - point3)**2
tmp = [cost1, cost2, cost3]
print(min(tmp))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
G = round(sum(A)/N)
HP = 0

for i in range(N):
	HP+=(A[i]-G)**2

print(HP)

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

Solution (Python):
import sys

n = int(input())
xs = list(map(int, sys.stdin.readline().split()))
center = round(sum(xs) / n)
distances = [(center - x)**2 for x in xs]
ans = sum(distances)
print(ans)

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

Solution (Python):
N = int(input())
zahyo = list(map(int, input().split()))
av= sum(zahyo) // len(zahyo)
av2 = sum(zahyo) / len(zahyo)

if av2 - av >= 0.5:
    av += 1

sumv = 0
for i in range(N):
    sumv += (zahyo[i] - av)**2
    
print(sumv)

Solution (Python):
import numpy as np
N = int(input())
X = list(map(int, input().split()))
P = np.round(np.mean(X))
print(int(sum([(x - P)**2 for x in X])))

Solution (Python):
import math
n=int(input())
a=list(map(int,input().split()))
t=sum(a)/n
s=0
p=0
if t==int(t):
    for i in range(n):
        s += int(math.pow(t - a[i], 2))
    print(s)
else:
    for i in range(n):
        s += int(math.pow(int(t) - a[i], 2))
        p+= int(math.pow(int(t)+1 - a[i], 2))

    print(min(p,s))

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

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

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

dp = {}

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

print(min(dp.values()))

Solution (Python):
import sys

n = int(input())
xs = list(map(int, sys.stdin.readline().split()))
center = round(sum(xs) / n)
distances = [(center - x)**2 for x in xs]
ans = sum(distances)
print(ans)

Solution (Python):
import numpy as np

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

x = 10 ** 10
for p in range(1, 101):
    tmp = sum((X_array - p) ** 2)
    x = min(x, tmp)

print(x)

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

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

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

anc = float('inf')
tmp = 0
for p in range(min(c),max(c)+1):
    for i in c:
        tmp += (i-p)**2
    if tmp < anc:
        anc = tmp
    tmp = 0
print(anc)

Solution (Python):

import math

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

power = []

point = sum(A) / len(A)
avg = round(point)

for i in range(N):
    power.append((A[i] - avg) ** 2)

print(sum(power))

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

ans = 10**8
for p in range(1, 150):
    w = 0
    for i in range(n):
        w += (x[i] - p)**2

    ans = min(w, ans)
print(ans)

Solution (Python):
n=int(input())
L=sorted(list(map(int,input().split())))
ans=10**10 if n!=1 else 0
for P in range(L[0],L[-1]+1):
    temp=0
    for l in L:
        temp+=(l-P)**2
    ans=min(temp,ans)
print(ans)

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

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

pos = round(np.mean(x_list))
ans = sum([(x-pos)**2 for x in x_list])
print(int(ans))

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

s = 10000000000
for p in range(max(x)+1):
    sss = 0
    for i in range(n):
        a = (x[i]-p)**2
        sss += a
    if sss < s:
        s = sss
print(s)

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

ver=int(sum(X)/len(X)+0.5)


sumsum=0
for i in X:
    sumsum+=(i-ver)**2

print(sumsum)

Solution (Python):

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

result=100000000
p = 0

for i in range(1,101):
    tmp_r = 0
    for xj in x:
        tmp_r += (i-xj)*(i-xj)
    if tmp_r < result:
        result = tmp_r
        p = i

print(result)

Solution (Python):




n = int(input())
x = list(map(int,input().split()))
xl = [0] * 101


for p in range(101):
    for j in range(n):
        xl[p] = xl[p] + (x[j] - p) ** 2


print(min(xl))

Solution (Python):
def val(X, point):
    ans = 0
    for v in X:
        ans += (v - point) ** 2
    return ans


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

point = sum(X) // len(X)
first = val(X, point)
second = val(X, point + 1)
print(min(first, second))

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

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

minimum = min(X)
maximum = max(X)

def shohi(zahyo, shukai):
  return pow(zahyo - shukai, 2)

saisho = None
for i in range(minimum, maximum + 1):
  ret = sum(map(lambda zahyo: shohi(zahyo, i), X))
  saisho = ret if saisho is None or ret < saisho else saisho

print(saisho)

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

pow = []

for p in range(min(x), max(x)+1):
    sum = 0
    for i in range(n):
        sum += (x[i] - p) ** 2
    pow.append(sum)

print(min(pow))

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ave=0
for i in range(n):
  ave+=x[i]
ave//=n
ave2=ave+1
ans1=0
ans2=0
for i in range(n):
  ans1+=(x[i]-ave)**2
  ans2+=(x[i]-ave2)**2
print(min(ans1,ans2))

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
x.sort()
min_d = 10**18
if x[0] != x[n-1]:
    for p in range(x[0],x[n-1]):
        sm = 0
        for j in range(n):
            sm += (x[j] - p)**2
        else:
            min_d = min(min_d,sm)
    print(min_d)
else:
    print(0)

Solution (Python):
n = int(input())
arr = [int(s) for s in input().split(" ")]

def calculate(n,arr):
    arr = sorted(arr)
    data = []
    for i in range(1,101):
        sum = 0
        for ar in arr:
            sum += (ar - i) ** 2

        data.append(sum)

    return min(data)


result = calculate(n,arr)

print(result)

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    X = list(map(int, input().split()))

    min_ = min(X)
    max_ = max(X)
    ans = float('inf')
    for p in range(min_, max_ + 1):
        n = 0
        for xi in X:
            n += (xi - p) ** 2
        ans = min(ans, n)
    print(ans)


main()

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

dp = [0] * 100

for p in range(100):
    for x in X:        
        dp[p] += (x - p) ** 2

print(min(dp))

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

nlist = map(int,input().split())

llist = list(nlist)

resu = float('INF')

def stamina_req(coordinate):
    res = 0
    for nl in llist:
        res += abs(nl - coordinate)**2
    return res



for j in range(1, 101):
    resu = min(resu, stamina_req(j))

print(resu)

Solution (Python):
import functools
n = input()

x = [int(x) for x in input().split()]
ans = functools.reduce(lambda a,b: a +(b-0)**2, x, 0)
for i in range(min(x),max(x)+1):
    t = functools.reduce(lambda a,b: a +(b-i)**2, x, 0)
    ans  = min(ans, t)
print(ans)

Solution (Python):



import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    X = i2nn()
    ave = round(sum(X) / N)
    print(sum(map(lambda x: (x - ave)**2, X)))
    return

main()

Solution (Python):
num_of_points = int(input())
points = [int(x) for x in input().split(" ")]

average = round(sum(points) / num_of_points)

sum = 0

for point in points:
    sum += (point - average)**2

print(sum)

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


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

x2 = [i ** 2 for i in x]
ans = float('inf')
sum1 = sum(x)
sum2 = sum(x2)
for p in range(1, 101):
    cnt = sum2 + (sum(x) * (-1) * 2 * p) + (p**2*n)
    ans = min(ans, cnt)
print(ans)

Solution (Python):
import numpy as np

n = int(input())
x = np.array([int(x) for x in input().split()])

ans = 10 ** 10
for i in range(1, 101):
    temp = x - i
    ans = min(ans, sum([j ** 2 for j in temp]))

print(ans)

Solution (Python):
import numpy as np

N = int(input())
X = list(map(int, input().split()))
m = round(np.mean(X))
result = 0
for x in X:
    result += (x-m)**2
print(int(result))