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:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector <int> X(N);

	int xMax = 0;
	int xMin = 101;
	for (int i = 0; i < N; i++) {
		cin >> X.at(i);
		xMax = max(X.at(i), xMax);
		xMin = min(X.at(i), xMin);
	}

	int ans = 100000;
	for (int P = xMin; P < xMax; P++) {
		int toughness = 0;
		for (int i = 0; i < N; i++) {
			toughness += pow(X.at(i) - P, 2);
		}
		ans = min(toughness, ans);
	}

	cout << ans << endl;

}

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(input()) for i in range(n)]
e = sum(x)//len(x)
k = 0
for i in range(len(x)):
    k = k + (x[i] - e)*(x[i] - e)
print(k)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=[]
b=0
if N==1:
    print(0)
else:
    for i in range(min(a),max(a)):
        for k in range(N):
            b+=(a[k]-i)**2
        ans.append(b)
        b=0
    print(min(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N = int(input())
X = list(map(int,input().split()))
P = math.ceil(sum(X)/N)
P1 = P - 1
hp = 0

for x in X:
  hp_x = (P-x)**2
  hp2_x = (P1 - x)**2
  hp = hp + hp_x
  hp2 = hp2 + hp2_x
print(min(hp,hp2))

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(input().split()))
P = ceil(sum(X)/2)

hp = 0

for x in X:
  hp_x = (P-X)**2
  hp = hp + hp_x
print(hp)

Submission status: Runtime Error

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

ans = []

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

print(min(ans))

Submission status: Runtime Error

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

if n ==1:
    print(0)
else:
    cnt = 0
    res_ = []
    for i in range(x_[0],x_[n-1]):
        cnt = 0
        for j in range(len(x_)):
            cnt += (x_[j] - i)**2
        res_.append(cnt)

    print(min(res_))

Submission status: Runtime Error

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

cnt = 0
res_ = []
for i in range(1,x_[n-1]):
    cnt = 0
    for j in range(len(x_)):
        cnt += (x_[j] - i)**2
    res_.append(cnt)
print(min(res_))

Submission status: Runtime Error

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

each = 0
loss = 0
ll = []

for k in range(min(x), max(x)):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
      loss = 0
  
print(min(ll))

Submission status: Runtime Error

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

each = 0
loss = 0
ll = []

for k in range(min(x), max(x)):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
  
print(min(ll))

Submission status: Runtime Error

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

each = 0
loss = 0
ll = []
k = 0

for k in range(min(x), max(x)):
      for j in range(len(x)):
            each = np.power((x[j]-k), 2)
            loss += each
      ll.append(loss)
  
print(min(ll))

Submission status: Runtime Error

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

each = 0
loss
ll = []

for(int i=min(x); i<max(x); i++):
  for j in range(len(x)):
    each = np.power((x[j]-i), 2)
    loss += each
  ll.append(loss)
  
print(min(each))

Submission status: Runtime Error

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

each = 0
loss = []

for(int i=min(x); i<max(x); i++):
  for j in range(len(x)):
    each = np.power((x[j]-i), 2)
    each += each
  loss.append(each)
  
print(min(each))

Submission status: Runtime Error

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

each = 0
loss = []

for(int i=min(x); i<max(x); i++):
  for j in range(len(x)):
    each = np.power((x[j]-i), 2)
  loss.append(each)
  
print(min(each))

Submission status: Runtime Error

Solution code:
N=int(input())
if N==1:
    print(0)
else:
    X=[int(x) for x in input().split(" ")]
    cons=lambda P:sum([(x-P)**2 for x in X])
    print(min([cons(P) for P in range(min(X),max(X))]))

Submission status: Runtime Error

Solution code:
N=int(input())
X=[int(x) for x in input().split(" ")]
cons=lambda P:sum([(x-P)**2 for x in X])
print(min([cons(P) for P in range(min(X),max(X))]))

Submission status: Runtime Error

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

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    X = map(int, input().split())
    print( (n))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()

Submission status: Runtime Error

Solution code:
cost=0
for u in X:
  cost += abs(u-N)**2
print(cost)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=0
average=sum(x)//n

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
x_list = list(map(int,input().split()))
#print(x_list)
#print(sum(x_list))
#(len(x_list))

#p = sum(x_list) // (len(x_list))
#p = (min(x_list) + max(x_list)) // 2
#print(p)

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
        #print(ans)
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))
#print(ans)n = int(input())
x_list = list(map(int,input().split()))
#print(x_list)
#print(sum(x_list))
#(len(x_list))

#p = sum(x_list) // (len(x_list))
#p = (min(x_list) + max(x_list)) // 2
#print(p)

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
        #print(ans)
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))
#print(ans)

Submission status: Runtime Error

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

cost_list = []

for p in range(min(zyunin_list), max(zyunin_list)):
    cost = 0
    for zahyo in zyunin_list:
        cost += (zahyo - p) ** 2
    cost_list.append(cost)

print(min(cost_list))

Submission status: Runtime Error

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

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

print(min(answers))

Submission status: Runtime Error

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0
for i in range(min(X),max(X) + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
hp.remove(0)
print(min(hp))

Submission status: Runtime Error

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0
for i in range(X[0],X[N-1] + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
hp.remove(0)
print(min(hp))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    X = [int(x) for x in input().split()]
    ans = []
    for i in range(min(X), max(X)):
        a = map(lambda x: (x-i)**2, X)
        ans.append(sum(a))
    return print(min(ans))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
s = []
for i in range(1,101):
    b = sum((a[j]-i-1)**2 for j in range(N))
    s.append(b) 
print(min(b))

Submission status: Runtime Error

Solution code:
import sys
n = int(sys.stdin.readline())
li = list(map(int, sys.stdin.readline().split()))
min = 0
for k in li:
    min += (k-i) ** 2
i = 2
while i <= 100:
  s = 0
  for k in li:
    s += (k-i) ** 2
  if s < min:
    min = s
  i += 1
print(min)

Submission status: Runtime Error

Solution code:
import math


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

head = min(X)
tail = max(X)

min_score = math.inf
for p in range(head, tail+1):
    min_score = min(sum(map(lambda x: (x - p)**2, X)), min_score)

print(min_score)

Submission status: Runtime Error

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

ans = 10**20 #答えになるので初期化
for i in range(1,101): #1<=P<=100の範囲について消費する体力の総和を計算
    dis = 0
    for j in x:
        dis += (i-j)**2
    ans = min(dis)

print(ans)

Submission status: Runtime Error

Solution code:
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(min(r, l))

Submission status: Runtime Error

Solution code:
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(r)

Submission status: Runtime Error

Solution code:
n=input()
x=list(map(int, input().split()))
maxn=0
for i in range(n):
    if x[i]>maxn:
        maxn=x[i]
    else:
        maxn=maxn
minp=0
for j in range(n):
    minp=minp+(x[j]-1)**2
for i in range(maxn+1)
    for j in range(n):
        power=power+(x[j]-i)**2
    if power<minp:
        minp=power
    else:
        minp=minp
print(minp)

Submission status: Runtime Error

Solution code:
N=input()
list=map(int,input().split())
sum+=0
for i in range(1,N+1)
sum+=abs(i-list)
print(min(sum**2))

Submission status: Runtime Error

Solution code:
N=input()
list=map(int,input().split())
sum+=0
for i in range(1,N+1)
sum=abs(i-list)
print(min(sum**2))

Submission status: Runtime Error

Solution code:
num = [int(n) for n in input().split()] 
    
s = sum(num[1:num[0]+1])/num[0]
s = round(s)
r = 0
for i in range(1,num[0]+1):
    r += pow(num[i]-s,2)
print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
import decimal as dec

num = [int(n) for n in input().split()] 
    
s = sum(num[1:num[0]+1])/num[0]
s = round(s)
r = 0
for i in range(1,num[0]+1):
    r += pow(num[i]-s,2)
print(r)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
sigmaList = list()
for p in range(x[0], x[n - 1]):
    sigma = 0
    for i in range(n):
        sigma += (x[i] - p) ** 2
    sigmaList.append(sigma)

print(min(sigmaList))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
sigmaList = list()
for p in range(x[0], x[n]):
    sigma = 0
    for i in range(n):
        sigma += (x[i] - p) ** 2
    sigmaList.append(sigma)

print(min(sigmaList))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=(int)1e10
for i in range(1,101):
  sum=0
  for x in a: sum+=abs(x-i)
  ans=min(ans,sum)
print(ans)

Submission status: Runtime Error

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

ans = 100000

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

Submission status: Runtime Error

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

ans = 100000

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


for i in 100:
  result = 0
  for j in x:
    result += (i - j)**2
  print(min(result))

Submission status: Runtime Error

Solution code:
N=int(input())
X= list(map(int,input().split()))
cnt = 1000000
for j in range(100):
    t = 0
    for i in li:
        t += (i-(j+1))**2
    if t <= cnt:
        cnt = t
print(cnt)

Submission status: Runtime Error

Solution code:
N =int(input())
X = list(map(int,input().split()))
c = 100000000
for i in range(1,101):
  t=0
  for j in X:
    t += (j-i)**2

  if t=<c:
    t=c
print(c)

Submission status: Runtime Error

Solution code:
N =int(input())
X = map(int,input().split())
c = 100000000
for i in range(1,101):
  t=0
  for j in X:
    t += (j-i)**2

  if t=<c:
    t=c
print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
X=[map(int,input().strip().split())]
t=[]
for i in range(1,N+1):
    s=0
    for j in range(0,N):
        s+=(X[j]-i)**2
    t.append(s)
print(t.index(min(t))+1)

Submission status: Runtime Error

Solution code:
N=int(input())
X=[input() for i in range(N)]
t=[]
for i in range(1,N+1):
    s=0
    for j in range(0,N):
        s+=(X[j]-i)**2
    t.append(s)
print(t.index(min(t))+1)

Submission status: Runtime Error

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

cost = 0

for i in range(1, 101):
  cand = 0
  for x in X:
    cand += (x[i]-i)**2
  cost = min(cost, cand)

print(cost)

Submission status: Runtime Error

Solution code:
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1


n=input1()
X=input_array()

min_p=min(X)
max_p=max(X)
b_p=10000
p=[]
for i in range(min_p,max_p):
	s=0
	for j in X:
		s+=(j-i)**2
	p.append(s)
	# if s>b_p:
	# 	break
	# else:
	# 	b_p=s
print(min(p))

Submission status: Runtime Error

Solution code:
n = int(input())
X = list(map(int,input().split)())
ans = 10**100
for i in range(1,101):
  count = 0
  for j in X:
    count += (i-j)*2
  ans = min(ans,count)
print(ans)

Submission status: Runtime Error

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

yy=[]
for p in range(x[0],x[-1]):
    y=[]
    for i in range(len(x)):
        y.append((p-x[i])*(p-x[i]))
    yy.append(sum(y))
print(min(yy))

Submission status: Runtime Error

Solution code:

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

yy=[]
for p in range(x[0],x[-1]):
    y=[]
    for i in range(len(x)):
        y.append((p-x[i])*(p-x[i]))
    yy.append(sum(y))
print(min(yy))    
 

"""
import numpy as np

a=[1,2,3]
p=0
y=[]
for p in range(0,2):
    for i in range(len(a)):
        a_=p-a[i]
        y.append(np.square(a_))
    print(y)
"""

Submission status: Runtime Error

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
result = []
sum = 0
goal = round(mean(X))
for i in range(len(X)):
    sum += (X[i] - goal) ** 2
print(sum)

Submission status: Runtime Error

Solution code:
from statistics import mean
ans = 0

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

P = round(mean(X))

for i in range(N):
    ans += ((X[i] - P)**2)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ma = max(x)
mi = min(x)
z = 0
a = []
for i in range(mi,ma):
    for j in range(n):
        y = (x[j] - (mi+i))**2
        z += y
    a.append(z)
    z = 0

print(min(a))

Submission status: Runtime Error

Solution code:
from math import *
return ceil((b-1).(a-1))

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(i,X) < D(i+1,X):
		print(D(i,X))
		break

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(i,X) < D(i+1,X):
		print(D(i,X))
		break

Submission status: Runtime Error

Solution code:
def f(n, x):
    mean =  np.mean(x)
    s1 = sum((x-np.floor(mean))**2)
    s2 = sum((x-np.ceil(mean))**2)
    print(int(min(s1, s2)))

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

Submission status: Runtime Error

Solution code:
n = int(input().strip())
L = list(map(int, input().strip().split()))
ans=10**6+1
for p in range(max(L[-1])+1):
    tmp=0
    for x in L:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)

Submission status: Runtime Error

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

res = float('inf')

for i in range(min(X, 1), max(X, 100) + 1):
    tmp = 0
    for x in X:
        tmp += (i - x) ** 2

    res = min(tmp, res)

print(res)

Submission status: Runtime Error

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

MaxX = max(X)
MinX = min(X)

ListP = []

for i in range(MinX, MaxX):
    P = 0
    for j in range(N):
        P += (X[j]-i)**2
    
    ListP.append(P)

print(min(ListP))

Submission status: Runtime Error

Solution code:
= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    if max(spot)==min(spot):
        ans.append(0)
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    ans.sort(reverse=True)
    print(ans[0])

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    if max(spot)==1:
        ans.sppend(0)
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    ans.sort(reverse=True)
    print(ans[0])

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    ans.sort(reverse=True)
    print(ans[0])

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    print(min(ans))

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
    ans.append(x)
if n != 1:
    print(min(ans))

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    for s in range(min(spot),max(spot)):
        x = 0
    for t in spot:
        x += (s-t)**2
    ans.append(x)
if n != 1:
    print(min(ans))

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
for s in range(min(spot),max(spot)):
    x = 0
    for t in spot:
        x += (s-t)**2
    ans.append(x)
if n == 1:
    print(ans[0])
else:
    print(min(ans))

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
for s in range(min(spot),max(spot)):
    x = 0
    for t in spot:
        x += (s-t)**2
    ans.append(x)
print(min(ans))

Submission status: Runtime Error

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

print(min(p))

Submission status: Runtime Error

Solution code:
import os

def main():
        num = int(input())
        dict_list = {}
        for i in range(num):
                strings = input()
                if strings in dict_list.keys():
                        dict_list[strings] += 1
                else:
                        dict_list[strings] = 1 

        max_num = max(dict_list.values())
        result = []
        
        for k,v in dict_list.items():
                if v == max_num:
                        result.append(k)
        result.sort()
        for i in result:
                print(i)

if __name__ == "__main__":
        main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n= int(input())
spot = input().split()
cnt = 0
ans = []
for i in spot:
    spot.append(int(i))
    del spot[cnt]
    cnt += 1
for s in range(min(spot),max(spot)):
    x = 0
    for t in spot:
        x += (t-s)**2
    ans.append(x)
print(min(ans))

Submission status: Runtime Error

Solution code:
import math


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


mi_stamina = math.inf
for i in range(-1000, 1000):
    def _distance(x):
        return (x-i)**2
    double_list = list(map(_distance, x_list))
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

Submission status: Runtime Error

Solution code:
import math


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


mi_stamina = math.inf
for i in range(-1000, 1000):
    def _distance(x):
        return (x-i)**2
    double_list = list(map(lambda x: _distance(x), x_list))
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

Submission status: Runtime Error

Solution code:
import math

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

mi_stamina = math.inf
for i in range(-1000, 1000):
    double_list = list(map(lambda x: (x-i)**2, x_list))
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

Submission status: Runtime Error

Solution code:
import math

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

mi_stamina = math.inf
for i in range(-1000, 1000):
    print(x_list)
    double_list = list(map(lambda x: (x-i)**2, x_list))
    print(double_list)
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

Submission status: Runtime Error

Solution code:
N=int(input())
lst=list(map(int,input().split()))
P=round(sum(lst)/N)
print(sum[(i-P)**2 for i in lst])

Submission status: Runtime Error

Solution code:
N=int(input())
lst=list(map(int,input().split()))
P=round(lst/N)
print(sum[(i-P)**2 for i in lst])

Submission status: Runtime Error

Solution code:

n = int(input())
x = list(map(int,input().split()))
x.sort()
cnt = 0
min = 0

for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2

    if i == x[0]:
        minimum = cnt

    minimum = min([minimum, cnt])
    cnt = 0

print(minimum)

Submission status: Runtime Error

Solution code:
n = int(input())
list = []
list1 = []
list2 = []
list3 = []
c = 0
a = input().split()
for i in range(0, len(a)):
    list1.append(int(a[i]))
for j in range(1, 30):
    for item in list1:
        c = c+ (item-j)**2
    list2.append(c)
l = len(list2)
for z in range(0, l):
    list3.append(list2[z+1]-list2[z])
list3.sort()
print(list3[0])

Submission status: Runtime Error

Solution code:
n=int(input())
M=list(map(int,input().split()))
m=sorted(M)
l=[]
for p in range(m[0],m[n-1]):
  L=0
  for i in range(n):
    L+=(m[i]-p)**2
  l.append(L)
print(min(l))

Submission status: Runtime Error

Solution code:
import sys

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


def cal(number):
    ans = 0
    for X in Xn:
        ans += (X - number)**2
    return ans

ans = sys.maxsize
for i in range(Xn[1], Xn[-1], 1):
    ans = min(ans, cal(i))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

tmp = np.array(num).mean() 
if tmp-int(tmp)<0.5:
    tmp=int(tmp)
else:
    tmp=int(tmp)+1
ans = 0
for i in num:
    ans += (i-tmp)**2
print(ans)

Submission status: Runtime Error

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

for i in range(N):
  for j in range(1,101):
    print(min(sum(j-x[i])**2))

Submission status: Runtime Error

Solution code:
loss = 0
ans = 0
minimum = min(zahyou)
maximum = max(zahyou)
for i in range(minimum, maximum+1):
    loss = 0
    for j in zahyou:
        loss += (j-i)**2
        
    if i == minimum:
        ans = loss
    if loss < ans:
        ans = loss
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]

ans = [0] * N
checkd = [False] * N

for i in range(M):
    if not checkd[sc[i][0]-1]:
        checkd[sc[i][0]-1] = True
        ans[sc[i][0]-1] = sc[i][1]
    else:
        if ans[sc[i][0]-1] != sc[i][1]:
            print('-1')
            sys.exit()

if N >= 2 and checkd[0] and ans[0] == 0:
    print('-1')
    sys.exit()

real = 0
for i in ans:
    real = real * 10 + i
    
print(real)

Submission status: Runtime Error

Solution code:
n = int(input())

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

l = min(xs)
r = max(xs)

costs = []
for i in range(l, r):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)

print(min(costs))

Submission status: Runtime Error

Solution code:
n = int(input())

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

l = min(xs)
r = max(xs)

costs = []
for i in range(l, r):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)
    print(cost)

print(min(costs))

Submission status: Runtime Error

Solution code:
n = int(input())

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

l = min(xs)
r = max(xs)

costs = []
for i in range(l, r):
    cost = 0
    for j in xs:
        cost += (j - i) ** 2
    costs.append(cost)

print(min(costs))

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = float("inf")
for p in range(1, max(X)+1):
   
    for x in X:
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)

Submission status: Runtime Error

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

for p in range(1, max(X)+1):
    x_sum=0
    for x in X:
        x_sum+=(x-p)**2
    ans = min(ans, x_sum)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()
People = list(map(int, input().split()))
for P in range(1, max(People)):
    Distance = list(map(lambda x: (x-P)**2), People)
    Total_Distance = sum(Distance)
Total_Distance_List = list(Total_Distance)
print(min(Total_Distance_List))

Submission status: Runtime Error

Solution code:
N = input()
coordinate = list(map(int, input().split()))
result = 0
resultl = 0

for j in range(N):
    result += (1-coordinate[j])**2

for i in range(1,101):
    for k in range(N):
        resultl += (i-coordinate[k])**2

    if resultl < result:
        result = resultl
    resultl = 0

print(result)

Submission status: Runtime Error

Solution code:
N=int(input())
X=list(map(int,input().split()))
P=round(sum(X)/N) #四捨五入
print(sum((x-P)**2 for x in X))　#listに入っているものを一つずつ取り出して、合計する

Submission status: Runtime Error

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

Submission status: Runtime Error

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