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



Sample input:
2
1 4


Sample output:
5

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
k = []
for j in range(min(l), max(l)):
  ans=0
  for i in range(len(l)):
    x = (l[i] - j)**2
    ans += x
  k.append(ans)
print(min(k))

Submission status: Runtime Error

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

X = sorted(X)
X_undupe = list(set(X))
stamina = []
for i in range(X_undupe[0], X_undupe[len(X_undupe)-1] + 1):
    s = 0
    for ii in X:
        s = s + ((ii - i) ** 2)
    stamina.append(s)

print(min(stamina))

Submission status: Runtime Error

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

X = sorted(X)
X_undupe = list(set(X))
stamina = []
for i in range(X_undupe[0], X_undupe[len(X_undupe)-1] + 1):
    s = 0
    for ii in X:
        s = s + ((ii - i) * (ii - i))
    stamina.append(s)

print(min(stamina))

Submission status: Runtime Error

Solution code:
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp) + 1
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Submission status: Runtime Error

Solution code:
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp)
p = int(p)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Submission status: Runtime Error

Solution code:
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Submission status: Runtime Error

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

min_a = X[0]
max_a = X[-1]
mid = (min + max) // 2

sum_min = 0
sum_max = 0
    
def calc(x, min, max):
    mid = (min + max) // 2
    sum_min = 0
    sum_max = 0
    for value in x:
        sum_min += (value - min) ** 2
        sum_max += (value - max) ** 2
    
    if abs(min - max) <= 1:
        if sum_min < sum_max:
            return int(sum_min)
        else:
            return int(sum_max)
    elif sum_min < sum_max:
        return calc(x, min, mid)
    else:
        return calc(x, mid, max)
    
    return -1
    
ans = calc(X, min_a, max_a)
print(ans)

Submission status: Runtime Error

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

# process/output
L = min(X)
R = max(X)

ans = int(float('inf'))
for i in range(L, R+1):
    cost = 0
    for x in X:
        cost += (x-i)**2
    
    if cost < ans:
        ans = cost

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input(),split()))

s=min(l)
g=max(l)
ans=0
for k in range (n):
  ans+=(l[k]-s)**2

for i in range(s+1,g+1):
  hyp=0
  for j in range (n):
    hyp+=(l[j]-i)**2
  if hyp<ans:
    ans=hyp
    
print (ans)

Submission status: Runtime Error

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

#iが座標の位置

list_ans = []

for i in range(min(list_x), max(list_x)):
    
    #計算する
    ans = 0
    for j in list_x:
        ans += (i-j)**2

    list_ans.append(ans)

print(min(list_ans))

Submission status: Runtime Error

Solution code:
n = int(input())
X = list(map(int, input().split()))
low = min(X)
high = max(X)
ans = []

for p in range(low, high-low+1):
  dist = 0
  for x in X:
    dist += (x-p)**2
  ans.append(dist)
print(min(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(input()) for _ in range(n)]
ans = list()
for p in x:
  v_sum = 0
  for i in x:
    v_sum += (p - i)**2
  ans.append(v_sum)
print(ans.min())

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(input()) for _ in range(n)]
ans = list()
for p in x:
  v_sum = 0
  for i in x:
    v_sum += (p - i)**2
  	ans.append(v_sum)
print(min(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(input()) for _ in range(n)]
ans = list()
for p in x:
  v_sum = 0
  for i in x:
    v_sum += (p - x)**2
  	ans.append(v_sum)
print(min(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(input()) for _ in range(n)]
ans = list()
for p in x:
  v_sum = 0
  for i in x:
    v_sum += (p - x)**2
  	ans.append(v_sum)
print(ans.min())

Submission status: Runtime Error

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

ans=10**10
for i in range(N):
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = [a for a in map(int,input().split())]
K = max(L)
Power = []
for i in range(1,K):
  add = 0
  for j in range(len(L)):
    add+= (i - L[j])**2
  Power.append(add)
print(min(Power))

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(map(int,input().split()))
memo=[]
for i in range(min(S),max(S)):
    summ = 0
    for j in range(0,N):#実際にsumを求める
        summ+=(i-S[j])**2
    memo.append(summ)

print(min(memo))

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(map(int,input().split()))
memo=[]
for i in range(S[0],S[N-1]):
    summ = 0
    for j in range(0,N):#実際にsumを求める
        summ+=(i-S[j])**2
    memo.append(summ)

print(min(memo))

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(map(int,input().split()))
print(S)
memo=[]
for i in range(S[0],S[N-1]):
    summ = 0
    for j in range(0,N):#実際にsumを求める
        summ+=(i-S[j])**2
    memo.append(summ)

print(min(memo))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / N)
p = 0
for i in x:
    p += ((i-t)**2)
print(p)

Submission status: Runtime Error

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

ans = 100000000
for p in range(x[1],x[-1]+1):
  sum =0
  for i in range(n):
    sum += (x[i]-p)**2
    
  ans = min(ans,sum)
  
print(ans)

Submission status: Runtime Error

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

ans = 10000
for p in range(x[1],x[-1]+1):
  sum =0
  for i in range(n):
    sum += (x[i]-p)**2
    
  ans = min(ans,sum)
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

ans = float('inf')

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

Submission status: Runtime Error

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

for p in range(min(X), max(X)):
    sum_HP = 0
    for i in range(N):
        sum_HP += (X[i] - p) ** 2
    N_sum_HP.append(sum_HP)

print(min(N_sum_HP))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(n):
    HP = 0
    for j in range(100):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(n):
    HP = 0
    for j in range(max(a)):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)

Submission status: Runtime Error

Solution code:
n = int(input())
x = []
sum = 0
for i in range(n):
  s = int(input())
  sum += s
  x.append(s)
  
ave = s//n
sum = 0
for i in range(n):
  sum += (x[i] - ave)**2
min = sum
sum = 0
for i in range(n):
  sum += (x[i] - ave - 1)**2
max = sum 

if min > max:
  print(max)
else:
  print(min)

Submission status: Runtime Error

Solution code:
    N=int(input())
     
    X=list(map(int, input().split()))
     
    X.sort()
    i=X[0]
    min=10000000000
    while i <= X[-1]:
        power=0
        for j in range(len(X)):
            power=power+(X[j]-i)**2
     
        if power<=min:
            min=power
     
        i=i+1
     
     
    print(min)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

N = int(input())
x = list(map(int,input().split()))
A2 = max(x); A1 = min(x)
k = 0; Solve = np.zeros(A2-A1);
for A in range(A1,A2):
  B=0
  for i in range(0,N):
    B = (x[i]-A)**2 + B
  Solve[k] = B
  k += 1
print(int(min(Solve)))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

N = int(input())
x = list(map(int,input().split()))
A2 = max(x); A1 = min(x)
k = 0; Solve = np.zeros(A2-A1);
for A in range(A1,A2):
  B=0
  for i in range(0,N):
    B = (x[i]-A)**2 + B
  Solve[k] = B
  k += 1
print(min(Solve))

Submission status: Runtime Error

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

minX = min(X)
maxX = max(X)
li = []
for i in range(minX, maxX):
    temp = 0
    for j in range(N):
        temp += (X[j] - i)**2
    li.append(temp)

print(min(li))

Submission status: Runtime Error

Solution code:
N = int(input())

X_law_input = input().split()
X_list = []
for prefix in range(len(X_law_input)):
    X_list.append(int(X_law_input[prefix]))

tairyoku_list = []

for n in range(abs(max(X_list) - min(X_list))):
    current_shuukai_zahyou = n + min(X_list)
    current_tairyoku = 0
    for a in range(len(X_list)):
        sonohitono_tairyoku = abs (X_list[a] - current_shuukai_zahyou)
        current_tairyoku = current_tairyoku + (sonohitono_tairyoku * sonohitono_tairyoku)
    tairyoku_list.append(current_tairyoku)

print(min(tairyoku_list))

Submission status: Runtime Error

Solution code:
N = int(input())

X_law_input = input().split()
X_list = []
for prefix in range(len(X_law_input)):
    X_list.append(int(X_law_input[prefix]))

tairyoku_list = []

for n in range(abs(max(X_list) - min(X_list))):
    current_shuukai_zahyou = n + min(X_list)
    current_tairyoku = 0
    for a in range(len(X_list)):
        sonohitono_tairyoku = X_list[a] - current_shuukai_zahyou
        current_tairyoku = current_tairyoku + (sonohitono_tairyoku * sonohitono_tairyoku)
    tairyoku_list.append(current_tairyoku)

print(min(tairyoku_list))

Submission status: Runtime Error

Solution code:
N = int(input())
X_list = list(map(lambda x: int(x), input().split()))

tairyoku_list = []

for n in range(max(X_list) - min(X_list)):
    current_shuukai_zahyou = n + min(X_list)
    current_tairyoku = 0
    for a in range(len(X_list)):
        current_tairyoku = current_tairyoku + (X_list[a] - current_shuukai_zahyou)**2
    tairyoku_list.append(current_tairyoku)

print(min(tairyoku_list))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import sympy

def cal_result(result_param,info_list):
    result = 0
    for num in info_list:
        num = int(num)
        result = result + (num-result_param)**2
    return result
    

def min_answear(info):
    param = sympy.Symbol('param')
    formula = sympy.Symbol('formula')
    
    formula = 0
    for num in info:
        num = int(num)
        calculate = sympy.Symbol('calculate')
        calculate = (num - param)**2
        formula = formula + calculate
        
    result_form = sympy.diff(formula , param)
    result = sympy.solve(result_form)
    result = str(result[0])
    result = result.split("/")
    result = int(result[0])/int(result[1])
    
    if result.is_integer():
        result = int(result)
        answear = cal_result(result,info)
    else:
        result1 = int(result)
        sub_answear1 = cal_result(result1,info)
        result2 = int(result) + 1
        sub_answear2 = cal_result(result2,info)
        if sub_answear1 <= sub_answear2:
            answear = sub_answear1
        else:
            answear = sub_answear2
    
    print(answear)
    
def main():
    join_num = int(input())
    
    join_info = input()
    join_info = join_info.split()
    min_answear(join_info)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
l = np.array(map(int, input().split()))

ans = np.sum((l - round(np.mean(l)))**2)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
ans = 100100100
for i in range(1,101) :
    s = 0
    for o in x :
        s+=(i-x)*(i-x)
    ans = min(ans,s)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().strip().split()))
total = 0
points = 0 
for i in X:
  total += i
avg = int(round(total/N))
for i in X:
  points += (a-avg)^^2
print(points)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
Xi = list(map(int, input().split(" ")))

Xi_min = min(Xi)
Xi_max = max(Xi)

ans = math.inf
print("-----")
for i in range(Xi_min, Xi_max+1):
    tmp = 0
    for j in range(N):
        tmp += pow(Xi[j] - i, 2)
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = iter(input, "")
    n = int(cin[0].split(" ")[0])
    xs = np.array(cin[1].split(" ")).astype("int")
    cout = main(n, xs)
    print(cout)

Submission status: Runtime Error

Solution code:
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = list(iter(input, ""))
    n = int(cin[0].split(" ")[0])
    xs = np.array(cin[1].split(" "))
    xs = xs.astype("int")
    cout = main(n, xs)
    print(cout)

Submission status: Runtime Error

Solution code:
N=int(input())
List=[int(i) for i in input().split()]
P=int(round(sum(List)/N,0))
def length(x):
 return sum([(i-P-x)**2 for i in List])
i=0
data=length(0)
while True:
 if(length(i-1)<length(i)<length(i+1)):
  i-=1
 elif(length(i-1)>length(i)>length(i+1)):
  i+=1
 else:
  print((length(i))
  break

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
Min,Max = min(x),max(x)
s = [0] * (Max - Min)
k = 0

for i in range(Min,Max):
    for j in x:
        s[k] += (j - i) ** 2
    k += 1
print(min(s))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
m_energy = 250000
for i range(0,101):
  m_energy = 0
  for k range(n):
    m_energy += (x[k]-1)**2
  if energy < m_energy:
    m_energy = energy
print(minenergy)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
min_energy = 250000
for i range(0,101):
  energy = 0
  for k range(n):
    energy += (x[k]-1)**2
  if energy < min_energy:
    min_energy = energy
print(min_energy)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
min_energy = 250000
for i range(100):
  energy = 0
  for k range(n):
    cons = (i+1-x[k])*(i+1-x[k])
    energy += cons
  if energy < min_energy:
    min_energy = energy
print(min_energy)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
min_energy = 250000
for i range(100):
  energy = 0
  for k range(n):
    energy += (i+1-x[k])*(i+1-x[k])
  if energy < min_energy:
    min_energy = energy
print(min_energy)

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
min_energy = 250000
for i range(100):
  energy = 0
  for k range(n):
    energy += (i+1-p[k])(i+1-p[k])
  if energy < min_energy:
    min_energy = energy
print(min_energy)

Submission status: Runtime Error

Solution code:
import math


def point_stamina(p):
    stamina = 0
    for x in persons_coordinates:
        stamina += (x - p) ** 2
    return stamina


n = int(input())
persons_coordinates = list(map(int, input().split()))
max_coordinate = max(persons_coordinates)
min_coordinate = min(persons_coordinates)
min_stamina = math.inf

for p in range(min_coordinate, max_coordinate + 1):
    stamina = point_stamina(p)
    if min_stamina >= stamina:
        min_stamina = stamina

print(min_stamina)

Submission status: Runtime Error

Solution code:
import math


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


n = int(input())
persons_coordinates = list(map(int, input().split()))
max_coordinate = max(persons_coordinates)
min_stamina = math.inf


for p in range(max_coordinate + 1):
    stamina = 0
    for x in persons_coordinates:
        stamina += get_stamina(x, p)
    
    if min_stamina >= stamina:
        min_stamina = stamina
print(min_stamina)

Submission status: Runtime Error

Solution code:
number, base = map(int, input().split())
devision = number
list = []
while(devision>=base):
    surplus = devision % base
    devision = int(devision / base)
    #print(devision, surplus)
    list.insert(0,surplus)
    #print(list)
list += [devision]
#print(list)
print(len(list))

Submission status: Runtime Error

Solution code:
number = input()
coordinates = list(map(int, input().split()))
coordinates.sort()
coordinates.reverse()
#print(coordinates)
list = []
for i in range(coordinates[0]):
    total=0
    for j in range(number):
        total += (coordinates[j]-i)**2
    list.insert(0, total)
list.sort()
print(list[0])

Submission status: Runtime Error

Solution code:
N=int(input())
X=list(map(int,input().split()))
dispersion=[]
cnt=0
for i in range(min(X),max(X)):
    for j in range(N):
        cnt+=abs(X[j]-i)**2
    dispersion.append(cnt)
    cnt=0
print(min(dispersion))

Submission status: Runtime Error

Solution code:
def rally():
    N=int(input())
    X=list(map(int,input().split()))
    dispersion=[]
    cnt=0
    for i in range(min(X),max(X)):
        for j in range(N):
            cnt+=abs(X[j]-i)**2
        dispersion.append(cnt)
        cnt=0
    print(min(dispersion))
    return 0
rally()

Submission status: Runtime Error

Solution code:
def rally():
    N=int(input())
    X=list(map(int,input().split()))
    dispersion=[]
    cnt=0
    for i in range(min(X),max(X)):
        for j in range(N):
            cnt+=abs(X[j]-i)**2
        dispersion.append(cnt)
        cnt=0
    print(min(dispersion))

rally()

Submission status: Runtime Error

Solution code:
def rally():
    N=input()
    X=list(map(int,input().split()))
    dispersion=[]
    cnt=0
    for i in range(min(X),max(X)):
        for j in X:
            cnt+=abs(j-i)**2
        dispersion.append(cnt)
        cnt=0
    print(min(dispersion))

rally()

Submission status: Runtime Error

Solution code:
def rally():
    N=input()
    X=list(map(int,input().split()))
    dispersion=[]
    cnt=0
    for i in range(min(X),max(X)):
        for j in X:
            cnt+=(j-i)**2
        dispersion.append(cnt)
        cnt=0
    print(min(dispersion))

rally()

Submission status: Runtime Error

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

for i in range(100):
   	cnt = 0
	for j in range(n):
   		cnt = cnt + (x[j]-i)**2
    	p.append(cnt)

print(sorted(p)[0])

Submission status: Runtime Error

Solution code:
N = int(input())
Xs = input()
Xlist = Xs.split(' ')
anslist = []
for P in range(int(Xlist[0]),int(Xlist[N - 1])+1):
    ans = 0
    for i in range(len(Xlist)):
        ans = ans + (int(Xlist[i]) - P)**2
    anslist.append(ans)
print(min(anslist))

Submission status: Runtime Error

Solution code:
n = int(input())
xs = [int(elem) for elem in input().split()]

min_ = min(xs)
max_ = max(xs)
result = []
for p in range(min_, max_):
  res = 0
  for x in xs:
    res += (x - p) ** 2
  result.append(res)
print(min(result))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
x = list(map(int, input().split()))
 
n = len(x)

sum_a = 0
sum_b = 0

for xi in x:
  sum_a += xi * xi
  sum_b += xi
  
ans = sum_a - (sum_b*sum_b)/n
min_ans = 10**9
if ans < min_ans
    ans = min_ans

print(int(ans+0.5))

Submission status: Runtime Error

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

n = len(X)

for xi in x:
  sum_a += xi * xi
  sum_b += xi
  
ans = sum_a - (sum_b*sum_b)/n
print(ans)

Submission status: Runtime Error

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

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(a-i)*(a-i)
  ans=min(ans,d)
print(ans)

Submission status: Runtime Error

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

ans=99999999
for i in range(1,101):
  d=0
  for x in a:
    d+=(a-i)*(a-i)
  ans=min(ans,d)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math


N = int(input())
Xi = list(map(int, input().split()))
Xi.sort()
min = Xi[0]
max = Xi[N-1]
tmp = 0
result = math.inf
for i in range(min,max+1):
    for j in range(0,N):
        tmp += (Xi[j] - i)**2
    if tmp <= result:
        result = tmp
    tmp = 0

print(result)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

if __name__=='__main__':
    N = int(input())
    Xi = list(map(int, input().split()))
    Xi.sort()
    min = Xi[0]
    max = Xi[N-1]
    tmp = 0
    result = math.inf
    for i in range(min,max+1):
        for j in range(0,N):
            tmp += (Xi[j] - i)**2
        if tmp <= result:
            result = tmp
        tmp = 0

    print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
A = min(L)
Z_L = list()
for i in range(A, M):
  ZZ = 0
  for j in range(N):
    Z =  pow(L[j] - i, 2)
    ZZ += Z
  Z_L.append(ZZ)
print(min(Z_L))

Submission status: Runtime Error

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
Z_L = list()
for i in range(1, M):
  ZZ = 0
  for j in range(N):
    Z =  pow(L[j] - i, 2)
    ZZ += Z
  Z_L.append(ZZ)
print(min(Z_L))

Submission status: Runtime Error

Solution code:
5 5 17 6 37 17 18

25 25 289 36 1369 289 324def rally(n , xl):

    ans = 0

    aaa = round(sum(xl) / n)

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

    return ans

def main():
    n = int(input())
    xl = list(map(int , input().split()))
    print(rally(n , xl))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int,input()
X=list(map(int,input().split()))
def P(n):
    return sum([(X[i]-n)**2 for i in range(0,N)])
l=[P(i) for i in range(1,101)]
print(min(l))

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum = 0
for x in X:
  sum = sum +(x-P)**2
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [map(int,input().split())]
b = 0
ans = 0
for i in range(n):
  b = (int(a[i])-n)**2
  ans += b
print(b)

Submission status: Runtime Error

Solution code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1
def count(p):
    d = 0
    for n in nums:
        d += (n-p)**2
    return d
print(min(count(a1), count(a2)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
X = map(int, raw_input().split())

P = 0
for i in N:
  P += X[i]/N

sum=0
for i in N:
  sum += (X[i]-P)**2
 
print(sum)

Submission status: Runtime Error

Solution code:
n=int(input())
X=list(map(int,input().split()))
ans=float('inf')
for i in range(min(x),max(x)):
  now=0
  for x in X:
    now+=(i-x)*(i-x)
  ans=min(now,ans)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
x=[int(i) for i in input().split()]
a=[]
p=0
for i in range(1,n**n):
  for j in range(n):
    p+=(x[j]-i)**2
  a.append(p)
  p=0
print(min(a))

Submission status: Runtime Error

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

s = 0
for xi in X:
    s += xi
si = round(s / N)
ps = 0
for xi in X:
    ps += int(math.pow(xi-si, 2))
print(ps)

Submission status: Runtime Error

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

m = sum(x) / n
mp = float(m/1)

p = 0

if (m - mp) < 0.5:
  p = int(mp)

else:
  p = int(mp + 1)

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

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int,input().split()))
S = []
for p in range(min(X), max(X)):
    t = [(i - p) ** 2 for i in X]
    S.append(sum(t))
print(min(S))

Submission status: Runtime Error

Solution code:
import sys
Row=int(input())
 

X = map(int, input().strip())
 
res = float('inf')
for i in range(1, 101):
  cur_res = 0
  for j in X:
    cur_res = cur_res + (j-i)^2
  if cur_res < res:
    res = cur_res
 
print(res)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()
 
N, X = lines.strip("\n")
X = map(int, X.strip())
 
res = float('inf')
for i in range(1, 101):
  cur_res = 0
  for j in X:
    cur_res = cur_res + (j-i)^2
  if cur_res < res:
    res = cur_res
 
print(res)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()
 
N, X = lines.strip("\n")
X = map(int, X.strip(" "))
 
res = float('inf')
for i in range(1, 101):
  cur_res = 0
  for j in X:
    cur_res = cur_res + (j-i)^2
  if cur_res < res:
    res = cur_res
 
print(res)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()
 
N, X = lines.strip("\n")
X = map(int, X.strip(" "))
 
res = float('inf')
for i in Range(1, 101):
  cur_res = 0
  for j in X:
    cur_res = cur_res + (j-i)^2
  if cur_res < res:
    res = cur_res
 
print(cur_res)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

N, X = lines.strip("\n")
X = X.strip(" ")

res = float('inf')
for i in Range(1, 101):
  cur_res = 0
  for j in X:
    cur_res = cur_res + (j-i)^2
  if cur_res < res:
    res = cur_res

print(cur_res)

Submission status: Runtime Error

Solution code:
N = input()
List = [input().split()]


ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (p-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)

Submission status: Runtime Error

Solution code:
N = input()
List = list(map(int,input().split())

N = 7
List = [14,14,2,13,56,2,37]

ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (p-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)

Submission status: Runtime Error

Solution code:
N = input()
List = [int(i) for i in input().split()]



ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (p-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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

a = round((sum(X) / N), 3)
integer = int(a)
f = a - i

if f < 0.5:
    P = integer
else:
    P = integer + 1

total = 0
for i in X:
    total += (i - P) ** 2

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())

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

a = sum(X) / N
integer = int(a)
f = a - i

if f < 0.5:
    P = integer
else:
    P = integer + 1

total = 0
for i in X:
    total += (i - P) ** 2

print(total)

Submission status: Runtime Error

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

ave=int(sum(list)/len()list)

ans=0
for i in list:
  ans+= pow((i-ave),2)

print(ans)

Submission status: Runtime Error

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

ave=int(sum(list)/len()list)

ans=0
[ans+= pow((i-ave),2) for i in list]

print(ans)

Submission status: Runtime Error

Solution code:
import math
n=input()
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=math.inf
for p in range(a,b+1):
    m=0
    for x in Xs:
        m+=(x-p)**2
    if m<ans:
        ans=m
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=inf
for p in range(a,b+1):
    m=0
    for x in Xs:
        m+=(x-p)**2
    if m<ans:
        ans=m
print(ans)

Submission status: Runtime Error

Solution code:
N = input()
for i in N:
	A = [int(i) for i in input().split()]
P=round(sum(A)/N)
B=0
for i in N:
	B=B+(A[i]-P)**2
print(B)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
count=0
max=0
min=0
sum=0

for i in range(n):
  count+=x[i]
  if max<x[i]:
    max=x[i]
  elif min>x[i]:
    min=x[i]
  num=max+min

p=round(count/round(num/2))

for i in range(0,n):
  power=(x[i]-p)**2
  sum+=power

print(sum)

Submission status: Runtime Error

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

def sutamina(P, X):
    return (X-P)**2
  
sutamina_min = math.inf
for i in range(100):
    sutamina_souwa = 0
    for k in X:
        sutamina_souwa += sutamina(i, k)
    if sutamina_souwa < sutamina_min:
        sutamina_min = sutamina_souwa

print(sutamina_min)

Submission status: Runtime Error

Solution code:
n = int(n)
seq = [int(x) for x in input().split()]
d = round(sum(seq) / len(seq))
print(sum([(x-d)**2 for x in seq]))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
X = np.array([int(i) for i in input().split()])

ans = []
for i in range(1, max(X)):
    ans.append(sum((X - i)**2))
    
print(min(ans))