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: Wrong Answer

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

    if temp_sum < max_num:
        max_num = temp_sum

print(max_num)

Submission status: Wrong Answer

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

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

print(min)

Submission status: Wrong Answer

Solution code:
import math
from statistics import mean


def main():
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    avg = mean(x)
    result = 0
    for i in x:
        result += (i - avg) ** 2
    print(math.ceil(result))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
#x.sort()
s = 0
ma = 0
mi = 0
for i in range(n):
	s += x[i]
	if ma<x[i]:
		ma = x[i]
	if mi>x[i]:
		mi = x[i]


p = int(s/n)

if s%n != 0:
	p += 1		


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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
X_sum=sum(X)
ans=0
if abs(int(X_sum/N)-X_sum/N)>=abs(int(X_sum/N)+1-X_sum/N):
    P=int(X_sum/N)
else:
    P=int(X_sum/N)+1
for i in range(N):
    ans+=(X[i]-P)**2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
t = 0
for i in a:
    t += i
wp = int(t//n + np.sign(t/n))
ans = 0
for i in a:
    ans += (i -wp) **2
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    mean = np.mean(A)
    x = np.array(A) - mean
    print(int(np.dot(x, x)))

main()

Submission status: Wrong Answer

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

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

ans = 0
for i in list:
  ans += (i-average-1)*(i-average-1)
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for i in list:
  ans += (i-average-1)*(i-average-1)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

i = math.ceil(sum(X) / N)
s_sum = 0
for x in X:
    dd = (x - i) ** 2
    s_sum += dd

print(s_sum)

Submission status: Wrong Answer

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

loss = 0

sum = 0
for X in Xs:
  sum += X
  
ave = sum/len(Xs)

for X in Xs:
  loss += (X-ave)**2

print(round(loss))

Submission status: Wrong Answer

Solution code:
import numpy as np

def resolve():
    input()
    x = list(map(int, input().split()))
    m = round(np.mean(x))
    sum = 0
    for val in x:
        sum += (val - m) ** 2

    print(sum)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m = 100 * 100 * n
sumlist = []

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

    sumlist.append(s)

if sumlist == []:
    print((x[0] - n) ** 2)
else:
    print(min(sumlist))

Submission status: Wrong Answer

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

def num(N,X):
    number = 0
    for x in X:
        num = x-N
        #print(str(num))
        num2 = num**2
        print(str(num2))
        number += num2
        #print(str(number))
    return number
    
kekka = str(num(N,X))
print(kekka)

Submission status: Wrong Answer

Solution code:
import math

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

loss = 0

sum = 0
for X in Xs:
  sum += X
  
ave = sum/len(Xs)

for X in Xs:
  loss += (X-ave)**2

print(math.ceil(loss))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

min = 0
avg = math.ceil(sum(X) / len(X))

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

print(min)

Submission status: Wrong Answer

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

hp_sums = []

for i in range(max(X)):
    P = i+1
    distance_list = list(map(lambda x: (x-P)**2, X))
    print(distance_list)
    hp_sum = sum(distance_list)
    hp_sums.append(hp_sum)

print(min(hp_sums))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
X = sum(A)/N
ans = 0
X = math.ceil(X)
for i in A:
  ans += (i-X)**2
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input())
xlist = list(map(int,input().split()))
xlist.sort()
ans = 10**9+7

st = xlist[0]
ed = xlist[-1]

for p in range(st, ed):
  pp = 0
  for i in range(n):
    pp += (xlist[i] - p) ** 2
  ans = min(ans, pp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = 999999999999999999
for i in range(x[0], x[-1]):
    t = 0
    for q in range(n):
        t += (i - x[q]) ** 2
    else:
        if ans > t:
            ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
line1 = input('')
line2 = input('')
n = int(line1)
xs = line2.split(' ')

min = 0
for p in range(1,101):
  sum = 0
  for x in xs:
    xi = int(x)
    d = (xi - p)*(xi-p)
    sum += d
  if min == 0:
    min = sum
  elif sum < min:
    min = sum

print(min)

Submission status: Wrong Answer

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

l=len(list)
m=0
i=0
j=1
r=0

while(i<l):
  if(m < abs(list[i]-j)):
    m = j
  i+=1
  j+=1

k=0

while(k<l):
  r+=abs(list[k]-m)*abs(list[k]-m)
  k+=1

print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0

x_sum = sum(x_list)

x_sum = x_sum // n
x_sum += 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

print(ans)

Submission status: Wrong Answer

Solution code:
N = 7
X = [14,14,2,13,56,2,7]
sum = 0
for a in X:
    sum = sum + a
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-C)**2
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = []

for i in range(min(x),max(x)+1):#Pは最大から最小までのどこか
    tmp = 0
    for j in x:
        tmp += (i-j)**2
    ans.append(tmp)

print(ans)
print(min(ans))

Submission status: Wrong Answer

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

    #集会の場所
    for p in range(1,a+1):
        #各人の消費体力
        for score in l:
            temp[p-1] = temp[p-1] + (score-p)**2 
    print(min(temp))
            

if __name__ == '__main__' :
    main()

Submission status: Wrong Answer

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

Max = max(X)
p_min = 10000
for i in range(1, 101):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0

x_sum = sum(x_list)

x_sum = x_sum//n + 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
aaa = [i+1 for i, x in enumerate(X) if isinstance(x, int)]

ans = 0
for i in aaa:
  k = []
  for a in X:
    k.append((a-i)**2)
  if i==1:
    ans = sum(k)
  if ans>sum(k):
    ans = sum(k)
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
  num_resident = int(input())
  
  x_list = [int(a) for a in input().split()]
  min_x = min(x_list)
  max_x = max(x_list)
  
  fin_ps = pow(max_x, 2)
  for i in range(min_x, max_x + 1):
    sum_ps = 0
    for x_i in range(num_resident):
      sum_ps += pow((x_list[x_i] - i), 2)
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
X = sum(A)//N
ans = 0
for i in A:
  ans += (i-X)**2
print(math.ceil(ans))

Submission status: Wrong Answer

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

for i in range(max(x)):
    hp = 0
    point = i
    for j in x:
        hp += (j - point) ** 2
        if loss < hp:
            break
    else:
        loss = hp
print(loss)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0

x_sum = sum(x_list) // n + 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

print(ans)

Submission status: Wrong Answer

Solution code:
import math 
N=int(input())
X=list(map(int,input().split()))
s=0
for i in range(N):
  s+=(X[i]-N)**2
  
print(s)

Submission status: Wrong Answer

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

x_ave = sum(x_list) // len(x_list)

diff_sum = 0
for x in x_list:
    diff = abs(x - x_ave)**2
    diff_sum += diff
print(diff_sum)

Submission status: Wrong Answer

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


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(1, 100+1):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
N = int(input())
X = map(int, input().split())
res = 0
for num in X:
  res = res + (num - N)**2

print(res)

Submission status: Wrong Answer

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

h=sum(x)//N+1
s=0

for i in range(0,N):
  s+=(x[i]-h)**2
print(s)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
X = sum(A)/N
ans = 0
for i in A:
  ans += (i-X)**2
print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 100000
for j in range(max(x)):
    cnt = 0
    for i in range(n):
        cnt += (x[i] - (j + 1)) ** 2
    if cnt < ans:
        ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
  num_resident = input()
  x_list = [int(a) for a in input().split()]
  min_x = min(x_list)
  max_x = max(x_list)
  
  fin_ps = pow(max_x, 2)
  for i in range(min_x, max_x + 1):
    sum_ps = 0
    for x in x_list:
      sum_ps += pow((x - i), 2)
    # print("sum: " + str(sum_ps) + " fin: " + str(fin_ps))
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
pivot = (x[0] + x[-1]) // 2
Sum = 0
Min = 99999
for i in range(101):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(input().split(" "))
ans = 0
for i in X:
    i = int(i)
    ans += (i -N)**2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 0
for i in range(1, N+1):
  k = []
  for a in X:
    k.append((a-i)**2)
  if i==1:
    ans = sum(k)
  if ans>sum(k):
    ans = sum(k)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0

x_sum = sum(x_list) //  n + 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

print(ans)

Submission status: Wrong Answer

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

l = min(x)
r = max(x)
ans = 100 ** 3
for i in range(l, r + 1):
    vit = sum(abs(xi - i) ** 2 for xi in x)
    print(i, vit)
    ans = min(ans, vit)
print(ans)

Submission status: Wrong Answer

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


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(1, 100):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Wrong Answer

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

Max = max(X)
p_min = 10000
for i in range(1, Max+1):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)

Submission status: Wrong Answer

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


max_x = max(x)
min_x = min(x)
sum_a = [0]*max_x


for i in range(0,max_x):
    for j in range(0,N):
        sum_a[i] += abs((x[j]-i)**2)

#print(sum_a)
min_dis = min(sum_a)

check = min(sum_a)
ans = sum_a.index(check)
a = 0
for i in range(0,N):
    a += (x[i] - ans)**2

print(a)

Submission status: Wrong Answer

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


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(1, 100):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp
    print(p)

print(ans)

Submission status: Wrong Answer

Solution code:
line1 = input('')
line2 = input('')
n = int(line1)
xs = line2.split(' ')

min = 0
for p in range(1,100):
  sum = 0
  for x in xs:
    xi = int(x)
    d = (xi - p)*(xi-p)
    sum += d
  if min == 0:
    min = sum
  if sum < min:
    min = sum

print(min)

Submission status: Wrong Answer

Solution code:
N=int(input())
K=list(map(int,input().split()))
Za=sorted(K)
S=0
T=0
for i in range(0,len(Za)):
  S+=Za[i]
  T+=Za[i]**2
G=S%N
if G==0:
  print(int(T-S**2/N))
elif G/N<0.5:
  print(int(T-S**2/N+G**2/N))
else:
  print(int(T-S**2/N+(N-G)**2/N))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
x=sorted(x)
m=9999
for j in range(x[0],x[n-1]+1):
    s=0
    for i in range(n):
        s+=(x[i]-j)**2
    m=min(m,s)

print(m)

Submission status: Wrong Answer

Solution code:
from statistics import mean
import math
N = int(input())
X = list(map(int, input().split()))
P = mean(X)
ans = 0
for x in X:
    ans += (x-P)**2
print(math.ceil(ans))

Submission status: Wrong Answer

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

print(np.sum((X-np.round(sum(X)/len(X)))**2))

Submission status: Wrong Answer

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

p = round(sum(xi) / n)
print(p)
hp = 0
for x in xi:
    hp += (x - p) ** 2

print(hp)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
souwa = 0
kazu = len(x)
souwalist=[]
saidai = max(x)

for j in range(saidai):
	for i in range(kazu):
		tem = x[i]
		souwa = (tem - j) ** 2 + souwa
	souwalist.append(souwa)
	souwa = 0

print(min(souwalist))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [int(i) for i in input().split(" ")]
XP2 = [i**2 for i in X]
sum_x = sum(X)
sum_xp2 = sum(XP2)

Min = 10000000000

for p in range(1,max(X)):
    M = sum_xp2 - 2*p*sum_x + (p**2)*N
    if  M < Min:
        Min = M
print(Min)

Submission status: Wrong Answer

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

m=9999
for j in range(x[0],x[n-1]+1):
    s=0
    for i in range(n):
        s+=(x[i]-j)**2
    m=min(m,s)

print(m)

Submission status: Wrong Answer

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

ans = float("inf")

i = 1
while i < max(X):
    cnt = 0
    if i not in X:
        for j in range(N):
            cnt += abs(i-X[j])**2

        if isinstance(i, int):
            ans = min(ans, cnt)

    i += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = float("inf")

i = 1
while i < max(X):
    cnt = 0
    if i not in X:
        for j in range(N):
            cnt += abs(i-X[j])**2

        if isinstance(i, int):
            ans = min(ans, cnt)

    i += 1

print(i)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int, input().split()))
minX=min(X)
maxX=max(X)
minE = 1000000000
for P in range(minX,maxX):
  sum = 0
  for Xi in X:
    sum = sum + (Xi-P)**2
  if minE>sum:
    minE=sum
print(minE)

Submission status: Wrong Answer

Solution code:

N = int(input())
x_list = list(map(int, input().split()))
maxValue = max(x_list)
minValue = 1000000
for i in range(1,maxValue):
    ans = 0
    for j in range(N):
        ans += ( x_list[j] - i ) **2

    if(ans < minValue):
        minValue = ans

print(minValue)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
pivot = (x[0] + x[-1]) // 2
Sum = 0
Min = 99999
for i in range(1,101):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Wrong Answer

Solution code:
input()
a =list(map(int, input().split()))
a.sort()
m = (a[0] + a[-1]) //2
ans = 0
for x in a:
	ans += abs(m-x)**2
print(ans)

Submission status: Wrong Answer

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

m=9999
for j in range(0,101):
    s=0
    for i in range(n):
        s+=(x[i]-j)**2
    m=min(m,s)

print(m)

Submission status: Wrong Answer

Solution code:
N=int(input())
X= list(map(int, input().split())) 
K=max(X)
Y=0
for j in range(N):
    Y=Y+X[j]**2
for i in range(K):
    S=0
    for l in range(N):
        S=S+(X[l]-i)**2
    if S<Y:
        Y=S
print(Y)

Submission status: Wrong Answer

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

spot = sum(X) // len(X)
stamina = 0
for x in X:
    stamina += pow(x - spot, 2)

print(stamina)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 10000
for j in range(1, max(x) + 1):
    cnt = 0
    for i in range(n):
        cnt += (x[i] - j) ** 2
    if cnt < ans:
        ans = cnt
print(ans)

Submission status: Wrong Answer

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

for i in range(max(x)):
    for j in range(n):
        sum+=(x[j]-i)**2
    hp.append(sum)
    sum=0

print(min(hp))

Submission status: Wrong Answer

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

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

print(sum(remain))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
xl = list(map(int, input().split()))
xl_cnt = len(xl)
xl_sum = sum(xl)
xl_avg = xl_sum / xl_cnt
xl_diff = map(lambda x: x - math.ceil(xl_avg), xl)
xl_double = map(lambda x: x * x, xl_diff)
print(sum(xl_double))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
min_total = 0
X_ = sum(X) // len(X)

for i in range(2):
    total = 0
    for j in range(N):
        total += (X[j] - (X_ + i)) ** 2
    if min_total == 0 or min_total >= total:
        min_total = total
print(min_total)

Submission status: Wrong Answer

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

m = 100 * 100 * n
sumlist = []

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

    sumlist.append(s)

print(min(sumlist))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m = int(np.median(x))
k = int(np.std(x))
ans = max(x) ** 2 * n

# pos = m + k
# print(pos)
# cost = 0

low = max(1, m - k)
high = min(m + k, np.max(x))

for i in range(low, high, 1):
  cost = 0
  for j in range (n):
    cost += (x[j] - i) ** 2
  # print(cost)
  if cost < ans:
    ans = cost

print(ans)

Submission status: Wrong Answer

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

ans = float("inf")

i = 0
while i < max(X):
    cnt = 0
    if i not in X:
        for j in range(N):
            cnt += abs(i-X[j])**2

        if isinstance(i, int):
            ans = min(ans, cnt)

    i += 1

print(ans)

Submission status: Wrong Answer

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

m = 10000
ans = 0

for p in range(min(x), max(x)+1):
    ans = 0

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

    if ans < m:
        m = ans


print(m)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip().split()
x = [None]*n
x = [int(s[i]) for i in range(0, n)]

ave = 0
for i in range(0, n):
   ave += x[i]
p = ave//n + 1

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

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	X=list(map(int, input().split()))
	wa = 10000
	for i in range(min(X),max(X)+1):
		dmy_wa = sum(list(map(lambda x:(x-i)**2, X)))
		if dmy_wa < wa:
			wa=dmy_wa
	print(wa)
main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

avg = np.mean(lst)
avg= math.ceil(avg)

ans = 0
for _ in lst:
    ans += (_ - avg) ** 2
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
pivot = (x[0] + x[-1]) // 2
Sum = 0
Min = 99999
for i in range(x[0],x[-1]+1):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Wrong Answer

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

p = int(sum(xi) / n)
hp = 0
for x in xi:
    hp += (x - p) ** 2

print(hp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m = int(np.median(x))
k = int(np.std(x))
ans = max(x) ** 2 * n

# pos = m + k
# print(pos)
# cost = 0

low = max(0, m - k)
high = min(m + k, np.max(x))

for i in range(low, high, 1):
  cost = 0
  for j in range (n):
    cost += (x[j] - i) ** 2
  # print(cost)
  if cost < ans:
    ans = cost

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int, input().split()))
l=[]
#for i in range(len(X)):
#  a=(X[i]-N)**2
#  l.append(a)
l=[(X[i]-N)**2 for i in range(len(X))]
L=sum(l)
print(L)

Submission status: Wrong Answer

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

if sum(x)%n==0: m = sum(x)//n
else: m = sum(x)//n + 1

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

Submission status: Wrong Answer

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

#a=sum(x)//n+1
#x=sorted(x)
m=9999
for j in range(1,101):
    a=j
    s=0
    for i in range(n):
        s+=(x[i]-a)**2
    m=min(m,s)

print(m)

Submission status: Wrong Answer

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

print(sum)

Submission status: Wrong Answer

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


MaxCoo = max(X)
MinCoo = min(X)
ave = (MaxCoo + MinCoo)//2
Range = MaxCoo-MinCoo+1
MinCost = 10**10
for i in range(Range//2):
    pos = ave + i
    cost = 0
    for member in X:
        cost += (member-pos)**2
    if cost < MinCost:
        MinCost = cost

    pos = ave - i
    cost = 0
    for member in X:
        cost += (member-pos)**2
    if cost < MinCost:
        MinCost = cost
print(MinCost)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
x = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
#一行で入力された数値をリストに
p = 0
x2 = np.power(x,2)

xsum = sum(x)
xsum2 = sum(x2)

p = -(-xsum//n)

print(xsum2 - 2*p*xsum + n*p*p)

Submission status: Wrong Answer

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


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(min, max+1):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Wrong Answer

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

d_min = 10**18
for i in range(min(x), max(x)):
  d = 0
  for j in range(len(x)):
    d += (i-x[j])**2
    
  if d<d_min:
    d_min = d
    
print(d_min)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m = int(np.median(x))
k = int(np.std(x))
ans = max(x) ** 2 * n

# pos = m + k
# print(pos)
# cost = 0

for i in range(m-k, m+k, 1):
  cost = 0
  for j in range (n):
    cost += (x[j] - i) ** 2
  # print(cost)
  if cost < ans:
    ans = cost

print(ans)

Submission status: Wrong Answer

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

max_x = max(x)
min_x = min(x)

ans = []
for i in range(1, 101):
  a = 0
  for xi in x:
    a += (xi - (i+1))*(xi - (i+1))
  ans.append(a)
  
print(min(ans))

Submission status: Wrong Answer

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

sum=0
A=[]

for i in range(int(X[N-1]+5)):
    for j in range(N):
        sum+=(X[j]-i)**2
    A.append(sum)
    sum=0

print(min(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
sorted(X)
maxP = X[-1]
total = 1000000000000
for P in range(maxP + 1):
    tmpTotal = 0
    for tmpX in X:
#        print("{} {} {}".format(tmpX, N, (N-int(tmpX))**2))
        tmpTotal = tmpTotal + (P - int(tmpX))** 2
    if tmpTotal < total:
        total = tmpTotal

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
pivot = (x[0] + x[-1]) // 2
Sum = 0
Min = 99999
for i in range(x[0]+1,x[-1]):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Wrong Answer

Solution code:
def minus(x,y):
    return (x - y) ** 2

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

min = 0
result = 0
for i in range(N):
    for j in X:
        result += (i + 1 - j) ** 2
    #print(result)
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
y = x
y.sort()
mini = 10000000000000
for i in range(y[-1]):
    tmp = 0
    for j in x:
        tmp += (j - i)**2
    if mini > tmp:
        mini = tmp
print(mini)

Submission status: Wrong Answer

Solution code:
N =int(input())
X = list(map(int,input().split()))
X.sort()
tans=[]
try:
  for i in range(1,X[N-1]):
    P=i
    ans=0
    for j in range(N):
      ans+=(X[j]-P)**2
    tans.append(ans)
  print(min(tans))
except:
  print(0)

Submission status: Wrong Answer

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


min = min(x_list)
max = max(x_list)

ans = 100*100

for p in range(min, max):
    tmp = 0
    for x in x_list:
        tmp += (x - p) ** 2
    if ans > tmp:
        ans = tmp

print(ans)