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:
from statistics import median

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

min_sum = 10**9
for location in range(min(p), max(p)):
    sum = 0
    for i in range(n):
        sum += (p[i]-location)**2
    if sum < min_sum:
        min_sum = sum

print(min_sum)

Submission status: Wrong Answer

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

low = min(X_list)
high = max(X_list)

minimum = 99999999999999
for p in range(low,high) :
    tmp = 0
    for x in X_list :
        tmp += pow(x-p,2)
    
    if (tmp < minimum) :
        minimum = tmp

if (minimum == 99999999999999) :
    print(high)
else :
    print(minimum)

Submission status: Wrong Answer

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

low = min(X_list)
high = max(X_list)

minimum = high
for p in range(low,high) :
    tmp = 0
    for x in X_list :
        tmp += pow(x-p,2)
    
    if (tmp < minimum) :
        minimum = tmp

print(minimum)

Submission status: Wrong Answer

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

low = min(X_list)
high = max(X_list)

minimum = 999999999999
for p in range(low,high) :
    tmp = 0
    for x in X_list :
        tmp += pow(x-p,2)
    
    if (tmp < minimum) :
        minimum = tmp

print(minimum)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = input().split()
result = []
for i in range(len(X)):
    result.append((int(X[i]) - 2)**2)
print(sum(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = int(sum(x)**2)
current = 0
for p in range(min(x),max(x)):
    for i in range(len(x)):
        current += int((x[i] - p)**2)
    if(current < ans):
        ans = current
    current = 0
print(ans)

Submission status: Wrong Answer

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

    x_min = min(x_list)
    x_max = max(x_list)
    hp_min = 10**18

    for i in range(x_min, x_max):
        tmp_hp = 0
        for j in x_list:
            tmp_hp += (j - i)**2
        if (hp_min is None) or (tmp_hp < hp_min):
            hp_min = tmp_hp

    print(hp_min)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

    x_min = min(x_list)
    x_max = max(x_list)

    hp_min = None

    for i in range(x_min, x_max):
        tmp_hp = 0
        for j in x_list:
            tmp_hp += (j - i)**2
        if (hp_min is None) or (tmp_hp < hp_min):
            hp_min = tmp_hp

    print(hp_min)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = sorted(list(map(int, input().split(" "))))
min = -1
for i in range(X[0], X[-1]):
  s = sum((x - i) ** 2for x in X)
  if min == -1:
    min = s
  if s < min:
    min = s
print(min)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
res = 0
for i in range(101):
  sum = 0
  if i == 0:
    pass
  else:
    for j in range(n):
      sum = sum + (li[j]-i)**2
    if res == 0:
      res = sum
    elif res > sum:
      res = sum
print(res)

Submission status: Wrong Answer

Solution code:
#156c
n=int(input())
x=[int(x) for x in input().split()]
min_t=[]
for i in range(0,max(x)):
    tmp=0
    for j in x:
        tmp +=(j-i)**2
    min_t.append(tmp)    
print(min(min_t))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
res = 10000
for i in range(101):
  sum = 0
  if i == 0:
    pass
  else:
    for j in range(n):
      sum = sum + (li[j]-i)**2
    if res > sum:
      res = sum
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

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

X.sort()
P=0
print(X)
min=10000000000
while P <= X[-1]:
    power=0
    for j in range(len(X)):
        power=power+(X[j]-P)**2

    if power<=min:
        min=power

    P=P+1


print(min)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

X.sort()
i=X[0]
print(X)
min=10000000000
while i <= X[-1]:
    power=0
    for j in range(len(X)):
        power=power+(X[j]-i)**2

    if power<=min:
        min=power

    i=i+1


print(min)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

X.sort()
i=X[0]

min=10000000000
while i < X[-1]:
    power=0
    for j in range(len(X)):
        power=power+(X[j]-i)**2

    if power<=min:
        min=power

    i=i+1
    

print(min)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  1 14:34:07 2020

@author: Kanaru Sato
"""

import sys

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

address.sort

ans = 0
total = sys.maxsize

for place in list(range(address[0],address[n-1]+1)):
    tmp = 0
    for i in range(n):
        tmp += (address[i]-place)**2
    if tmp <= total:
        total = tmp

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
count = 1000000000
sumX = 0
l = max(x) //2
for j in range(l):
    sumX = 0
    for k in range(n):
        sumX +=(x[k]-(j+1)) ** 2
    count = min(sumX,count)
print(count)

Submission status: Wrong Answer

Solution code:
import os

def main():
    count = int(input())
    int_list = list(map(int, input().split()))
    int_min,int_max = min(int_list),max(int_list)
    score = 0

    int_avg = int(sum(int_list) / len(int_list)) + 1
    print(int_avg)
    for i in int_list:
        score += (i - int_avg)**2
    print(score)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import os

def main():
    count = int(input())
    int_list = list(map(int, input().split()))
    int_min,int_max = min(int_list),max(int_list)
    score = 0

    int_avg = int(sum(int_list) / len(int_list)) 
    print(int_avg)
    for i in int_list:
        score += (i - int_avg)**2
    print(score)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import os

def main():
    count = int(input())
    int_list = list(map(int, input().split()))
    int_min,int_max = min(int_list),max(int_list)
    score = 0

    int_avg = int_max // 2
    print(int_avg)
    for i in int_list:
        score += (i - int_avg)**2
    print(score)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import statistics
import math

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

p = math.ceil(statistics.mean(X))
print(sum([(x - p) ** 2 for x in X]))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    x = list(map(int, input().split()))
    xx = sum(x)
    p = xx//N
    if (2*N*p+N-2*xx) < 0:
        ans = p+1
    else :
        ans = p
    kyori = 0
    for i in range(N):
        kyori += (x[i]-ans)**2
    print(kyori)

Submission status: Wrong Answer

Solution code:
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(n_list[0], n_list[-1]+1):
    sum = 0
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)

Submission status: Wrong Answer

Solution code:
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(n_list[0], n_list[-1]+1):
    sum = 0
    print(p)
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)

Submission status: Wrong Answer

Solution code:
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(1, n_list[-1]+1):
    sum = 0
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)

Submission status: Wrong Answer

Solution code:
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(n_list[-1]):
    sum = 0
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)

Submission status: Wrong Answer

Solution code:
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000

for i in range(n_list[-1]):
    sum = 0
    for j in n_list:
        sum += (j-i)**2

    if sum<min_num:
        min_num = sum

print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
sav = float("inf")
for i in range(min(X), max(X)):
    Xe = map(lambda x: abs(x - i) ** 2, X)
    health = sum(Xe)
    if sav > health:
        sav = health

print(sav)

Submission status: Wrong Answer

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

xpos = -(-sum(X)//N)
Xe = map(lambda x:abs(x-xpos)**2, X)
print(sum(Xe))

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 10**9+7
X_list = list(map(int,input().split()))
for P in range(min(X_list),max(X_list)):
    ans = min(ans,sum([(i-P)**2 for i in X_list]))
print(ans)

Submission status: Wrong Answer

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

INF = 10**9
m = INF
for x in range(max(X)):
    temp = 0
    for i in range(N):
        temp += (x - X[i])**2
    if m > temp:
        m = temp
print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
x = np.array(list(map(int,input().split())))
r = np.full(100, 100 * n)

for p in range(100):
    r[p] = np.sum((x - p + 1)**2)
print(np.min(r))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = input()
x = np.array(list(map(int,input().split())))
# x = np.array(x)
r = np.full(100, 100)

for p in range(100):
    r[p] = np.sum((x - p + 1)**2)
print(np.min(r))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = []
s = input()
x = s.split()
y = len(x)
summ1 = 0
summ2 = 0
sr = 0
setx = set(x)
h = len(setx)
if N == 1:
    print("0")
else:
    if h == 0:
        print("0")
    else:
        for i in range(y):
            x[i] = int(x[i])
            sr = sr + x[i]
        PMA = (sr//N)+1
        PMM = sr//N
        print(PMA, PMM)
        for i in range(y):
            summ1 = summ1 + ((x[i]-PMA)*(x[i]-PMA))
        for i in range(y):
            summ2 = summ2 + ((x[i] - PMM) * (x[i] - PMM))
        if summ2 > summ1:
            print(summ1)
        else:
            print(summ2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = []
s = input()
x = s.split()
y = len(x)
summ1 = 0
summ2 = 0
sr = 0
setx = set(x)
h = len(setx)
if N == 1:
    print("0")
else:
    if h == 0:
        print("0")
    else:
        for i in range(y):
            x[i] = int(x[i])
            sr = sr + x[i]
        PMA = math.ceil(sr/N)
        PMM = math.floor(sr/N)
        print(PMA, PMM)
        for i in range(y):
            summ1 = summ1 + ((x[i]-PMA)*(x[i]-PMA))
        for i in range(y):
            summ2 = summ2 + ((x[i] - PMM) * (x[i] - PMM))
        if summ2 > summ1:
            print(summ1)
        else:
            print(summ2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = []
s = input()
x = s.split()
y = len(x)
summ1 = 0
summ2 = 0
sr = 0
setx = set(x)
h = len(setx)
if N == 1:
    print("0")
else:
    if h == 0:
        print("0")
    else:
        for i in range(y):
            x[i] = int(x[i])
            sr = sr + x[i]
        PMA = math.ceil(sr//N)
        PMM = math.floor(sr//N)
        for i in range(y):
            summ1 = summ1 + ((x[i]-PMA)*(x[i]-PMA))
        for i in range(y):
            summ2 = summ2 + ((x[i] - PMM) * (x[i] - PMM))
        if summ2 > summ1:
            print(summ1)
        else:
            print(summ2)

Submission status: Wrong Answer

Solution code:
# 156-C
N = int(input())
X = [int(x) for x in input().split()]
cnt = 1
ans = 100000000
A = 0
while cnt <= 100:
  cnt += 1
  i = 0
  while i < N:
    A += (int(X[i])-cnt)*(int(X[i])-cnt)
    i += 1
  ans = min(ans, A)
  A = 0
print (ans)

Submission status: Wrong Answer

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

w = 0
min_w = 10**5
for p in range(1,n+1):
    for i in range(n):
        w += (x[i] - p)**2
    min_w = min(w,min_w)
    w = 0
print(min_w)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = input()
    n = int(cin.split(" ")[0])
    cin = input()
    xs = np.array([], dtype="int")

    for i in range(n):
        xs = np.append(xs, int(cin.split(" ")[i]))
    print(xs)
    cout = main(n, xs)
    print(cout)

Submission status: Wrong Answer

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

p = int(sum(x_list)/n)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def f(t,x):
  s = 0
  for i in range(len(x)):
    s += (x[i]-t)**2
  return s

l = min(x)
u = max(x)
m = float('inf')
for i in range(l,u):
  if m > f(i,x):
    m = f(i,x)
print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
X = [int(_) for _ in input().split()]
b = np.polyfit([0 for _ in range(N)], X, 0) #切片だけ
# y = ax + b
P = round(b[0])
res = [(x-P)*(x-P) for x in X]
print(sum(res))

Submission status: Wrong Answer

Solution code:
import math
a=int(input())
s=list(map(int,input().split()))
p=sum(s)/a
psum=0
for i in s:
    psum+=(i-p)**2
print(math.ceil(psum))

Submission status: Wrong Answer

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

min_energy = None

for p in range(x[0], x[-1]+1):
    energy = 0
    for x_i in x:
        energy += (x_i - p) ** 2
    if min_energy is None:
        min_energy = energy
    else:
        min_energy = min(energy, min_energy)

print(min_energy)

Submission status: Wrong Answer

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

min_energy = None

for p in range(x[0], x[-1]+1):
    energy = 0
    for x_i in x:
        energy += (x_i - p) ** 2
    if min_energy is None:
        min_energy = energy
    else:
        min_energy = min(energy, min_energy)

print(min_energy)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X_s = tuple(map(int,input().split()))
MIN = 10**5
for i in range(1,101):
  SUM = sum(tuple(map(lambda x:(x-i)**2, X_s)))
  if MIN > SUM:
    MIN = SUM
print(MIN)

Submission status: Wrong Answer

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

min_cost = float('inf')
for p in X:
  cost = 0
  for xi in X:
    cost += (p - xi) * (p - xi)
  if cost < min_cost:
    min_cost = cost

print(min_cost)

Submission status: Wrong Answer

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

mi = float('inf')

for i in range(max(x)):
    res = 0
    for j in range(n):
        res += (x[j] - i)**2
    if res <= mi:
        mi = res

print(mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[i**2 for i in a]
#sum_=sum(b)-2*p*sum(a)+n*p**2
c=sum(a)
def tai(p):
    return n*p**2-2*p*c
d=[]
for i in range(min(a),max(a)+1):
    d.append(tai(i+1))
print(min(d)+sum(b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
li=list(map(int,input().split()))
li.sort()

mi,mx=li[0],li[-1]
ans=10**9
t=10**9
if mi==mx:
    print(0)
    sys.exit()

for i in range(mi,mx):
    ans=min(ans,t)
    t=0
    for j in (li):
       try:
           t+=(li[j]-i)**2
       except:
           print(j)
       
print(ans)

Submission status: Wrong Answer

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

mi,mx=li[0],li[-1]
ans=10**9
t=10**9
for i in range(mi,mx):
    ans=min(ans,t)
    t=0
    for j,item in enumerate (li):
       try:
           t+=(li[j]-i)**2
       except IndexError:
           print(j)
       
print(ans)

Submission status: Wrong Answer

Solution code:
def calculate_hp(n,x):
  total_hp = 0
  xlist = [int(s) for s in x]
  for i in xlist:
    hp = (i-n) ** 2
    total_hp+=hp    
  return total_hp
def main():
  n = int(input())
  x = input().split()
  total_hp=calculate_hp(n, x)
  print(total_hp)

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

ave = 0
for val in x:
    ave += val

loc = int(ave / n)
if ave - loc > 0.5:
    loc += 1

ans = 0
for val in x:
    ans += (val - loc) * (val - loc)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

ave = 0
for val in x:
    ave += val

loc = int(ave / n)
if ave - loc > 0.5:
    loc += 1

ans = 0
for val in x:
    ans += (val - loc)**2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

ave = 0
for val in x:
    ave += val

loc = int(ave / n)
if loc - ave > 0.5:
    loc += 1

ans = 0
for val in x:
    ans += (val - loc)**2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
X = LI()

# 距離の2乗の体力を消費
# 100ループすれば求まる

min_x = min(X)
max_x = max(X)

min_XP = 10**9
for p in range(min_x, max_x):
    XP = 0
    for x in X:
        XP += (x-p)**2
    if min_XP > XP:
        min_XP = XP
print(min_XP)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ave = sum(x)/len(x)
ans = 0
for i in range(len(x)):
	ans += (x[i]-ave)**2

temp = ans 
if ans//1 !=temp:
	print(int(ans//1+1))
else:
	print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
mi = 10**6
for i in range(1, n+1):
    tmp = 0
    for j in x:
        tmp += (i-j)**2
    mi = min(tmp, mi)
print(mi)

Submission status: Wrong Answer

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

def kyori(x,y):
    return (x-y)**2

ave=sum(X_list)//N
av2=ave+1
print(min([sum([kyori(x,ave) for x in X_list]),sum([kyori(x,av2) for x in X_list])]))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=int(sum(a)/len(a))
c=sum(a)
d=sum(map(lambda x:x**2,a))
if N-2*c<0:
  b=b+1
e=d+N*b*b-2*c*b
print(e)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=int(sum(a)/len(a))+1
c=sum(a)
d=sum(map(lambda x:x**2,a))
e=d+N*b*b-2*c*b
print(e)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    print("solve abc156 C")
    n = int(input())
    x = [int(i) for i in input().split()]
    min_x = round(sum(x) / n)
    ans = sum([(min_x - i)**2 for i in x])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x_lis = list(map(int, input().split()))
ans = 0
avg = sum(x_lis)/n
if avg - int(avg) >= 0.5:
    avg = int(avg) + 1
else:
    avg = int(avg)
print(avg)
for x in x_lis:
    ans += (x - avg)**2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
x = [int(e) for e in input().split()]
max_cost = float('inf')
for i in range(min(x), max(x)):
    cost = 0
    for j in x:
        cost = cost + (i - j)**2
    max_cost = min(cost, max_cost)
print(max_cost)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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


P = N[0]//2

suma = 0
for a in range(N[0]):
    suma = suma + (X[a] + P)**2

Q = (N[0]//2)+1
sumb = 0
for b in range(N[0]):
    sumb = sumb + (X[b] + Q)**2
if suma < sumb:
    print(suma)
else:
    print(sumb)

Submission status: Wrong Answer

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

p=(math.ceil(sum(X)/n))
cnt=0
for x in X:
  cnt += (x-p)**2
  
print(cnt)

Submission status: Wrong Answer

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

p=(sum(X)//n)+1
cnt=0
for x in X:
  cnt += (x-p)**2
  
print(cnt)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev

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

loc = int(mean(X))+1
i = 0
result = 0
for i in range(N):
    result = result + ((loc - X[i]) ** 2)
    i += 1
print(result)

Submission status: Wrong Answer

Solution code:
import statistics
import math

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

mean = math.ceil(statistics.mean(x))
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
def MinimumStamina(N, X_list):
  P = int(sum(X_list) / N)
  stamina = 0
  for i in range(N):
    X = X_list[i]
    stamina += X * X - 2 * P * X
  stamina += N * P * P
  return stamina

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

Submission status: Wrong Answer

Solution code:
def MinimumStamina(N, X_list):
  P = sum(X_list) / N
  stamina = 0
  for i in range(N):
    X = X_list[i]
    stamina += X * X - 2 * P * X
  stamina += N * P * P
  return stamina

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
x = list(map(int, input().split()))
 
n = len(x)
 
sum_a = 0
sum_b = 0
 
for xi in x:
  sum_a += xi * xi
  sum_b += xi
  
ans = sum_a - (sum_b*sum_b)/n
min_ans = 10**9
if ans > min_ans:
    ans = min_ans

print(math.ceil(ans))

Submission status: Wrong Answer

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

sum_a = 0
sum_b = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
 
s = 0
r = 0
for x in X:
  s += x*x
  r += x
rr = r*r
print(s-rr/N)

Submission status: Wrong Answer

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

s = 0
r = 0
for x in X:
  s += x*x
  r += x
print(s-r*r/N)

Submission status: Wrong Answer

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

s = 0
r = 0
for x in X:
  s += x*x
  r += x
print(s-r/N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
X.sort()
x_min=X[0]
x_max=X[N-1]
Min=10**10
for i in range(x_min,x_max+1):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
print(Min)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
X.sort()
x_min=X[0]
x_max=X[N-1]
Min=10**10
for i in range(x_min,x_max+1):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
print(X)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
X.sort()
x_min=X[0]
x_max=X[N-1]
Min=10**10
for i in range(x_min,x_max):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
print(Min)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
Min=10**10
for i in range(N):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
print(Min)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
Min=10**10
for i in range(N):
    p=0
    for j in range(N):
        p+=(X[j]-i-1)**2
    if Min>p:
        Min=p
    print(p)
print(Min)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
print(min_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
 for n in X:
   sum = sum +(n-P)**2
 if sum <= min_sum:
   min_sum = sum
 P = P + 1
print(min_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P =1
if P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
print(min_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P =1
if P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum  
print(min_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
Z = []
b = 0

for i in range(max(X)):
    for a in X:
        b = b + pow((a - i),2)
    Z.append(b)
    b = 0

print(min(Z))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
Z = []
b = 0

for i in range(X[N-1]+1):
    for a in X:
        b = b + pow((a - i),2)
    Z.append(b)
    b = 0

print(min(Z))

Submission status: Wrong Answer

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

mini, maxi = min(x), max(x)
min2, max2 = mini**2*n, maxi**2*n
ans = max2 if max2 > min2 else min2

for p in range(mini, maxi):
  suma = 0
  for z in x:
    suma += (z-p)**2
  if ans > suma:
    ans = suma
    
print(ans)

Submission status: Wrong Answer

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

mini, maxi = min(x), max(x)
min2, max2 = mini**2, maxi**2
ans = max2 if max2 > min2 else min2

for p in range(mini, maxi):
  suma = 0
  for z in x:
    suma += (z-p)**2
  if ans > suma:
    ans = suma
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
mx = max(a)
b = 0
ans = 0
answer = []
for x in range(int(mx)):
  for i in range(n):
    b = (int(a[i])-x)**2
    ans += b
  answer.append(ans)
  ans = 0
print(min(answer))