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:
import math

def calc(N, X):
    P = sum(X) / N
    res = 0
    for x in X:
        res += (P - x) ** 2
    return math.ceil(res)

if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    print(calc(N, X))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
if N == 1:
  print(0)
  exit()
ans = float('inf')
for p in range(X[0], X[N - 1] + 1):
  sum = 0
  for x in X:
    sum += (x - p) ** 2
  ans = min(sum, ans)
print(ans)

Submission status: Wrong Answer

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

min = 10000*N

lst.sort()

for i in range(lst[0],lst[-1]):
  x = 0
  for j in lst:
    x += (j-i)*(j-i)
  if x < min:
    min = x
    
print(min)

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    x = list(map(int, input().split()))
    total = 0
    for i in range(n):
        total += x[i]
    p = math.ceil(total/n)
    ans = 0
    for i in range(n):
        ans += (x[i]-p)**2
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m = int(np.mean(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 = [int(x) for x in input().split()]

ans = 100 ** 2
for i in range(1, max(X)+1):
  a = 0
  for j in range(N):
    a += (X[j] - i) ** 2
  if ans > a:
    ans = a
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(min_x, max_x+1):
  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 = sorted([int(x) for x in input().split()])
min_cost = 10**12
for p in range(X[0]+1, X[-1]):
    cost_sum = 0
    for x in X:
        cost_sum += (x-p)**2
    min_cost = min(min_cost, cost_sum)

print(min_cost)

Submission status: Wrong Answer

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

mid = round(sum(X) / 7)
hoge = 0
for i in X:
    hoge += (i - mid)** 2
    
print(hoge)

Submission status: Wrong Answer

Solution code:
def physical_strength(x,p):
  return pow((x - p), 2)



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 += physical_strength(x, i)
    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_min = min(X)
X_max = max(X)
S = []
if X_min == X_max:
    S.append(X_min)
for x in range(X_min, X_max):
    s = 0
    for i in range(N):
        s += (X[i]-x)**2
    S.append(s)
print(min(S))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

p = (1/n) * sum(x)

h = -(1/n)*(sum(x)**2)
m = np.array(x)
d = sum(m ** 2)

print(math.ceil(h + d))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    N, *X = map(int, read().split())
    s = -(-sum(X)//len(X))
    res = [(x - s) ** 2 for x in X]
    print(sum(res))
    
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#ABC156 C - Rally

n = int(input())
x = [int(x) for x in input().split(' ')]
    
min_len =  100**2 * n

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

    min_len = min(min_len,all_len)

print(min_len)

Submission status: Wrong Answer

Solution code:
n = int(input())
k = list(map(int, input().split()))
p = min(k)
counta = 0
min_ = 2147483647
while p != max(k):
    tmp = 0
    for i in range(0,n):
        tmp += ((k[i]-p)**2)
    if tmp < min_:
        min_ = tmp
    p += 1
print(min_)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(max(X)):
    goukei = 0
    for j in range(N):
        if i%1==0:
            goukei+=(X[j]-i)**2
    ans.append(goukei)
kotae=set(ans)
print(min(kotae))

Submission status: Wrong Answer

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

for i in range(len(X)):
  sum += abs(X[i] - N) ** 2

print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m = int(np.mean(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-1) ** 2
  # print(cost)
  if cost < ans:
    ans = cost

print(ans)

Submission status: Wrong Answer

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

#処理
import numpy as np
X=np.array(X)
Z=[i**2 for i in range(101)]
Y=X-1
S=np.array([Z[i] for i in Y])
T=np.sum(S)
for i in range(2,np.max(X)):
    Y=X-i
    S=np.array([Z[abs(i)] for i in Y])
    SS=np.sum(S)
    if int(SS)<int(T):
        T=SS
print(T)

Submission status: Wrong Answer

Solution code:
import statistics
import math

ans = 0
n = int(input())
x = list(map(int, input().split()))
m = math.ceil(statistics.mean(x))
for i in range(n):
    num = (x[i]-m)**2
    ans = ans+num

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(np.mean(X))
print(int(np.mean(X)))
if np.mean(X)-int(np.mean(X))>=0.5:
    count=int(np.mean(X))+1
else:
    count=int(np.mean(X))    

result=0
for i in range(N):
    result+=(X[i]-count)*(X[i]-count)
print(result)

Submission status: Wrong Answer

Solution code:
b = input()
a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])

best = None

for i in range(len(a)):
    a[i] = a[i] + 1

for i in range(100):
    for j in range(len(a)):
        a[j] = a[j] - 1
    s = sum(a)**2
    if best is None or s < best:
        best = s

print(best)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

x.sort()
ave = sum(x) / len(x)
squared = sum([i*i for i in x])

print(Decimal(str(squared - n*(ave)*ave)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().strip().split()))
alist=[]
pm=10e9
for p in range (min(x),max(x)):
    ans=0
    for xi in x:
        ans += (xi-p)**2

    if(ans<pm):
        pm=ans
print(pm)

Submission status: Wrong Answer

Solution code:
import numpy as np

minans = 1000000000

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

ma = int(np.max(X))
mi = int(np.min(X))

for i in range(mi, ma):
	ans = int(np.sum((X-i) ** 2))
	if ans < minans:
		minans = ans

print(minans)

Submission status: Wrong Answer

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

min = 10000*N

lst.sort()

for i in range(lst[0],lst[N-1]):
  x = 0
  for j in lst:
    x += (j-i)*(j-i)
  if x < min:
    min = x
print(min)

Submission status: Wrong Answer

Solution code:
from statistics import median


def main():
    n = int(input())
    x = list(map(int, input().split()))
    med = 0
    result = 0

    if n % 2 == 0:
        med = int(median(x))
    else:
        med = median(x)
    for i in x:
        result += (i - med) ** 2
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 100 ** 2
for i in range(1, max(X)):
  a = 0
  for j in range(N):
    a += (X[j] - i) ** 2
  if ans > a:
    ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted([int(x) for x in input().split()])
min_cost = 10**5
for p in range(X[0]+1, X[-1]):
    cost_sum = 0
    for x in X:
        cost_sum += (x-p)**2
    min_cost = min(min_cost, cost_sum)

print(min_cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
K= list(map(int,input().split()))
A = 0
import statistics
median = int(statistics.median(K))
for i in range(N):
   A +=K[i]**2 -2*K[i]*median + median*2

print(A)

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]+1)):
    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 = list(map(int, input().split()))


sumDist = sum(x_list)
p = int(sumDist // N)
print(p)
ans1 = 0
ans2 = 0
ans3 = 0
for i in range(N):
    ans1 += (x_list[i] - p)**2
    ans2 += (x_list[i] - p -1)**2
    ans3 += (x_list[i] - p +1)**2

if(ans1 <= ans2 and ans1 <= ans3):
    print(ans1)
elif(ans2 <= ans1 and ans2 <= ans3):
    print(ans2)
else:
    print(ans3)

Submission status: Wrong Answer

Solution code:
import math

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

mx = float(sum(lx)/n)

if sum(lx)%n == 0:
  print(sum(lx)/n)
else:
  mx = float(sum(lx)/n)
  mxc = sum([(x - math.ceil(mx))**2 for x in lx])
  mxf = sum([(x - math.floor(mx))**2 for x in lx])
  if mxc < mxf:
    print(mxc)
  else:
    print(mxf)

Submission status: Wrong Answer

Solution code:
def physical_strength(x,p):
  return pow((x - p), 2)



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):
    sum_ps = 0
    for x in x_list:
      sum_ps += physical_strength(x, i)
    if(sum_ps < fin_ps):
      fin_ps = sum_ps
  
  print(fin_ps)

Submission status: Wrong Answer

Solution code:
n = int(input())
people = list(map(int, input().split()))
P = int(sum(people)/n + 0.5)
square = sum([x ** 2 for x in people])
res = n * (P - sum(people) / n) ** 2 + square - sum(people) ** 2 / n
print(int(res))

Submission status: Wrong Answer

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

min = 10000

lst.sort()

for i in range(lst[0],lst[N-1]):
  x = 0
  for j in lst:
    x += (j-i)*(j-i)
  if x < min:
    min = x
print(min)

Submission status: Wrong Answer

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

if n%2==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:
# Initializing variables
n = int(input())
x = list(map(int, input().split()))
max_X = max(x)
mini = 0
maximum = 1000000

# Calculating the minimum total of stamina
for i in range(0, max_X) :
    for j in range(n) :
        mini += (x[j] - i) ** 2
    if mini < maximum :
        maximum = mini

print(maximum)

# Check out my Youtube channel! https://www.youtube.com/channel/UCMOKVyAbTZOpKikTrX5dy_A

Submission status: Wrong Answer

Solution code:
b = input()
a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])

best = None
besti = None

for i in range(len(a)):
    a[i] = a[i] + 1

for i in range(100):
    for j in range(len(a)):
        a[j] = a[j] - 1
    s = sum(a)**2
    if best is None or s < best:
        best = s
        besti = i

print(besti)

Submission status: Wrong Answer

Solution code:
n = int(input())
xls = list(map(int, input().split()))
mx = max(xls)
res = mx ** 2
for i in range(1, mx + 1):
    s = sum((x - i) ** 2 for x in xls)
    if s < res:
        res = s
print(res)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
X = list(map(int, input().split()))
P = math.floor(sum(X)/N)+1
ans = sum([(x-P)**2 for x in X])
print(ans)

Submission status: Wrong Answer

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

ave = -1*(-1*sum(X)//len(X))
dist = [(i-ave)**2 for i in X]

print(sum(dist))

Submission status: Wrong Answer

Solution code:
n = int(input())
za = list(map(int,input().split()))
print(za)
za_max = max(za)
za_min = min(za)
kouho = 0
kouho_sum = 0
ans = 9999999999999999999999999999999999999999999999999999999999999999999999999999
for zahyou in range(za_min,za_max+1):
    for i in za:
        kouho = (i - zahyou)*(i - zahyou)
        kouho_sum = kouho_sum + kouho
    if(ans > kouho_sum):
        ans = kouho_sum
        kouho_sum = 0
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=999999999999
for j in range(x[0],x[n-1]):
    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())
li = list(map(int,input().split()))
sum = 0
for i in range(N):
    sum = sum + (li[i]-(1))**2
#print(sum)
for i in range(2,N+1):
    temp = 0
    for j in range(N):
        temp = temp + (li[j]-i)**2
#        print("座標=",i," : ",li[j],li[j]-i,(li[j]-i)**2)
    if(sum > temp):
        sum = temp
#    print("temp")
#    print(temp)
print(sum)

Submission status: Wrong Answer

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

phy = []
tmp = 0
max = 0
count = 0

for i in range(101):
    phy.append(i*i)

for j in range(1,x[n-1]+1):
    for k in range(n):
        tmp += phy[abs((j-x[k]))]
    if(max > tmp or count == 0):
        max = tmp
    count += 1
    tmp = 0

print(max)

Submission status: Wrong Answer

Solution code:
from statistics import mean

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

spot = int(mean(X))
stamina = 0
for x in X:
    stamina += pow(x - spot, 2)

print(stamina)

Submission status: Wrong Answer

Solution code:
n=int(input())
ls=input().split(' ')
hp=0
for i in range(n):
  hp+=(int(ls[i])-n)**2
print(hp)

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
if S%N==0:
  print(int(T-S**2/N))
elif (S/N)%1<0.5:
  print(int(T-S**2/N+N*((S/N)%1)**2))
else:
  print(int(T-S**2/N+N*((1-(S/N%1)))**2))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

ans = math.ceil(np.var(lst) * n)

print(ans)

Submission status: Wrong Answer

Solution code:
b = input()
a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])

best = 10000000
besti = None

for i in range(len(a)):
    a[i] = a[i] + 1

for i in range(100):
    for j in range(len(a)):
        a[j] = a[j] - 1
    s = sum(a)**2
    print(s)
    if s < best:
        best = s
        besti = i

print(besti)

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    array = [int(s) for s in input().split(" ")]
    max_v = max(array)
    min_ans = float("inf")
    for i in range(0, max_v):
        total = 0
        for a in array:
            total += (a - i) ** 2
        if min_ans > total:
            min_ans = total
    print(min_ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def HPlist(p):
    return [(i-p)**2 for i in X]

HP_list = []
for i in range(len(X)):
    HP_list.append(sum(HPlist(i+1)))
print(HP_list)

Submission status: Wrong Answer

Solution code:
import math

def round_manual(n):
    if n >= 0.5:
        res = math.ceil(n)
    else:
        res = math.floor(n)
    return res

def resolve_c():
    n = input()
    l = list(map(int, input().split()))
    mean = sum(l) / len(l)
    res = round_manual(mean)
    ans = sum([(i-res) ** 2 for i in l])
    print(ans)
    
resolve_c()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

for i in range(n):
    cost += (x[i] - pos) **2

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

print(cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#a=sum(x)//n+1

m=999999999999
for j in range(x[0],x[n-1]):
    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 = list(map(int, input().split()))

max_x = max(x_list)
min_x = min(x_list)

each_value_list = []
min_value = 10e1000
for i in range(min_x, max_x + 1):
    print(i)
    tmp_sum = 0
    for x in x_list:
        tmp_sum += (x - i)**2
    if min_value > tmp_sum:
        min_value = tmp_sum

print(min_value)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
temp = 0
min = 100000000000000000000000000
for i in range(li[0], li[-1]+1):
    for k in li:
        temp += (k - i)**2
    if temp < min:
        min = temp
    temp = 0
print(str(min))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# 住人の人数
n = int(input())
# 住んでいる場所
x = list(map(int, input().split()))

print(min([sum([(temp - p) ** 2 for temp in x])for p in range(max(x))]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().rstrip().split(" ")))
ans = 0
ansb = 0
for i in range(100):
  ansb = 0
  for i2 in range(N):
    ansb += (X[i2] - i)**2
  if ans == 0 or ans > ansb:
    ans = ansb
print(ans)

Submission status: Wrong Answer

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

s.sort()
minx=s[0]
maxx=s[-1]

c=10**9
for p in range(minx,maxx):
  t=0
  for i in s:
    t=t+(i-p)*(i-p)
  if c>t:
    c=t

print(c)

Submission status: Wrong Answer

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

for i in X: ans += pow((i - n), 2)
print(ans)

Submission status: Wrong Answer

Solution code:
P= int(input())
personArray = [int(i) for i in input().split()]

def distance(person):
    return (person-P)**2

result = 0
for i in personArray:
    result += distance(i)

print(result)

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    array = [int(s) for s in input().split(" ")]
    total = 0
    min_v = min(array)
    max_v = max(array)
    min_ans = float("inf")
    for i in range(min_v, max_v):
        total = 0
        for a in array:
            total += (a - i) ** 2
        if min_ans > total:
            min_ans = total
    print(min_ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
x = input().split()
x = np.array(x,dtype='int')
m = x.sum()
v = (x**2).sum()
pm = int(np.round(m/n))
n * pm**2 - 2*pm*m + v

Submission status: Wrong Answer

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

#s = float('Inf')
s = float('Inf')
for i in range(min(x), max(x)):
    score = 0
    for j in x:
        score += (j - i)**2 
    s = min(s, score)

print(s)

Submission status: Wrong Answer

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

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:
import math

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

num = math.ceil(sum(x)/len(x))
res = 0

for i in x:
    res += (i - num)**2

print(res)

Submission status: Wrong Answer

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

mini = (100-1)**2
for p in range(1, 101):
    temp = 0
    for i in x:
        temp += (i-p)**2
    mini = min(mini, temp)

print(mini)

Submission status: Wrong Answer

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

a=sum(x)//n+1

m=999999999999
for i in range(x[0],x[n-1]):
    a=i
    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()))
x.sort()
mini = 10000000000000
for i in range(x[-1]):
    tmp = 0
    for j in x:
        tmp += (j - i)**2
    if mini > tmp:
        mini = tmp
print(mini)

Submission status: Wrong Answer

Solution code:
hito = int(input())
pos = list(map(int,input().split()))
pos.sort()
best = 10*5
temp = 0
for i in range(pos[0], pos[hito - 1] + 1):
    for n in pos:
        temp += (i - n)**2
    if best > temp:
        best = temp
    temp = 0
print(best)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
res=float("inf")
for i in range(max(A)):
    res1=0
    for j in range(len(A)):
        res1=res1+(A[j]-i)**2
    res=min(res,res1)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input().rstrip())

A = [int(n) for n in input().rstrip().split(' ')]

ans = []
for i in range(1, N+1):
  temp = 0
  for j in range(len(A)):
    temp += (A[j]-i)**2
  ans.append(temp)

print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
a1 = np.min(A)
a2 = np.max(A)

ans = 10000
for p in range(a1,a2+1):
    B = (A-p)**2
    s = np.sum(B)
    if s < ans:
        ans = s

print(ans)

Submission status: Wrong Answer

Solution code:
import sys 
read = sys.stdin.buffer.read
N,*X = map(int,read().split())
s = sum(X)
res = [(x-s)**2 for x in X]
print(sum(res))

Submission status: Wrong Answer

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

num = sum(lst)//n
sum1 = 0
sum2 = 0

for i in lst:
  sum1 += (i-num)**2
  sum2 += (i-num+1)**2
  
if sum1 < sum2:
  print(sum1)
else:
  print(sum2)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
mini = 10000000000000
for i in range(x[0],x[-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(' ')))
distlist = [10000] * 101
for P in range(1, 101):
    dist = 0
    for Xi in X:
        dist += (Xi - P) ** 2
    distlist[P] = dist
print(min(distlist))

Submission status: Wrong Answer

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

a=sum(x)//n+1

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

print(m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from statistics import mean
import math

def solve(N: int, X: "List[int]"):
    p = math.ceil(mean(X))
    r = 0
    for x in X:
        r += (x-p)**2

    return r


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, X))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
X = [int(x) for x in input().split()]
ans = 9999999999
su = 0

X.sort()

xm = max(X)

for i in range(xm):
  for j in range(N):
    su += (X[j]-i)**2
  ans = min(ans, su)
  su = 0


print(int(math.floor(ans)))

Submission status: Wrong Answer

Solution code:
import itertools

N = input()
# n, r = map(int, input().split())
# p = list(map(int, input().split()))
x = input().split()
# S = [int(input()) for i in range(int(n))]
summ =0
ave =0

for ii in x:
    ave+=int(ii)

ave = -(-ave // int(N))

for i in x:
    summ+= (int(i) - ave)**2

print(summ)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=list(map(int,input().split()))
r=0
for i in range(max(L)):
    b=0
    for j in range(n):
        b+=(L[j]-i)**2
    if i==0 or b<r:
        r=b
print(r)

Submission status: Wrong Answer

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

M = max(X)
m = min(X)
total = [0] * (M - m + 1)
for i in range(M - m + 1):
    for j in range(N):
        total[i] += (X[j] - i) ** 2

print(min(total))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import pvariance, mean
from math import ceil


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

print(ceil(pvariance(X) * n))

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

from collections import defaultdict

n = int(input())
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(s[0], s[-1]):
    l = sum([int(pow(x - p, 2)) for x in s])

    if l < ans:
        ans = l

print(ans)

Submission status: Wrong Answer

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

p = 100 * 100
sum = 0

for i in range(100):
    sum = 0
    for j in range(N):
        sum = sum + (A[j] - i) * (A[j] - i)
    if sum < p:
        p = sum

print(str(p))

Submission status: Wrong Answer

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

min = 0
for i in range(max):
	sum = 0
	for j in range(N):
		sum += (X[j] - i) ** 2
	if (i == 0):
		min = sum
	elif (min > sum):
		min = sum
print(min)

Submission status: Wrong Answer

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

phy = []
tmp = 0
max = 0
count = 0

for i in range(101):
    phy.append(i*i)

for j in range(1,x[n-1]):
    for k in range(n):
        tmp += phy[abs((j-x[k]))]
    if(max > tmp or count == 0):
        max = tmp
    count += 1
    tmp = 0

print(max)

Submission status: Wrong Answer

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

mx = 100010001000
for i in range(1, n+1):
    s = 0
    for j in range(n):
        xj = X[j]
        s += (xj - i)**2
        # print(xj, i, (xj - i)**2, s)
    # print(s)
    if s < mx:
        mx = s
print(mx)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(min(X),max(X)):
    sum_pw = 0
    for x in X:
        sum_pw += (i-x)**2
    if sum_pw < min_pw:
        min_pw = sum_pw

print(min_pw)

Submission status: Wrong Answer

Solution code:
N = int(input().rstrip())

A = [int(n) for n in input().rstrip().split(' ')]

ans = 0
for i in range(len(A)):
  ans += (A[i]-N)**2

print(ans)

Submission status: Wrong Answer

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

p = sum(x) // n

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

print(result)

Submission status: Wrong Answer

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

for i in range(min(X),max(X)):
    cnt = 0
    for j in X:
        cnt += (j - i)**2
    ans = min(ans,cnt)
print(ans)

Submission status: Wrong Answer

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

point = math.ceil(sum(list)/N)

ans_list = []
for item in list:
  ans_list.append((point - item)**2)

print(sum(ans_list))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]

ans = 100 * 100
tmp = 0
for i in range(-1000, 1001): #iは集会を開く場所
    for j in range(n):
        tmp += pow(x[j] - i, 2)
    if ans > tmp:
        ans = tmp
    tmp = 0
print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
X = [int(x) for x in input().split()]
ans = 9999999999
su = 0

X.sort()

xm = max(X)

for i in range(xm):
  for j in range(N):
    su += (X[j]-i)**2
  ans = min(ans, su)
  su = 0


print(ans)

Submission status: Wrong Answer

Solution code:
N,*X=map(int,open(0).read().split())
X.sort()
P = (sum(X)+X[0]) // N
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()))
import math
P = sum(X)/len(X)
P = math.ceil(P)
count = 0
for i in range(N):
  count += (X[i] - P)**2
print(math.ceil(count))

Submission status: Wrong Answer

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

sowa=0
ans=[]
for p in range(0,max(X)):
    for i,x in enumerate(X):
        tairyoku=(x-p)**2
        sowa+=tairyoku
    ans.append(sowa)
    # print(sowa)
    sowa=0
print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

minans = float('inf')

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

m = int(np.max(X))

for i in range(m):
	ans = int(np.sum((X-i) ** 2))
	if ans < minans:
		minans = ans

print(minans)