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:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

if n==1:
    print((arr[i]-1)**2)
    exit()

ans = int(sum(arr)//n)+1
cnt=0
for i in range(n):
    cnt+=(ans-arr[i])**2

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
total = 0 
X = list( input().split())
for i in X: 
    total +=  (X[i] - N) * (X[i] - N)
print(total)

Submission status: Runtime Error

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

for p in range(1, max_N):
    tmp = sum([(x-p)**2 for x in X])
    ans.append(tmp)
print(min(ans))

Submission status: Runtime Error

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

for i in range(n):
    if k ** (i - 1) <= n < k ** i:
        ans = i
        break
if ans == 0:
    ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(input().split())
x=[int(s) for s in x]
if n>1:
    b_li=[]
    for i in range(min(x),max(x)):
        a_li=[]
        for j in range(n):
            a=(x[j]-i)**2
            a_li.append(a)
        b=sum(a_li)
        b_li.append(b)
    print(min(b_li))
else:
    print(0)

Submission status: Runtime Error

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

k=max(x)-min(x)
box=[0]*k

for i in range(0,k):
    aa=0
    for j in range(0,n):
        aa = aa+(x[j]-min(x)-i)**2
    box[i]=aa


print(min(box))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
ans = sys.maxint

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


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import statistics

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

if __name__ == '__main__':
        resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
X=list(map(int, input().split()))
minX=min(X)
maxX=max(X)
minE = 1000000000
for P in range(minX,maxX):
  sum = 0
  for i in X:
    sum = sum + (X[i]-P)**2
  if minE>sum:
    minE=sum
print(minE)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=0
m=0
for i in b:
    c+=i
d=c/len(b)
e=str(d)[2]
e=int(e)
if e>=5:
    f=int(str(d)[0])+1
else:
    f=int(str(d)[0])
for g in b:
    m+=(abs(g-f))**2
print(m)

Submission status: Runtime Error

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

s = 0
for x in X:
    s += (x-1)**2

S = s

if N == 1:
    print(0)
else:
    m = max(X)
    n = min(X)
    for P in range(n,m+1):
        s = 0
        for x in X:
            s += (x-P)**2
        if s < S:
            S = s
	print(S)

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(1,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:
a=int(input())
b=list(map(int,input().split()))
c=0
m=0
for i in b:
    c+=i
d=c/len(b)
e=str(d)[2]
e=int(e)
if e>=5:
    f=int(str(d)[0])+1
else:
    f=int(str(d)[0])
for g in b:
    m+=abs((g-f)**2)
print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a_min = min(a)
a_max = max(a)

x = a_max - a_min

for i in range(x):
    z = i + a_min
    hp = 0
    for x in a:
        hp += (x - z) ** 2
    if i == 0:
        ans = hp
    if ans > hp:
        ans = hp

print(ans)

Submission status: Runtime Error

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

max_x = max(x)
min_x = min(x)

ans = []
for i in range(min_x, max_x):
  a = 0
  for xi in x:
    a += (xi - (i+1))*(xi - (i+1))
  ans.append(a)
  
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)):
    goukei = 0
    for j in range(N):
        if i%1==0:
            goukei+=(X[j]-i)**2
    ans.append(goukei)
kotae=set(ans)
print(min(kotae))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=input()
mk=input().split()
t=0
s=0
ans=0
for k in mk:
  pk=int(k)
  t+=pk
  s+=(pk**2)
px=round(t/n)
ans+=s+n*(px**2)-2*px*t
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
x = np.array(sorted(list(map(int, input().split()))),dtype = 'int64')

s = []
for p in range(x[0],x[-1]):
    s.append(np.sum((x-p)*(x-p)))
    
print(min(s))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a_min = min(a)
a_max = max(a)

n = a_max - a_min

for i in range(n):
    z = i + a_min
    hp = 0
    for x in a:
        hp += (x - z) ** 2
    if i == 0:
        ans = hp
    if ans > hp:
        ans = hp

print(ans)

Submission status: Runtime Error

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

p=min(l)
q=max(l)+1
k=0
r=[]
for i in range(p,q):
  for j in range(n):
    k+=(l[j]-i)**2
  r.append(k)

print(min(r))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
X=list(map(int,input().split()))
i=1
XT=list(map(tairyoku,X))
ans=sum(XT)
for i in range(2,101):
    XT=list(map(tairyoku,X))
    ans=min(ans,sum(XT))
print(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)):
    goukei = 0
    for j in range(len(X)):
        if i%1==0:
            goukei+=(X[j]-i)**2
    ans.append(goukei)
kotae=set(ans)
print(min(kotae))

Submission status: Runtime Error

Solution code:
n=input()
mk=input().split()
m=[]
t=0
s=0
for k in mk:
  pk=int(k)
  t+=pk
  s+=(pk**2)
  m.append(pk)
px=round(t/n)
ans=s+n*(px**2)-2*px*t
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
import numpy as np


def comb(a, b):
    result = 1
    for i in range(b):
        result *= (a - i) / (i + 1)
    return result


def main():
    N = int(input())
    Xs = list(map(int, input().split()))
    Xs = np.array(Xs)

    min_load = None
    for p in range(101):
        load = np.sum((Xs - p) ** 2)
        if min_load is None or min_load > load:
            min_load = load

    print(min_load)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i(0);i<n;i++)
typedef long long ll;

int main(){
	int N;
    cin >> N;
    vector<int> X(N);
    rep(i,N) cin >> X[i];
    sort(X.begin(),X.end());
    int ans(999999999);
    for(int P(X[0]); P<X[X.size()-1]; P++){
        int tmp(0);
        rep(i,X.size()){
            tmp += pow((X[i]-P),2);
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=0
m=0
for i in b:
    c+=i
d=c/len(b)
e=str(d)[2]
e=int(e)
if e>=5:
    f=int(str(d)[0])*2+1
else:
    f=int(str(d)[0])
for g in b:
    m+=abs((g-f)*2)
print(m)

Submission status: Runtime Error

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

x = int(input()) 
san = list(map(int,input().split(" ")))

if x == 1:
    print("0")
    sys.exit()

sta = min(san)
goa = max(san)

tai = 0
ans = [] 

for i in range(sta,goa):
    tai = 0
    for j in range(x):
        tai += (i - san[j])**2
    ans.append(tai)
    
print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
x = np.array(sorted(list(map(int, input().split()))))

s = []
for p in range(x[0],x[-1]):
    s.append(np.sum((x-p)*(x-p)))
    
print(min(s))

Submission status: Runtime Error

Solution code:
n=int(input())
xl=list(map(int,input().split()))
ans=[]
for p in range(xl[-1]-xl[0]+1):
    sum1=0
    for xi in xl:
        sum1+=(xi-xl[0]-p)**2
    ans.append(sum1)
print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
x = np.array(list(map(int, input().split())))

s = []
for p in range(x[0],x[-1]):
    s.append(np.sum((x-p)*(x-p)))
    
print(min(s))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
max_X = max(x)
maximum = 0

for i in range(0, max_X):
  for j in range(n):
    maxi += (x[j] - i) ** 2
  if maxi > maximum:
    maximum = maxi

print(maximum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n=int(input())
i = list(map(int, input().split()))
ave=sum(i) / n
ans=0
as=Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for k in range(n):
  ans+=(as-i[k])**2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = np.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
else:
  break
s = n*(m**2) - 2*a*m + b
print(int(s))

Submission status: Runtime Error

Solution code:
import numpy as np
N =int(input())

X = np.array([int(i) for i in input().split()])

co_min = min(X)
co_max = max(X)

Y =np.ones(co_max-co_min)

for i in range(len(Y)):
    start = co_min + i
    Y[i] = sum((X-start)**2)
    
ans = int(min(Y))

print(ans)

Submission status: Runtime Error

Solution code:
from math import inf

N = int(input())

line = input().split(" ")
X = []

for e in line:
	X.append(int(e))

ans = inf
for P in range(101):
	curr = 0

	for x in X:
		curr += (x - P)**2

	ans = min(ans, curr)


print(ans)

Submission status: Runtime Error

Solution code:
a=int(input().split())
b=list(map(int,input(.split())))
c=0
m=0
for i in b:
    c+=i
d=c/len(b)
e=str(d)[1]
e=int(e)
if e>=5:
    f=int(str(d)[0])*2+1
else:
    f=int(str(d)[0])
for g in b:
    m+=(g-f)*2
print(m)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(input().split())
x=[int(s) for s in x]
b_li=[]
for i in range(min(x),max(x)):
    a_li=[]
    for j in range(n):
        a=(x[j]-i)**2
        a_li.append(a)
    b=sum(a_li)
    b_li.append(b)
print(min(b_li))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
x = int(input()) 
san = list(map(int,input().split(" ")))

sta = min(san)
goa = max(san)

tai = 0
ans = [] 

for i in range(sta,goa):
    tai = 0
    for j in range(x):
        tai += (i - san[j])**2
    ans.append(tai)
    
print(min(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
x_li = list(map(int, input().split()))
import math
ans = math.inf
for i in range(1, 101):
    d = 0
    for j in range(N):
        d += (x_li[j] - i) ** 2
    ans = min(ans, d)
print(ans)

Submission status: Runtime Error

Solution code:
from statistics import mean
import math
def solve():
    N = int(input())
    X = list(map(int, input().split()))
    mn = mean(X)
    if isinstance(mn, int) or mn.is_integer():
        P = mn
        print(calc(X, P))
    else:
        ans = min(calc(X, math.floor(mn)), calc(X, math.ceil(mn)))
        print(ans)

def calc(X, P):
    retval = 0
    for x in X:
        retval += (x - P) ** 2 
    return retval
    
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

xmax = max(xlist)
xmin = min(xlist)
powers = []
for p in range(xmin, xmax):
    powers.append(power(p, xlist))
print(min(powers))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = math.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
else:
  break
s = n*(m**2) - 2*a*m + b
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
x = [int(i) for i in input().split()]

_list = [-1 for i in range(100)]
if n==1:
    print(0)
else:
    for i in range(min(x), max(x), 1):
        a = 0
        for j in range(n):
            a += (x[j]-i)**2
        _list[i] = a
    _list = np.array(_list)
    print(min(_list[_list>=0]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

powers = []
for i in range(min(points), max(points)):
    power = 0
    for point in points:
        power += ((i - point) ** 2)
    powers.append(power)

print(min(powers))

Submission status: Runtime Error

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

powers = []
for i in range(min(points), max(points)):
    power = 0
    for point in points:
        power += ((i - point) ** 2)
    powers.append(power)
print(min(powers))

Submission status: Runtime Error

Solution code:
N = int(input())

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

dp = {}

for i in range(N):
    for j in range(min(X), max(X)):
        if j in dp:
            dp[j] += (X[i] - j)**2
        else:
            dp[j] = (X[i] - j)**2

print(min(dp.values()))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
x = [int(i) for i in input().split()]

_list = [-1 for i in range(100)]
for i in range(min(x), max(x), 1):
    a = 0
    for j in range(n):
        a += (x[j]-i)**2
    _list[i] = a
_list = np.array(_list)
print(min(_list[_list>=0]))

Submission status: Runtime Error

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

ans = []
for p in range(min(x), max(x)):
  sigma = 0
  for i in x:
    sigma += (p-i)**2
  ans.append(sigma)

print(min(ans))

Submission status: Runtime Error

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

X.sort()

Xmin = min(X)
Xmax = max(X)

#print(Xmin,Xmax)

T =[]

for i in range(Xmin+1,Xmax+1):
    HP = 0
    for j in X:
        HP = HP + (i-j)**2
    T.append(HP)
print(min(T))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
X=sorted(list(map(int,input().split(' '))))
ans =math.inf
for i in range(X[0],X[-1]+1):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
# C
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))

P_floor = math.floor(np.sum(X)/N)
P_ceil = math.ceil(np.sum(X)/N)

ans = min(np.sum((X-P_floor)**2), np.sum((X-P_ceil)**2))

print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int N;
vector<int> arr;

int main() {
  cin >> N;
  arr.resize(N);
  for(int i = 0; i < N; i++)
    cin >> arr[i];

  int ans = INT_MAX;
  for(int p = 1; p <= 100; p++) {
    int cur = 0;
    for(int i = 0; i < N; i++)
      cur += (arr[i] - p)*(arr[i] - p);
    ans = min(ans, cur);
  }
  cout << ans;
}

Submission status: Runtime Error

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

hp_list = []
for p in range(int(min(X_list)), int(max(X_list))):
    hp = 0
    for x in X_list:
        hp += abs(x - p) ** 2
    hp_list.append(hp)

print(min(hp_list))

Submission status: Runtime Error

Solution code:
import numpy as np
N = input()
X = list(map(int,input().split()))

muf = np.floor(np.mean(X))
muc = np.ceil(np.mean(X))
ansf = 0
ansc = 0
for i in X:
    ansf += (muf-i)**2
    ansc += (muc-i)**2

print(min(int(ansf),int(ansc)))

Submission status: Runtime Error

Solution code:
from statistics import mean
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(mean(X) + 0.5)
    d = 0
    for n in range(N):
        d += (X[n] - P)**2
    print(d)

main()

Submission status: Runtime Error

Solution code:
# じょえチャンネル
# 高評価・チャンネル登録宜しくお願いします！
# https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ

import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')
def Z(f):
    if f:
        print('Yay!')
    else:
        print(':(')
def ispow(n):
    if int(n**.5)**2==n:
        return True
    return False

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

res = 10 ** 100
for i in range(-100, 200):
    tmp = 0
    for j in range(a):
        tmp += (i - j) ** 2
    res = min(res, tmp)
print(res)