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: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    X = LI()
    ans = float("inf")
    for x in range(101):
        m = 0
        for xi in X:
            m += (xi-x)**2
        if m < ans:
            ans = m
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = 10**18
for i in range(1,101):
  p = 0
  for j in range(N):
    p += (i-X[j])**2
  ans = min(ans,p)
print(ans)

Submission status: Accepted

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
X = read_ints()


def ret_cost(X, P):
    return sum([(x - P) ** 2 for x in X])


ans = 10**10
for P in range(101):
    ans = min(ret_cost(X, P), ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xxx = list(map(int, input().split()))
ans = 10**10
for p in range(1, 101):
    tmp = sum((x - p) ** 2 for x in xxx)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = float('inf')
for i in range(1, 101):
    sumd = 0
    for x in X:
        sumd += (x - i) ** 2
    ans = min(ans, sumd)
print(ans)

Submission status: Accepted

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

ans = 10**9
for i in range(101):
    ans = min(ans, sum([ (i - pi)**2 for pi in person]))
print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x = na()

minc = 99999999999999999
for u in range(1, 101):
    cost = 0
    for v in x:
        cost += (v-u)*(v-u)
    minc = min(cost, minc)
print(minc)

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


N = I()
X = LMI()

p = sum(X) // N
ans1 = sum([(x - p) ** 2 for x in X])
ans2 = sum([(x - p - 1) ** 2 for x in X])
print(min(ans1, ans2))

Submission status: Accepted

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

ans=10**10

for i in range(100):
    p=i+1
    temp=0
    for j in range(N):
        temp+=(X[j]-p)**2
        
    ans=min(ans,temp)
    
print(ans)

Submission status: Accepted

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

ans = 100000000000
for i in range(a[0], a[-1]+1):
    tmp = 0
    for j in a:
        tmp +=  (j-i)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

y = sum(X)//N
c1 = 0
c2 = 0
for x in X:
    c1 += (x-y)**2
    c2 += (x-y-1)**2
print(min(c1, c2))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=10**12
for i in range(a[0],a[n-1]+1):
	p=0
	for j in range(n):
		p+=(a[j]-i)**2
	ans=min(ans,p)
print(ans)

Submission status: Accepted

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

ans = 1000000000000
for i in range(101):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans, temp)

print(ans)

Submission status: Accepted

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

ans = 10 ** 20
for i in range(1, 101):
    temp = 0
    for j in range(N):
        temp += (X[j] - i) ** 2
    ans = min(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
from collections import *
from itertools import *
from bisect import *
import copy

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

value=10**18
for i in range(0,101):
    value=min(value,sum([(x-i)**2 for x in X]))

print(value)

Submission status: Accepted

Solution code:
n = int(input())
ans = 10 ** 9
lis = list(map(int,input().split()))
for i in range(0,101):
  num = 0
  for nu in lis:
    num += (nu-i) ** 2
  ans = min(ans,num)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = []
for p in range(min(x), max(x)):
    meter = 0
    for xi in x:
        meter += pow((xi-p),2)
    ans.append(meter)
print(min(ans))

Submission status: Runtime Error

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

# i = min(x)
# while i <= max(x):
for i in range(min(x),max(x)+1,1):
    tmp = sum(map(lambda p: (p-i)**2,x))
    if ans > tmp:
        ans = tmp
    # i += 1
print(ans)

Submission status: Runtime Error

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

def calc_power(p):
  P = list(map(lambda x: (x-p)**2, X))
  return sum(P)

power = []
for p in range(min(X), max(X)):
  power.append(calc_power(p))
  
print(min(power))

Submission status: Runtime Error

Solution code:
N = int(input())
X = map(int, input().split())
 
ans = 10000000000
for i in range(100):
  s = 0
  for j in range(N):
    s += (X[j]-i)**2
    
  ans = min(ans, s)
  
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
X = map(int, input().split())
 
ans = 100000
for i in range(100):
  s = 0
  for j in range(N):
    s += (X[j]-i)**2
    
  ans = min(ans, s)
  
print(ans)

Submission status: Runtime Error

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

ans = 100000
for i in range(100):
  s = 0
  for j in range(N):
    s += (X[i]-i)**2
    
  ans = min(ans, s)
  
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N = input()
X = list(map(int, input()))
ans=0
for P in range(max(X)):
  sum = np.sum(list(map(lambda x: (x-P)**2, X)))
    
  if sum >= ans:
    ans = sum
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N = input()
X = list(map(int, input()))
ans=0
for P in range(max(X)):
  sum = np.sum(map(lambda x: (x-P)**2, X))
    
  if sum >= ans:
    ans = sum
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
X = list(map(int, input()))
ans=0
for P in range(max(X)):
  sum = np.sum(map(lambda:x (x-P)**2, X))
    
  if sum >= ans:
    ans = sum
    
print(ans)

Submission status: Runtime Error

Solution code:
def sqerr(x, t):
  return (x - t)**2

N = input()
X = list(map(int, input()))
ans=0
for P in range(1, N+1):
  sum = 0
  for x in X:
    sum += (x-P)**2
    
  if sum > ans:
    ans = sum
    
print(ans)

Submission status: Runtime Error

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

if n==1:
    print('0')

a=sum(x)/len(x)
d=[]
for i in range(min(x),max(x)):
    c=0
    for j in x:
        c+=(i-j)**2
    d.append(c)

print(min(d))

Submission status: Runtime Error

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

a=sum(x)/len(x)
d=[]
for i in range(min(x),max(x)):
    c=0
    for j in x:
        c+=(i-j)**2
    d.append(c)

print(min(d))

Submission status: Runtime Error

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

print(p)

Submission status: Runtime Error

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

for x in X:
  result1 += (x - P)**2
  result2 += (x - P - 1)**2

if result1 < result2:
  result = result1
elif result1 > result2:
  result = result2


print(result)

Submission status: Runtime Error

Solution code:
n= int(input())
x= list(map(int,input().split()))
m= mean(x)
g= int(m)
if m-g<g+1-m:
  print(g)
else:
  print(g+1)

Submission status: Runtime Error

Solution code:
集会は数直線上の任意の 整数値の座標 で開くことができ、座標

Submission status: Runtime Error

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

mean_=sum(x)//len(x)

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

Submission status: Runtime Error

Solution code:
s = map(int,input().split())
m = 10000000
for p in s:
  t = 0
  for x in s:
    t+=(x-p)**2
   m = min(t,m)
print(m)

Submission status: Runtime Error

Solution code:
from numpy import average

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

p=int(average(x))

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from numpy import average
n = int(input())
x_list = list(map(int, input().split()))
m = int(average(x_list) + 0.5)
print(sum((x - m)**2 for x in x_list))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
sl = []

ma, mi = max(l), min(l)

for x in range(mi, ma):
  s = 0
  for i in l:
    s += (i - x)**2 
  sl.append(s)

print(min(sl))

Submission status: Runtime Error

Solution code:
N = int(input())
X = sorted(list(map(int, readline().split())))
ans = 10**9+7
for p in range(0, 102):
    res = 0
    for x in X:
        res += (p-x)**2 
    ans = min(ans, res)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

Mini = min(X)
Max = max(X)

H_list = []
for i in range(Mini, Max):
    P_list = np.full(N,i)
    H = sum((P_list-np.array(X))**2)
    H_list.append(H)

print(min(H_list))

Submission status: Runtime Error

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

P = round(sum(in)/N)

sum = 0
for i in range(N):
  sum += (in[i] - P)**2
  
print(sum)

Submission status: Runtime Error

Solution code:
in = input().split(' ')
in = list(map(int, in))
in.pop(0)

P = round(sum(in)/len(in))

sum = 0
for i in range(len(in)):
  sum += (in[i] - P)**2
  
print(sum)

Submission status: Runtime Error

Solution code:
n=int(input())
man=list(map,int(input().split()))
can=list[]
for i in range(1,101):
  for j in range(len(man)):
    p=(man[j]-i)**2
	pp+=p
  can.append(pp)
can.sort(key=int)
print(can[0])

Submission status: Runtime Error

Solution code:
import numpy
n = int(input())
l = numpy.array(list(map(int,input().split())))
av = round(numpy.average(l))
square_list = numpy.square(l - av)

print(numpy.sum(square_list))

Submission status: Runtime Error

Solution code:
import numpy
n = int(input())
l = list(map(int,input().split()))
av = round(numpy.average(l))
sumsquare = 0
for i in l:
    sumsquare += (i - av)**2
print(sumsquare)

Submission status: Runtime Error

Solution code:
    x.append(int(input()))N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

print(int(hpsum))

Submission status: Runtime Error

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

minimum = 10000000

for n in range(1,N+1):
  d = 0
  for i in range(N):
    d += (X[i]-n)**2
  print(d)
  if kyori < minimum:
    minimum = kyori
print(minimum)

Submission status: Runtime Error

Solution code:
import numpy as np
from math import ceil, floor

n = int(input())
l = [int(input()) for x in range(n)]

c = ceil(np.array(l).mean())
f = floor(np.array(l).mean())


print(min(sum([(x-c)**2 for x in l]), sum([(x-f)**2 for x in l])))

Submission status: Runtime Error

Solution code:
N = int(input())
X1 = list(map(int, input().split()))
ans = []
if N == 1:
    print(0)
    exit()
    
for p in range(min(X1), max(X1)):
    num = 0
    for i in range(N):
        num += (X1[i] - p)*(X1[i] - p)
        
    ans.append(int(num))


print(min(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
X1 = list(map(int, input().split()))
ans = []
for p in range(min(X1), max(X1)):
    poi = 0
    for i in range(N):
        poi += (X1[i] - p)*(X1[i] - p)
        
    ans.append(int(poi))


print(min(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
list = list(map(int,input().split()))
min_ = min(list)
max_ = max(list)
num=[]
for a in range(min_,max_):
  _ = []
  for b in range(len(list)):
    _.append((a - list[b])**2)
  num.append(sum(_))
if n == 1:
  print(0)
  exit()
print(min(num))

Submission status: Runtime Error

Solution code:
n = int(input())
list = list(map(int,input().split()))
min_ = min(list)
max_ = max(list)
num=[]
for a in range(min_,max_):
  _ = []
  for b in range(len(list)):
    _.append((a - list[b])**2)
  num.append(sum(_))
print(min(num))

Submission status: Runtime Error

Solution code:

N = int(input())
li = list(map(int, input().split()))
li_2 = []

if N == 1:
    print(0)
else:
   for i in range(min(li),max(li)+1):
       cost_sum = 0
       for t in range(N):
           cost_sum += (li[t]-i) ** 2
       li_2.append(cost_sum)
print(min(li_2))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
x=list(map(int,input().split()))
l=min(x)
r=max(x)
cost=[]
for i in range(l,r):
    curcost=0
    for j in range(n):
        curcost+=(x[j]-i)**2
    cost.append(curcost)
print(min(cost))

Submission status: Runtime Error

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

t = []
for i in range(min(X), max(X)):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))

Submission status: Runtime Error

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

for i in range(1,101):
  temp=0
  for j in range(N):
    temp+=(X[i]-j)**2
  else:
    ans=min(ans,temp)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 100000000

for p in range(X[0], X[N]): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Runtime Error

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

p = X[0]
sum = 0
for x in X:
  sum += (x - p)**2
ans = sum

for p in range(X[1], X[N-1]): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Runtime Error

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

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1m E2))

Submission status: Runtime Error

Solution code:
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn =　10**6
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn =　10**9
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()

Submission status: Runtime Error

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

for i in range(X[0],1+X[N-1]):
  for j in range(N):
    tmp = tmp + (X[j]-i)**2
  ans.append(tmp)
  tmp = 0
print(min(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

minX = min(X)
maxX = max(X)

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))

Submission status: Runtime Error

Solution code:

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

minX = min(X)
maxX = max(X)



HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))

Submission status: Runtime Error

Solution code:
N = int(input())

X = list(map(int, input().split()))
ans = 10**18
for i in range(1, 101):
    temp=0
    for num in X:
        temp += (i-num)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

X = list(map(int, input().split()))
ans = 10**18
for i in range(1, 101):
    temp=0
    for num in X:
        temp + =(i-num)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

X = list(map(int, input().split()))
ans = 10**18
for i in range(1. 101):
    temp=0
    for num in X:
        temp + =(i-num)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
input_data = list(map(int,input().split()))
mini = min(input_data[1:])
length=max(input_data[1:])-mini
zahyo = [n-mini for n in input_data[1:]]
energy=[0 for i in range(length+1)]
for i in range(length+1):
    for j in range(input_data[0]):
        energy[i]=energy[i]+(i-zahyo[j])**2
print(min(energy))

Submission status: Runtime Error

Solution code:
input_data = list(map(int,input().split()))
import sys

sys.setrecursionlimit(10**10)
mini = min(input_data[1:])
length=max(input_data[1:])-mini
zahyo = [n-mini for n in input_data[1:]]
energy=[0 for i in range(length+1)]
for i in range(length+1):
    for j in range(input_data[0]):
        energy[i]=energy[i]+(i-zahyo[j])**2
print(min(energy))

Submission status: Runtime Error

Solution code:
input_data = list(map(int,input().split()))
import sys

sys.setrecursionlimit(10**6)
mini = min(input_data[1:])
length=max(input_data[1:])-mini
zahyo = [n-mini for n in input_data[1:]]
energy=[0 for i in range(length+1)]
for i in range(length+1):
    for j in range(input_data[0]):
        energy[i]=energy[i]+(i-zahyo[j])**2
print(min(energy))

Submission status: Runtime Error

Solution code:
input_data = list(map(int,input().split()))
mini = min(input_data[1:])
length=max(input_data[1:])-mini
zahyo = [n-mini for n in input_data[1:]]
energy=[0 for i in range(length+1)]
for i in range(length+1):
  for j in range(input_data[0]):
    energy[i]=energy[i]+(i-zahyo[j])**2
print(min(energy))

Submission status: Runtime Error

Solution code:
import math

N = input()
xs = [int(i) for i in input().split()]
p = round(sum(xs)/len(xs))

print(sum(math.pow(x-p) for x in xs))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp,)
print(hp)

Submission status: Runtime Error

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

def D(x, a):
    ans = 0
    for i in range(len(a)):
        ans += (x - a[i])**2
    return ans

for i in range(0, 101):
    if D(x, X) < D(i+1, X):
        print(D(i, X))
        break

Submission status: Runtime Error

Solution code:
N = int(input())
num_sum = 0
ans = 0
num_list = [0]*N

for i in range(N):
  num_list[i] = int(input())
  num_sum += num_list[i]
  
mean = int(num_sum/N)

for i in range(N):
  ans += (num_list[i]-mean)**2
  
print(ans)

Submission status: Runtime Error

Solution code:
let square x = x * x
let calc party = Array.sumBy (fun x -> square (x - party))
let fc coords =
    let min = Array.min coords
    let max = Array.max coords
    [ for x in [min..max] do calc x coords ] |> List.min

let input = [| [| 1; 4|]; [| 14; 14; 2; 13; 56; 2; 37; |] |]
for i in input do fc i |> printfn "%d"
// expected 5; 2354

[<EntryPoint>]
let main argv =
    stdin.ReadLine() |> ignore
    stdin.ReadLine() |> Array.map int |> fc |> printfn "%d"
    0

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input()
print(min(sum((x-p)**2 for x in map(int, input().split())) for p in range(101)))

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
print(min(lambda p: sum((x-p)**2 for x in X) for i in range(max(X)+1)))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0
y = True

for p in range(n):
    if x[0] != x[i]:
        y = False

if y:
    print(0)
    exit(0)

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
Min = min(X)
Max = max(X)
disList = []
flag = 1
for ass in range(Min, Max):
  dis = 0
  for person in range(N):
    dis += (X[person] - ass) * (X[person] - ass)
  disList.append(dis)  
for i in range(N):
  if not X[i] == 1:
    flag=0
    break
if N == 1:
  print(X[0])
elif flag == 0:
  print(min(disList))
else:
  print(1)

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
Min = min(X)
Max = max(X)
disList = []
for ass in range(Min, Max):
  dis = 0
  for person in range(N):
    dis += (X[person] - ass) * (X[person] - ass)
  disList.append(dis)
print(min(disList))

Submission status: Runtime Error

Solution code:
import collections

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

x = collections.Counter(X)

s = min(list(x.keys()))
e = max(list(x.keys()))

xl = list(x)

m = [0]*(e+1-s)

for i in range(s, e+1):
    p = 0
    for j in range(N):
        p += pow(xl[j]-i,2) * x[xl[j]]
    m[i-s] = p

print(min(m))

Submission status: Runtime Error

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

minX = min(X)
maxX = max(X)
from statistics import stdev
P = round(stdev(X))
D = 0
li = []
for i in range(N):
	D += (P - X[i]) ** 2
li.append(D)
D = 0
for i in range(N):
	D += (P + 1 - X[i]) ** 2
li.append(D)
D = 0
for i in range(N):
	D += (P - 1 - X[i]) ** 2
li.append(D)
print(min(li))

Submission status: Runtime Error

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

minX = min(X)
maxX = max(X)
from statistics import stdev
P = round(stdev(X))
D = 0
for i in range(N):
	D += (P - X[i]) ** 2
print(D)

Submission status: Runtime Error

Solution code:
def ans(p, x):
    a = 0
    for i in x:
        a += (i - p)**2
    return a

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

p = sum(x)//n

print(min(ans(p), ans(p+1)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

def main():
    number_of_human = int(input())
    position_list = list(map(int,input().split()))
    
    start_position = min(position_list)
    end_position = max(position_list)
    
    answear_list = []
    
    while True:
        answear = sum([(item - start_position)**2 for item in position_list])
        if start_position == end_position:
            break
        start_position += 1
        answear_list.append(answear)
    
    print(min(answear_list))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

sum_list = []
start = min(x)
stop = max(x)
for i in range(start, stop):
    sum = 0
    for j in x:
        sum += (i - j) ** 2
    sum_list.append(sum)

print(min(sum_list))

Submission status: Runtime Error

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

sum_list = []
for i in range(min(x), max(x)):
    sum = 0
    for j in x:
        sum += (x[i] - x[j]) ** 2
    sum_list.append(sum)
    
print(min(sum_list))

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=float("Inf")
for i in range(x[0],x[n-1]+1):
  print(i)
  cal=0
  for j in range(0,n):
    cal=cal+(x[j]-temp)**2
  ans=min(ans,cal)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main(n,x)
    print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
X=list(map(int, input().spliet()))
k1=(max(X)+min(X))//2
k2=k1+1
ans1=0
ans2=0
for x in X:
  ans1+=(k1-x)**2
  ans2+=(k2-x)**2

print(min(ans1, ans2))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

m = min(s)
M = max(s)

lis = []
ans = 0

for i in range(m,M):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))

Submission status: Runtime Error

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

m = s[0]
M = s[N-1]

lis = []
ans = 0

for i in range(m,M + 1):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))

Submission status: Runtime Error

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

m = s[0]
M = s[N-1]

lis = []
sum = 0

for i in range(m,M):
  for j in range(N):
  	sum += (s[j] - i) ** 2
  lis.append(sum)
  sum = 0
  
print(min(lis))

Submission status: Runtime Error

Solution code:
import math


def inp():
    return(int(input()))


def invr():
    return(map(int, input().split()))


n = inp()
arr = invr()
arr = sorted(arr)
max = arr[n-1]
min = arr[0]

cost = math.inf
for p in range(min, max+1):
    temp_cost = 0
    for xi in arr:
        temp_cost += (xi-p)**2
    if temp_cost < cost:
        cost = temp_cost
print(cost)

Submission status: Runtime Error

Solution code:
import math
num = int(input())
lst = sorted(list(map(int, input().split())))
result = math.inf
for i in range(lst[0], lst[-1] + 1):
    tmp = 0
    for v in lst:
        tmp += (v - i) ** 2
    if tmp < result:
        result = tmp
print(result)

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    n_array = np.array(list(map(int,input().split())))
    mea = int(np.average(n_array) + 0.5)
    ans = n_array - mea 
    print(sum(ans*ans))
resolve()

Submission status: Runtime Error

Solution code:
import math
N = int(input())
x = list(map(int, input().split()))
 
s = float((x[0] + x[1])/2)
for i in range(2,N-1):
	s = (s + x[i]) / 2
 
min = math.floor(s)
 
print(min)

Submission status: Runtime Error

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

s = float(x[0])
for i in range(N-1):
	t = (s + x[i+1]) / 2

min = math.floor(t)

print(min)