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())
x = list(map(int, input().split()))

min, max = 0, 0
for i in range(n):
  if min > x[i]:
    min = x[i]
  if max < x[i]:
    max = x[i]

min2, max2 = min**2, max**2
ans = max2 if max2 > min2 else min2
for p in range(min, max):
  sum = 0
  for z in x:
    sum += (z-p)**2
  if ans > sum:
    ans = sum
    
print(ans)

Submission status: Wrong Answer

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

min, max = 0, 0
for i in range(n):
  if min > x[i]:
    min = x[i]
  if max < x[i]:
    max = x[i]

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
X = [int(i) for i in input().split()]
X = np.array(X)
res = 100**100
for i in range(max(X)):
    tmp = sum((abs(X-i))**2)
    #print(tmp)
    if res > tmp:
        res = tmp
print(res)

Submission status: Wrong Answer

Solution code:
import sys
l = sys.stdin.readline().strip()
n = int(l)
l = sys.stdin.readline().strip()
nums = map(int, l.split())
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = -1
def compute_dist(p):
  dist = 0
  for n in nums:
    dist += (n-p) ** 2
  return dist
for i in range(start, end):
  d = compute_dist(i)
  if d < mi:
    mi = d
print(mi)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

p = sum(x)/N

if p == int(p):
	q = p
elif p-int(p) < int(p)+1-p:
	q = int(p)
else:
	q = int(p)+1

ans = 0
for i in range(N):
	ans += (x[i]-q)*(x[i]-q)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()
print(data)

temp = []
for i in range(n):
  for j in range(n):
    k = (int(data[i])-int(data[j]))**2
    temp.append(k)

print(min(temp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
aprx = round(sum(arr)/n)
ans = 0
d={}
for i in arr:
  if i in d:
    ans+=d[i]
  q = ((i-aprx)**2)
  d[i] = q
  ans+=q
  
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
x=np.fromstring(input(),int,sep=' ')
print(x)
p=0
hoge=np.inf
for i in range(1,np.max(x)+1):
    sux=sum((x-i)**2)
    if sux<hoge:
        p=i
        hoge=sux
print(hoge)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
k=0
s=9999999999999999999999999999
for i in range(1,n+1):
  k=0
  for j in range(n):
    k+=(a[j]-i)**2
  s=min(s,k)
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Solution code:
n=int(input())
X=[int(x) for x in input().split()]
ans=float("inf")
for p in range(1,101):
  s=0
  for x in X:
    s+=(p-x)^2
  ans=min(s,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[int(x) for x in input().split()]
ans=float("inf")
for p in range(1,101):
  s=0
  for a in x:
    s+=(p-a)^2
  ans=min(s,ans)
print(ans)

Submission status: Wrong Answer

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

m = min(X)
M = max(X)

cost = [100*100 for _ in range(101)]
for p in range(1,101):
    c = 0
    for x in X:
        c += (x-p)**2
    cost[p] = c

print(min(cost))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
mini = 10000
for i in range(1, 101):
    l_sum = sum(list(map(lambda x: (x - i)**2, l)))
    if mini > l_sum:
        mini = l_sum
print(mini)

Submission status: Wrong Answer

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

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

p = 0

if m - mp < mp + 1 - m:
  p = int(mp)

else:
  p = int(mp + 1)

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

Submission status: Wrong Answer

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 += (i - p)**2
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(1, n+1):
    hp = 0    
    for j in range(n):
        hp += (i - x[j]) * (i - x[j])
    
    min_hp = min(hp, min_hp)
    
print(min_hp)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
r = max(X)
list = []
n = 1
R = 0

for i in range(r):
  while n <= N-1:
    R += (int(X[n])-i)**2
    n += 1
  list.append(R)
  R = 0
  n = 0
    
print(min(list))

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
A=sum(X)
y=N*((round(A/N)-A/N)**2)-(A**2)/N
B=sum([i**2 for i in X])
print(y+B)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append((A[i]-N)**2)
print(sum(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
 
x = input().split()
x = [int(_x) for _x in x]
 
_p = sum(x) // n
 
_p_value = sum([(_x - _p) ** 2 for _x in x])
__p_value = sum([(_x - _p + 1) ** 2 for _x in x])
 
if _p_value > __p_value:
  print(__p_value)
else:
  print(_p_value)

Submission status: Wrong Answer

Solution code:
n = int(input())

x = input().split()
x = [int(_x) for _x in x]

_p = sum(x) // n

_p_value = sum([(_x - _p) ** 2 for _x in x]) / n
__p_value = sum([(_x - _p + 1) ** 2 for _x in x]) / n

if _p_value > __p_value:
  print(__p_value)
else:
  print(_p_value)

Submission status: Wrong Answer

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

m = min(X)
M = max(X)

min_val = 100 * 100
for p in range(m, M+1):
    score = 0
    for x in X:
         score += (x-p)*(x-p)
    if score < min_val: min_val = score
print(min_val)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xs = list(map(int, input().split()))
L,R = min(Xs), max(Xs)
cost = float("inf")
for p in range(L+1,R):
  cost_p = sum([(xi-p)**2 for xi in Xs])
  cost = cost_p if cost_p < cost else cost
print(cost)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

P = math.ceil(sum(X) / N)

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

print(total)

Submission status: Wrong Answer

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

Solution code:

N = input()
X = input().split()
total1 = 0
total2 = 0
for i in X:
    i = int(i)
    total1 += 1
    total2 += i
total2 *= 2
total1 *= 2
min = total2/total1
if min >= 1:
    if min%int(min) >=0.5:
        min = int(min) + 1
    elif min%int(min) == 0 :
        min = int(min)
    else:
        min = int(min) - 1
else:
    min = 1


sum = 0
for i in X:
    i  = int(i)
    sum += (min-i)*(min-i)
print(sum,end="")

Submission status: Wrong Answer

Solution code:
n=input()
Xs=list(map(int,input().split()))
Xs.sort()
a=Xs[0]
b=Xs[-1]
ans=b**2
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: Wrong Answer

Solution code:
N = input()
X = input().split()
total1 = 0
total2 = 0
for i in X:
    i = int(i)
    total1 += 1
    total2 += i
total2 *= 2
total1 *= 2
min = total2/total1
if min >= 1:
    if min%int(min) >=0.5:
        min = int(min) + 1
    elif min%int(min) == 0 :
        min = int(min)
    else:
        min = int(min) - 1
else:
    min = min = int(min) + 1


sum = 0
for i in X:
    i  = int(i)
    sum += (min-i)*(min-i)
print(sum,end="")

Submission status: Wrong Answer

Solution code:
N = input()
X = input().split()
total1 = 0
total2 = 0
for i in X:
    i = int(i)
    total1 += 1
    total2 += i
total2 *= 2
total1 *= 2
min = total2/total1
if min%int(min) >=0.5:
    min = int(min) + 1
elif min%int(min) ==0 :
    min = int(min)
else:
    min = int(min) - 1


sum = 0
for i in X:
    i  = int(i)
    sum += (min-i)*(min-i)
print(sum)

Submission status: Wrong Answer

Solution code:
N = input()
X = input().split()
total1 = 0
total2 = 0
for i in X:
    i = int(i)
    total1 += 1
    total2 += i
total2 *= 2
total1 *= 2
min = total2/total1
if min%int(min) >=0.5:
    min = int(min) + 1
else:
    min = int(min) - 1


sum = 0
for i in X:
    i  = int(i)
    sum += (min-i)*(min-i)
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x_min = 10**18
for j in range(max(x)):
  x_sum = 0
  for i in x:
    x_sum += (i - j)**2
  x_min = min(x_min,x_sum)
print(x_min)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = list(map(int,input().split()))
result = []
for i in li:
    n = (int(i-N)**2)
    if n < 0:
        pass
    elif n > 0:
        result.append(n)

print(sum(result))

Submission status: Wrong Answer

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

x_mean1 = sum(x) // n
x_mean2 = int(sum(x) / n)
x_sum1 = 0
x_sum2 = 0
for i in x:
  x_sum1 += (i - x_mean1)**2
  x_sum2 += (i - x_mean2)**2

print(min(x_sum1,x_sum2))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
l, r = 0, 0
for i in x:
    l = min(l, i)
    r = max(l, i)
ans = 10e9
for i in range(l, r):
    cost = 0
    for j in range(n):
        cost += (x[j] - i) * (x[j] - i)
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
l, r = 0, 0
for i in x:
    l = min(l, i)
    r = max(l, i)
ans = 10e9
for i in range(l, r + 1):
    cost = 0
    for j in range(n):
        cost += (x[j] - i) * (x[j] - i)
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
l, r = 0, 0
for i in x:
    l = min(l, i)
    r = max(l, i)
ans = 10e9
for i in range(l, r + 1):
    cost = 0
    for j in range(n):
        cost += (x[j] - i) * (x[j] - i)
        print(i, j)
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = []
l = min(x)
r = max(x)

for i in range(l, r+1):
  tmp = 0
  for j in range(n):
    tmp+= (x[j]-(i+1))*(x[j]-(i+1))
  ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
xlist = list(map(int, input().split()))
p = sum(xlist) // N + 1
s = 0
for x in xlist:
    s += (x-p)**2
print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(x) for x in input().split()]
import math
import statistics
mean=statistics.mean(a)
m=round(mean,0)

sum=0
for x in a:
    t=(x-m)**2
    sum+=t
print(sum)

Submission status: Wrong Answer

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

P = 1
Pmin = 999

while P <= 100:
	sum = 0
	for Xi in X:
  		sum = sum + (Xi-P)**2
    
	if P == 1:
		Smin = sum
	else:
		if Smin > sum:
			Smin = sum
			Pmin = P
	P= P+1      
      
print(Pmin)

Submission status: Wrong Answer

Solution code:
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
print(max(temp))
for n_ in range(max(temp) + 1):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
s = sum(x)
p = (s+n-1)//n
r = 0
for y in x:
    r += (y - p)**2
print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
s = sum(x)
p = (s+n-1)/n
r = 0
for y in x:
    r += (y - p)**2
print(r)

Submission status: Wrong Answer

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


N = ii()

X = li()

import numpy as np

X = np.sort(X)

x_st = X[0]
x_ed = X[-1]

all_min = np.inf

for i in range(x_st,x_ed):
    itr_min = np.sum(np.abs(X-i)**2)
    # print(i,itr_min)


    if(all_min > itr_min):
        all_min = itr_min


print(all_min)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
p = sum(b) // a

hp = 0
for i in b:
    hp += (i - p) ** 2

print(hp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

N = int(input())
Xn = [int(x) for x in input().split()]
L = Xn[0]
R = Xn[0]
for i in range(N):
    L = min(L, Xn[i])
    R = max(R, Xn[i])

ans = float('inf')
for i in range(L,R):
    pos = 0
    for j in Xn:
        pos += (j-i)*(j-i)
    ans = min(ans, pos)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xn = [int(x) for x in input().split()]
L = Xn[0]
R = Xn[0]
for i in range(N):
    L = min(L, Xn[i])
    R = max(R, Xn[i])

ans = float('inf')
for i in range(L,R):
    pos = 0
    for j in Xn:
        pos += (j-i)*(j-i)
    ans = min(ans, pos)
print(ans)

Submission status: Wrong Answer

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

print(  min( sum( (xx-j)**2 for xx in x ) for j in range(max(x)) ) )

Submission status: Wrong Answer

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

ans = 10 ** 5
for p in range(min(x), max(x) + 1):
    cost = 0
    for xi in x:
        cost += (xi - p) ** 2
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

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

tminm = 0
for k in range(N):
  tminm += (A[k] - 1)**2

ma = max(A)
for i in range(2,ma):
  minm = 0
  for j in range(N):
    minm += (A[j] - i)**2
  
  if minm < tminm:
    tminm = minm

print(tminm)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 100 * 100 + 100
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)

Submission status: Wrong Answer

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

ans = 100 * 100
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)

print(ans)

Submission status: Wrong Answer

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

p = sum(x)/n

h = 0
for i in x:
  h += abs(i - p)**2
print(math.ceil(h))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

m = math.ceil(sum(X) / N)

res = 0

for i in range(N):
    res += (X[i] - m) ** 2
    
print(res)

Submission status: Wrong Answer

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

ans = 9999999
for p in range(1,n+1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    ans = min(ans, s)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r+1):
      R = X[0] + i
      hp = 0
      for j in range(N):
        hp = hp + (R - X[j]) ** 2
 
        ans = min(hp, ans)
 
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    if r == 0:
        print(0)
    else:
        for i in range(r):
            R = X[0] + i
            hp = 0
            for j in range(N):
                hp = hp + (R - X[j]) ** 2

            ans = min(hp, ans)

    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue
import itertools

n = int(input())
x = np.array(list(int(i) for i in input().split()))

ans = 0x7FFF
for p in range(np.min(x), np.max(x) + 1):
	ans = min(np.sum((x - p) ** 2), ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2

        ans = min(hp, ans)

    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
if N == 1:
    print(0)
else:
    r = X[-1] - X[0]
    ans = 10 ** 20
    for i in range(r):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2

        ans = min(hp, ans)

    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
r = X[-1] - X[0]
ans = 10 ** 20
for i in range(r):
    R = X[0] + i
    hp = 0
    for j in range(N):
        hp = hp + (R - X[j]) ** 2

    ans = min(hp, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split())))
r = X[-1] - X[0]
ans = 10 ** 12
for i in range(r):
    R = X[0] + i
    hp = 0
    for j in range(N):
        hp = hp + (R - X[j]) ** 2

    ans = min(hp, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
res=0
arr  = [int(x) for x in input().split()]
for i in range(n):
  res+=arr[i]
res = res//n
if (res&1):
  res+=1
k=0
for i in range(n):
  k+=((arr[i]-res)**2)
print(k)

Submission status: Wrong Answer

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

c = sum(A)//N + 1
ans = 0
for i in range(N):
  ans += (A[i] - c) ** 2
print(ans)

Submission status: Wrong Answer

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

ans = 100 * 100
for p in range(1, 101):
    s = 0
    for xi in X:
        s += (xi - p) ** 2
    ans = min(ans, s)
    s = 0

print(ans)

Submission status: Wrong Answer

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

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

print(min)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X) / N) + 1
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X) / N) + 1
print(sum(X))
print(sum(X) / N)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
m = sum(x) // len(x)+1
l = [] 
for i in x:
  s = (i-m)**2
  if s < 0:
    l.append(-s)
  else:
    l.append(s)
print(sum(l))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
m = sum(x) // len(x)+1
l = [] 
for i in x:
  s = (i-m)**2
  if s < 0:
    l.append(-s)
  else:
    l.append(s)
print(sum(l), l, m)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
P = int(sum(X)/N)
total = 0
for x in X:
  kyori = (x - P) * (x - P)
  total += kyori
print(total)

Submission status: Wrong Answer

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

R = 99999
for p in range(1, 100 + 1):
    R0= sum([(x - p) ** 2 for x in XL])
    R = min(R, R0)

print(R)

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())
index = list(map(int, input().split()))
energy = []
for p in range(1, n+1):
    sum = 0
    for xi in index:
        sum += (xi-p)**2
    energy.append(sum)
print(min(energy))

Submission status: Wrong Answer

Solution code:
n = int(input())
r = list(map(int, input().split()))
old = None
for x in range(min(r), max(r)):
  t = sum([(i - x) ** 2 for i in r])
  if not old:
      old = t
      continue
  if t < old:
    old = t
print(old)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
p = s//n
r = 0
for i in arr:
  r += (p-i)**2
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
r = list(map(int, input().split()))
o = (max(r) + min(r)) // 2
old = None
for x in range(o//2, max(r)):
  t = sum([(i - x) ** 2 for i in r])
  if not old:
      old = t
      continue
  if t < old:
    old = t
print(old)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = list(map(int, input().split()))
o = (max(r) + min(r)) // 2
old = 1000000000000000000000000
for x in range(o//2, max(r)):
  t = sum([(i - x) ** 2 for i in r])
  if t < old:
    old = t
print(old)

Submission status: Wrong Answer

Solution code:
lenght = int(input())
people = [int(i) for i in input().split()]
resultList = []
for i in range(min(people), max(people)):
  mylist = []
  for j in people:
    mylist.append((j - i) ** 2)
  resultList.append(sum(mylist))
if(len(resultList) == 0):
  print(people[0])
else:
  print(min(resultList))

Submission status: Wrong Answer

Solution code:
import math
 
N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
        if(a != c):
            all = False
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-math.ceil(C))**2
if all == True:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
 
N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
        if(a != c):
            all = False
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-math.ceil(C))**2
    print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    X = list(iim())

    av = 2 * (sum(X) + N) // N // 2
    ans = 0
    for x in X:
        ans += (x - av)**2
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
N=int(input())
people=[]
cost=[]
 
people=list(map(int,input().split()))

for p in range(len(people)):
    cost.append(0)
    for person in people:
      cost[-1]+=(person-(p+1))**2
print(min(cost))

Submission status: Wrong Answer

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

p = sum(x) / N
p0 = p - int(p)

if p <= 0.5:
    p = int(p)
else:
    p = int(p) + 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    X = list(iim())

    av = 2 * (sum(X) + N) // N
    ans = 0
    for x in X:
        ans += (x - av)**2
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

Max = max(X)
p_min = 100000
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(map(int, input().split()))
print(int((sum(X) + 0.5) / N))

Submission status: Wrong Answer

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

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

ans = []

for i in range(a-1,b):
  S = 0
  for j in range(N):
    S += (X[j]-i)**2

  ans.append(S)
  
print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

a = []
for pp in range(max(x)):
    sum = 0
    for xx in x:
        sum += abs((xx-pp) ** 2)
    a.append(sum)

print(min(a))

Submission status: Wrong Answer

Solution code:
#import math

N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
P = 0
while P <= xList[-1]:
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)
  P +=1

result = min(dList)

if N == 1:
  result = 0

print(result)

Submission status: Wrong Answer

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

p0 = sum(x)//len(x)
# 123
cost = 10**9
for i in range(1,101):
    now = 0
    for j in x:
        now += abs(i-j)**2
    if cost > now:
        cost = now

print(now)

Submission status: Wrong Answer

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

p0 = sum(x)//len(x)
# 123
cost = 10**9
for i in range(0,100):
    now = 0
    for j in x:
        now += abs(i-j)**2
    if cost > now:
        cost = now

print(now)

Submission status: Wrong Answer

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

p0 = sum(x)//len(x)
# 123
cost = 10**9
for i in range(0,100):
    now = 0
    for i in x:
        now += abs(p0-i)**2
    if cost > now:
        cost = now

print(now)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
MAX = max(X)
res = []
if MAX == 1:
  print(1)
  sys.exit()
for a in range(1, MAX+1):
  total = 0
  for x in X:
    kyori = (x - a) * (x - a)
    total += kyori
  res.append(total)
print(min(res))
print(res)

Submission status: Wrong Answer

Solution code:
#import math

N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
P = 0
while P < xList[-1]:
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)
  P +=1

result = min(dList)

if N == 1:
  result = 0

print(result)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
MAX = max(X)
res = []
if MAX == 1:
  print(1)
  sys.exit()
for a in range(1, MAX+1):
  total = 0
  for x in X:
    kyori = (x - a) * (x - a)
    total += kyori
  res.append(total)
print(min(res))
print(res)

Submission status: Wrong Answer

Solution code:
def rally(n, x):
    if not len(x) == n:
        return "==== pleas input based on n times in one line ===="
    else:
        new_list = []
        for i in x:
            r = (i - n)**2
            new_list.append(r)
        return sum(new_list)
n = int(input())
x = list(map(int, input().split())) #input based on n
print(rally(n, x))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X = [int(x) for x in input().split()]
MAX = max(X)
res = []
if MAX == 1:
  print(1)
  sys.exit()
for a in range(1, MAX):
  total = 0
  for x in X:
    kyori = (x - a) * (x - a)
    total += kyori
  res.append(total)
print(min(res))

Submission status: Wrong Answer

Solution code:
import math
from statistics import mean, median,variance,stdev
N = int(input())
X = list(map(int,input().split()))
a = sum(X)
ave = math.ceil(a/N)
b = 0
for i in range(N):
    b +=(X[i]-ave)**2
print(b)