Problem:


Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354



Sample input:
2
1 4


Sample output:
5

Submission status: Runtime Error

Solution code:
n = int(input())
x_list = list(map(int, input().split()))
ans_list = [sum([(x - p) ** 2 for x in x_list]) for p in range(min(x_list), max(x_list)) + 1]
print(sorted(ans_list)[0])

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
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: Runtime Error

Solution code:
n = int(input())
x = sorted(list(map(int,input().split())))
li = []
cost = 0
for i in range(x[0],x[-1],1):
    cost = 0
    for b in x:
        cost += (b-i)**2
    li.append(cost)
print(min(li))

Submission status: Runtime Error

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)
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: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
cost = float("inf")
for i in range(101):
    cost = min(np.sum((X - i) ** 2))
print(cost)

Submission status: Runtime Error

Solution code:
import numpy as np
 
def resolve():
    input()
    x = list(map(int, input().split()))
    m = int(round(np.mean(x)))
    sum = 0
    for val in x:
        sum += (val - m) ** 2
    print(sum)
 
if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

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

print(min)

Submission status: Runtime Error

Solution code:
n = int(input())
index = list(map(int, input().split()))
energy = []
for p in range(min(index), max(index)):
    sum = 0
    for xi in index:
        sum += (xi-p)**2
    energy.append(sum)
print(min(energy))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
d = []
for i in range(min(x), max(x)):
  a = 0
  for j in x:
    a += (j - i)**2
#    print("({}-{})**2={}".format(j,i,(j - i)**2))
  d.append(a)
print(min(d))

Submission status: Runtime Error

Solution code:
M = 10**9 + 7
n, a, b = map(int, input().split())
r = (pow(2, n, M) - 1) % M
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    r = (r - c * pow(f, M - 2, M)) % M
print((r - c * pow(f, M - 2, M) % M))

Submission status: Runtime Error

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

b = 0
for i in range(min(x), max(x)):
  a = 0
  for j in x:
    a += (i - j)**2
#    print("({}-{})**2={}".format(j,i,(j - i)**2))
  d.append(a)
print(min(d))

Submission status: Runtime Error

Solution code:
M = 10**9 + 7
n, a, b = map(int, input().split())
r = (pow(2, n, M) - 1) % M
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    r = (r - c * pow(f, M - 2, M)) % M
print((r - c * pow(f, M - 2, M) % M)

Submission status: Runtime Error

Solution code:
N = int(input())
X=list(map(int, input().split())) 
print(X)
X_max = max(X)
X_min = min(X)

answerlist = []
for i in range(X_min,X_max):
  newX = [(n-i)**2 for n in X]
  print(newX)
  total = sum(newX)
  answerlist.append(total)
  
print(min(answerlist))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
people=[]
cost=[]

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

Submission status: Runtime Error

Solution code:

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

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

print(min(a))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = [input() for i in range(N)]

Xi = np.array(X)
P = (np.sum(X))/N
P = int(P)

Ei_1 = (Xi - P)*(Xi - P)
Ei_2 = (Xi - (P+1))*(Xi - (P+1))

E1 = np.sum(Ei_1)
E2 = np.sum(Ei_2)

if E1<E2 or E1==E2:
    print(E1)
if E2<E1:
    print(E2)

Submission status: Runtime Error

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

p0 = math.floor(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: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
  s=int(input())
  l.append(s)
 
 
a=int(round(sum(l)/n))
k=0
for j in l:
  k = k + (j-a)**2
print(k)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
  s=int(input())
  l.append(s)
 
 
a=round(sum(l)/n)
k=0
for j in l:
  k = k + (j-a)**2
print(k)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
  s=int(input())
  l.append(s)
 
 
a=round(sum(l)/n)
k=0
for j in range(n):
  k = k + (l[j]-a)**2
print(k)

Submission status: Runtime Error

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

for i in range(n):
    a = list((x[n]-n)**2) 

print(sum(a))

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
imax=int(max(x))
imin=int(min(x))
lis=[]
re=0
for k in range(imin,imax+1):
  for i in x:
    re=re+(x[i]-k)**2
  lis.append(re)
  re=0
print(min(lis))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
  s=int(input())
  l.append(s)
 
 
a=round(sum(l)/n)
k=0
for j in range(n):
  k+=(l[j]-a)**2
 
print(k)

Submission status: Runtime Error

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

def m(x, p):
  a = (x - p)**2
  return a
for i in range(min(x), max(x)):
  b = 0
  for j in x:
    b += m(j,i)
  d[i]=[b]
print(min(d.values())[0])

Submission status: Runtime Error

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

def m(x, p):
  a = (x - p)**2
  return a
#d.setdefault(j, []).append([i, j, m(i,j)])
for i in range(min(x), max(x)):
  b = 0
  for j in x:
    b += m(j,i)
  d[i]=[b]
print(min(d.values())[0]

Submission status: Runtime Error

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

for i in X:
    ans = ans + (N-i)**2

print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
cen = sorted(X)[int(-(sorted(len(X)/2)))]
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
            all = False
ans = 0
for b in X:
    ans = ans + (b-cen)**2
if all == True:
    ans = 0
    print(ans)
else:
    print(ans)

Submission status: Runtime Error

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

X_max = max(X)
X_min = min(X)

answerlist = []
for x in range(X_min,X_max):
  newX = [(n-x)^2 for n in X]
  sum = sum(str(newX))
  answerlist.append(sum)
  
print(max(answerlist))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
cen = sorted(X)[-(sorted(int(len(X)/2)))]
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
            all = False
ans = 0
for b in X:
    ans = ans + (b-cen)**2
if all == True:
    ans = 0
    print(ans)
else:
    print(ans)

Submission status: Runtime Error

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

X_max = max(X)
X_min = min(X)

answerlist = []
for x in range(X_min,X_max):
  newX = [(n-x)^2 for n in X]
  sum = sum(newX)
  answerlist.append(sum)
  
print(max(answerlist))

Submission status: Runtime Error

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))
print(min(resultList))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import statistics
from scipy.stats.mstats import gmean

N=int(input())
X=list(map(int,input().split()))
X.sort()
import sympy as sym
sym.init_printing()
(x, y) = sym.symbols("x, y")

sig=0
for i in range(N):
    sig+=X[i]

sig_2=0
for i in range(N):
    sig_2+=X[i]**2

min=10**10
med=X[0]
while True:
    sum=N*med**2-2*med*sig+sig_2

    if sum<min:
        min=sum
        prev=sum
        med+=1
    else:
        break

print(prev)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
cen = sorted(X)[-(sorted(len(X)/2))]
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
            all = False
ans = 0
for b in X:
    ans = ans + (b-cen)**2
if all == True:
    ans = 0
    print(ans)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
num = int(input())
ns = input().split(" ")
bcl = list()
ccl = list()
no = 0
minp = int(min(ns))
maxp = int(max(ns))
ntwo = minp
nsmo = int(len(ns))
def iwd(la, ntwo, no):
  acl = ""
  acl = list()
  for adc in range(la):
    an = int(ns[no]) - int(ntwo)
    swq = int(an) ** 2
    acl.append(swq)
    no+=1
  return sum(acl)
for dds in range(minp, maxp):
  ret = iwd(nsmo, ntwo, no)
  ccl.append(ret)
  ntwo+=1
print(min(ccl))

Submission status: Runtime Error

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

N = int(input())
X = [int(x) for x in input().split()]
MAX = max(X)
res = []
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: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

n, a, b=map(int, input().split())
mod = 10**9+7

L=[math.factorial(n) % mod // (math.factorial(n - i) % mod * math.factorial(i) % mod) for i in range(1,n+1) if i != a if i != b]
print(sum(L) % mod)

Submission status: Runtime Error

Solution code:
num = int(input())
ns = input().split(" ")
bcl = list()
ccl = list()
no = 0
minp = int(min(ns))
maxp = int(max(ns))
ntwo = minp
print(minp)
print(maxp)
print(ns)
print(no)
nsmo = int(len(ns))
print(nsmo)
def iwd(la, ntwo, no):
  acl = ""
  acl = list()
  for adc in range(la):
    print(no)
    an = int(ns[no]) - int(ntwo)
    swq = int(an) ** 2
    acl.append(swq)
    no+=1
  return sum(acl)
for dds in range(minp, maxp):
  ret = iwd(nsmo, ntwo, no)
  ccl.append(ret)
  ntwo+=1
print(min(ccl))

Submission status: Runtime Error

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

sum = 0
max = 0
minn = 100

for i in range(n):
  for j in range(100):
    sum += (x[j]-i)**2
  if min > sum:
    min = sum

print(min)

Submission status: Runtime Error

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

lis_X_sorted = sorted(lis_X)

def calc_dif_sq(a,b):
    return (a-b)**2

if N == 1:
    ans = 0
else :
    res = []
    for p in range(lis_X_sorted[0],lis_X_sorted[-1]):
        tmp = sum(list(map(lambda x:calc_dif_sq(x, p), lis_X_sorted)))
        res.append(tmp)
    ans = min(res)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
l1 = min(x)
l2 = max(x)
ans = 0
for i in range(l1, l2+1):
    for j in x:
        sum += (i-j)**2
    if sum > ans:
        ans = sum
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]):
    b=0
    for j in range(0,N):
        if i-X[j]>10**5:
            break
        b+=(i-X[j])**2
    a.append(b)
print(min(a))

Submission status: Runtime Error

Solution code:

N=int(input())
X=list(map(int,input().split()))
X.sort()
#print(X)
med=int(statistics.median(X))
#print(med)

"""
if med-math.floor(med)>math.ceil(med)-med:
    val=math.ceil(med)
else:
    val=math.floor(med)
"""
min=10**10
sum=0
#print(X)
while True:
    sum=0
    for i in range(N):
        sum+=(X[i]-med)**2
    if sum<min:
        min=sum
        prev=sum
        med+=1
    else:
        break

print(prev)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdin

n = int(input())
x_list_str = stdin.readline().rstrip().split()
x_list = [int(i) for i in x_list_str]

# 体力のリスト
sum_hp_list = []

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

for i in range(min_x, max_x):
    sum_hp = 0
    for x in x_list:
        sum_hp += (x-i)**2
    sum_hp_list.append(sum_hp)

print(min(sum_hp_list))

Submission status: Runtime Error

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

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

E = [0 for i in range(max(K)-min(K))]

for i in range(max(K)-min(K)):
    E[i] = 0
    for x in K:
        E[i] += (x-(i+min(K)))**2

print(min(E))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
  s=int(input())
  l.append(s)


a=round(sum(l)/n)
k=0
for j in range(n):
  k+=(l[j]-a)**2

print(k)

Submission status: Runtime Error

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

p_l = int(sum(x) / n)
p_h = p_l + 1

ans_l = 0
ans_h = 0
for x_i in x:
	ans_l = ans_l + (x_i - p_l) * (x_i - p_l)
    ans_h = ans_h + (x_i - p_h) * (x_i - p_h)

if ans_l < ans_h:
  ans = ans_l
else:
  ans = ans_h
print(ans)

Submission status: Runtime Error

Solution code:
N = input()
L = list(map(int, input().split()))
 
mean = sum(L)/N
r = round(mean)
print(mean)

Submission status: Runtime Error

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

lis_X_sorted = sorted(lis_X)

def calc_dif_sq(a,b):
    return (a-b)**2

res = []
for p in range(lis_X_sorted[0],lis_X_sorted[-1]):
    tmp = sum(list(map(lambda x:calc_dif_sq(x, p), lis_X_sorted)))
    res.append(tmp)
ans = min(res)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int,input().split())))
P =np.arange(X[0],X[N-1],1)
b = []
p=0
for j in range(N):
	p=P[j]
	a=0
	for i in range(N):
		a += (X[i]-p)**2
	b.append(a)
print(min(b))

Submission status: Runtime Error

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

mean = sum(L)/N
r = round(mean)
La = list(map(lambda x: (x - r)^2, L))

result = sum(La)

print(result)

Submission status: Runtime Error

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

p_l = int(sum(x) / n)
p_h = p_l + 1

ans_l = 0
for x_i in x:
	ans_l = (x_i - p_l) * (x_i - p_l)
    ans_h = (x_i - p_h) * (x_i - p_h)

if ans_l < ans_h:
  ans = ans_l
else:
  ans = ans_h
print(ans)

Submission status: Runtime Error

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

lis_X_sorted = sorted(lis_X)

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

res = []
for p in range(lis_X_sorted[0],lis_X_sorted[-1]):
    tmp = sum(map(lambda x:calc_dif_sq(x, p), lis_X_sorted))
    res.append(tmp)
ans = min(res)
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
l = input().split()
data = []
for i in range(int(min(l)), int(max(l))):
    sum_l = 0
    for j in range(len(l)):
        sum_l = sum_l + (int(l[j])-i)**2
    data.append(sum_l)

print(min(data))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int,input().split())))
P =np.arange(X[0],X[N-1],1)
b = []
p=0
for j in range(N):
	p=P[j]
	a=0
	for i in range(N):
		a += (X[i]-p)**2
	b.append(a)

print(min(b))

Submission status: Runtime Error

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

k.sort()

ave = round(sum(k) / len(k) )

#print(ave)

def calc_pow(n):
    i = pow(n - ave, 2) 
    return i
  
j = map(calc_pow, k)

print(sum(j))

Submission status: Runtime Error

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

p = sum(x) / n

ans = 0
for x_i in x:
	ans = (x_i - p) * (x_i - p)
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = input()
x = input().split()
n = int(n)
x = list(map(int,x))
x = np.array(x)
maxed = np.max(x)
cand = []

for p in range(1,maxed):
    xp = (x - p) ** 2
    cand.append(np.sum(xp))
y = np.min(cand)
print(y)

Submission status: Runtime Error

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

mean = sum(L)/N
r = round(mean)
L_abs = list(map(lambda x: (x - r)^2, L))

result = sum(L_abs)

print(result)

Submission status: Runtime Error

Solution code:
import statistics
n=int(input())
x=[int(_) for _ in input().split()]
mid=int(statistics.mean(x))
mmid=mid-1
cnt=0
cntm=0
for i in range(len(x)):
  cnt+= (x[i]-mid)**2
  cntm+=(x[i]-mmid)**2
print(min(cnt,cntm,cntp))

Submission status: Runtime Error

Solution code:

import sys
N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
if N == 1:
    print('0')
    sys.exit()
for i in range(min(X), max(X)):
    ans = 0
    for j in X:
        ans += (j - i) ** 2
    ans_list.append(ans)

print(min(ans_list))

Submission status: Runtime Error

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

t=1000000007

def mod(k):
    return k%t

def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

base=power_func(2,n,t)
    
print(mod(2*t+base-1-comb(n,a,t)-comb(n,b,t)))

Submission status: Runtime Error

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

mean = sum(L)/N
r = round(mean)
L_abs = map(lambda x: (x - r)^2, L)

result = sum(L_abs)

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
import math


def main():
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    hoge = np.array(x)
    fuga = hoge.std(ddof=1)
    result = 0

    for i in x:
        result += (i - fuga) ** 2
    print(math.ceil(result))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int,input().split())))
P =np.arange(X[0],X[N-1],1)
b = []
p=0
for j in range(N):
	p=P[j]
	a=0
	for i in range(N):
		a += (X[i]-p)**2
	b.append(a)
print(b)
print(min(b))

Submission status: Runtime Error

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

mean = sum(L)/N
r = round(mean)


L_abs = map(lambda x: (x - r)^2, L)

result = sum(L_abs)

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(int,input().split())
m = sum(X)//N
def fun(X,m):
  s = 0
  for i in X:
    s += (i-m)**2
  return s

print(min(fun(X,m),fun(X,m+1)))

Submission status: Runtime Error

Solution code:

N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
for i in range(min(X), max(X)):
    ans = 0
    for j in X:
        ans += (j - i) ** 2
    ans_list.append(ans)

print(min(ans_list))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

min_ = min(list)
max_ = max(list)

total = []
for i in range(min_, max_):
  length = 0
  for j in range(n):
  	length += (list[j] - i)**2
  total.append(length)
print(min(total))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

# 体力のリスト
sum_hp_list = []

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

for i in range(min_x, max_x):
    sum_hp = 0
    for x in x_list:
        sum_hp += (x-i)**2
    sum_hp_list.append(sum_hp)

print(min(sum_hp_list))

Submission status: Runtime Error

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

if N==1:
    print("0")
else:
    X_min=min(X_list)
    X_max=max(X_list)
    for i in range(X_min,X_max):
        sum_pow=0
        for j in range(N):
            sum_pow+=(X_list[j]-i)**2
        if i==X_min:
            min_pow=sum_pow
        if min_pow>sum_pow:
            min_pow=sum_pow
    print(min_pow)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int,input().split())))
P =np.arange(X[0],X[N-1],1)
b = []
p=0
for j in range(N):
	p=P[j]
	a=0
	for i in range(N):
		a += (X[i]-p)**2
	b.append(a)
print(b)
print(min(b))

Submission status: Runtime Error

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
for i in range(min(X), max(X)):
    ans = 0
    for j in X:
        ans += (j - i) * (j - i)
    ans_list.append(ans)

print(min(ans_list))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

N = input()
X = list(map(int, input().split()))
sum = 0
for a in X:
    sum = sum + a
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-C)**2
print(math.ceil(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]):
    b=0
    for j in range(0,N):
        b+=(i-X[j])**2
    a.append(b)
print(min(a))

Submission status: Runtime Error

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

res = 0
r = round(sum(x)/len(x))
for i in x:
    res +=(i-p)**2
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = mean(X)
print(a)
b = 0
for i in range(N):
    b +=(X[i]-a)**2
print(b)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = input()
data = []
for i in range(min(l), max(l)+1):
    sum_l = 0
    for j in range(len(l)):
        sum_l = sum_l + (l[j]-i)**2
    data.append(sum_l)

print(min(data))

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 10**9+7

N,a,b = map(int,input().split())

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

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

print(ans)

Submission status: Runtime Error

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

for i in range(1,100):
    sum_pow=0
    for j in range(N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

Submission status: Runtime Error

Solution code:
N = input()
X = list(map(int, input().split()))
sum = 0
for a in X:
    sum = sum + a
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-C)**2
print(int(ans))

Submission status: Runtime Error

Solution code:
N = input()
X = [int(input()) for i in range(int(N))]
res = 0
for i in range(len(X)-3):
    res += pow((int(X[i])-int(N)),2)
print(res)

Submission status: Runtime Error

Solution code:
# coding: utf-8


def main():
    n = int(input())
    point = list(map(int, input().split(' ')))    

    max_point = max(point)
    min_point = min(point)
    min_sums = []
    for p in range(min_point, max_point + 1):
        sum_ = 0
        for x in numbers:
            sum_ += (x - p) ** 2
        min_sums.append(sum_)

    print(min(min_sums))

    return 0


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

# 体力のリスト
sum_hp_list = []

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

for i in range(min_x, max_x):
    sum_hp = 0
    for x in x_list:
        sum_hp += (x-i)**2
    sum_hp_list.append(sum_hp)

print(min(sum_hp_list))

Submission status: Runtime Error

Solution code:
N = input()
X = list(map(int, input().split()))
sum = 0
for a in X:
    sum = sum + a
C = sum/N
for b in X:
    ans = (b-C)**2
print(int(ans))

Submission status: Runtime Error

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


def num(N,X):
    number = 0
    for x in X:
        num = x-N

        num2 = num**2

        number += num2

    return number
    
kekka = str(num(N,X))
print(kekka)

Submission status: Runtime Error

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

min_ = min(list)
max_ = max(list)

total = []
for i in range(min_, max_):
  length = 0
  for j in range(n):
  	length += (list[j] - i)**2
  total.append(length)
print(min(total))

Submission status: Runtime Error

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

X_min=min(X_list)
X_max=max(X_list)
for i in range(X_min,X_max):
    sum_pow=0
    for j in range(N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

Submission status: Runtime Error

Solution code:
from sys import stdin


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


def min_cost(n, data):
    cost = 1_000_000
    for p in range(1, 100 + 1):
        tmp_cost = sum([calc_cost(p, x) for x in data])
        if tmp_cost < cost:
            cost = tmp_cost
    return cost


def main():
    N = [int(x) for x in stdin.readline().rstrip()]
    CORP = [int(x) for x in stdin.readline().rstrip().split()]
    cost = min_cost(N, CORP)
    print(cost)


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=2
X_list=list(1,4)

X_min=min(X_list)
X_max=max(X_list)
for i in range(X_min,X_max):
    sum_pow=0
    for j in range(N):
        sum_pow+=(X_list[j]-i)**2
    if i==X_min:
        min_pow=sum_pow
    if min_pow>sum_pow:
        min_pow=sum_pow
print(min_pow)

Submission status: Runtime Error

Solution code:
def resolve():
    import statistics
    n = input()
    x = list(map(int, input().split()))
    m = round(statistics.mean(x))
    sum_val = 0
    for val in x:
        sum_val += (val - m) ** 2

    print(sum_val)

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
n = int(input())
x = input().split(" ")
x = [int(i) for i in x]
answer = 0
for index,i in enumerate(x):
    answer += pow((i - index), 2)
print(answer)

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

Submission status: Runtime Error

Solution code:
from sys import stdin


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


def min_cost(n, data):
    cost = 1_000_000
    for p in range(1, 100 + 1):
        tmp_cost = sum([calc_cost(p, x) for x in data])
        if tmp_cost < cost:
            cost = tmp_cost
    return cost


def main():
    N = [int(x) for x in stdin.readline().rstrip()]
    CORP = [int(x) for x in stdin.readline().rstrip().split()]
    cost = min_cost(N, CORP)
    print(cost)


if __name__ == "__main__":
    main()