Problem:


Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

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

Sample Input 1

2
1 4

Sample Output 1

5

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

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

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354



Sample input:
2
1 4


Sample output:
5

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
lmax=0
for i in range(n):
    if lmax<l[i]:
        lmax=l[i]
sumlist=[]

for i in range(lmax):
    sumlist.append(0)
total=0
for i in range(lmax):
    for j in range(n):
        t=(l[j]-i)*(l[j]-i)
        total+=t
    sumlist[i]=total
    total=0
min=99999999999999999999999999999999999
for i in range(lmax):
    if min>sumlist[i]:
        min=sumlist[i]
print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
lmax=0
for i in range(n):
    if lmax<l[i]:
        lmax=l[i]
sumlist=[]

for i in range(lmax):
    sumlist.append(0)
total=0
for i in range(lmax):
    for j in range(n):
        t=(l[j]-i)*(l[j]-i)
        total+=t
    sumlist[i]=total
    total=0
print(sumlist)
min=99999999999999999999999999999999999
for i in range(lmax):
    if min>sumlist[i]:
        min=sumlist[i]
print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
lmax=0
for i in range(n):
    if lmax<l[i]:
        lmax=l[i]
sumlist=[]

for i in range(lmax):
    sumlist.append(0)
total=0
for i in range(lmax):
    for j in range(n):
        t=(l[j]-i)*(l[j]-i)
        total+=t
    sumlist[i]=total
    total=0
min=99999999999999999999
for i in range(lmax):
    if min>sumlist[i]:
        min=sumlist[i]
print(min)

Submission status: Wrong Answer

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

ans = float("inf")

for i in range(min(X)+1, max(X)+1):
    num = 0
    for j in range(len(X)):
        num += (X[j]-i)**2

    ans = min(ans, num)

print(ans)

Submission status: Wrong Answer

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

dist_min = 9999
for i in range(min(x),max(x)):
    dist_sum = 0
    for j in range(n):
        dist_sum += (x[j] - i)**2
    if dist_sum < dist_min:
        dist_min = dist_sum

print(dist_min)

Submission status: Wrong Answer

Solution code:
n=int(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):
    power=0
    for j in range(n):
        power=power+(x[j]-i)**2
    if power<minp:
        minp=power
    else:
        minp=minp
print(minp)

Submission status: Wrong Answer

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

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

print(dist_min)

Submission status: Wrong Answer

Solution code:
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    X = input([int, N])
    c = ceil(sum(X) / N)
    ans = 0
    for x in X:
        ans += (c - x) ** 2
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Wrong Answer

Solution code:
def atcoder2():
    a = [list(map(int,input().split())) for l in range(2)]

    n= a[0][0]
    x_l = a[1]

    P = sum(x_l)/n

    print(a,n)
    print(P)
    if P - int(P) >= 0.5:
        add= 1
    else:
        add = 0

    P = int(P)+add
    
    print(P)

    result = 0
    for Xi in x_l:
        result = result + (Xi-P)**2 

    print(result)
    return 


atcoder2()

Submission status: Wrong Answer

Solution code:
n = input()
l = map(int,raw_input().split())
mxs = 10**9


for i in range(max(l)):
    sm = 0
    for j in l:
        sm += (j-i)**2
    if sm<mxs:
        mxs = sm
print mxs

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
x=list(map(int,input().split()))
max=max(x)
d=dict(Counter(x))
m=10000
for i in range(1,max+1):
    s=0
    for key,vlaue in d.items():
        s+=(i-key)**2*vlaue
    m=min(s,m)
print(m)

Submission status: Wrong Answer

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

total = 100**n
for p in range(min(x), max(x)):
    tmp = 0
    for i in x:
        tmp += (i - p)**2
    if tmp < total:
        total = tmp

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
ptc = 0
tc = 100**2*100
for i in range(min(X), max(X)):
    for k in X:
        ptc += (k-i)**2
    tc = min(ptc,tc)
    ptc = 0
print(tc)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
tmp = 0
tmp2 = 0
ans = 10 ** 10
for i in range(1,101):
  for a in range(N):
    tmp = abs(X[a] - i) ** 2
    tmp2 = tmp
  ans = min(ans,tmp2)
print(str(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(100):
  for j in range(N):
    t += (List[j]-i-1)**2

  if s>t:
    s = t

print(t)

Submission status: Wrong Answer

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

for i in range(N):
  s += List[i]

ave = s/N

for i in range(N):
  t += (List[i]-ave)**2

print(t)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
x = list(map(int,input().split()))
z = np.array(x)
ans = 10**10
for i in range(min(x),max(x)+1):
    z -= np.array([i for _ in range(n)])
    y = z*z
    ans = min(ans,sum(y))

print(ans)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
N =int(input())
X = map(int,input().split())
c = 0
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: Wrong Answer

Solution code:
n = int(input())
x_list = list(map(int,input().split()))
x_list.sort()
cost_tot_min = 100000

for p in range(x_list[0],x_list[-1]+1):
    cost_tot = 0
    for x in x_list:
        cost = (x-p)**2
        cost_tot += cost
    if cost_tot < cost_tot_min:
        cost_tot_min = cost_tot

print(cost_tot_min)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
 
cost = 0
 
for i in range(-50, 201):
  cand = 0
  for x in X:
    cand += (x-i)**2
  cost = min(cost, cand)
 
print(cost)

Submission status: Wrong Answer

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)**2
  cost = min(cost, cand)
 
print(cost)

Submission status: Wrong Answer

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

def cost_calc(list_x, p):
  cost = 0
  for x in list_x:
    cost += (x - p)**2
  return cost

cost = 10**20
for _ in range(min(list_x),max(list_x)):
  tmp = cost_calc(list_x, _)
  if tmp < cost:
    cost = tmp
print(cost)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    X = readInts()
    mid = (sum(X) + (n-1)) // n
    ans = 0
    for i in range(n):
        ans += (mid - X[i]) ** 2
    print(ans)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 10**9
for i in range(1, max(X)):
    z = 0
    for x in X:
        z += (x-i)**2
    ans = min(ans, z)

print(ans)

Submission status: Wrong Answer

Solution code:
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
import math
N = int(input())
arr = list(map(int,input().split()))
add = sum(arr)
avg = int(math.ceil(add/N)) 
ans = 0
for i in range(N):
	ans += (avg-arr[i])*(avg-arr[i])
print(int(ans))

Submission status: Wrong Answer

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

sum=0
for x in s:
    sum=sum+x**2
    
g=0
for x in s:
    g=g+x
    
z=[]
n=len(s)
for i in range(100):
    p=i+1
    x=n*p**2 -2*g*p +sum
    z.append(x)
print(min(z))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
mid = int(sum(x)/n)
ans = 1000000000000000000000
for j in range(x[0], x[n-1] + 1):
    total = 0
    for i in range(n):
        total += (x[i] - j)**2
    if total < ans:
        ans = total
    else:
        continue
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dis = [0]*a
for p in range(a):
    for i in range(a):
        dis[p] += (li[i]-(p+1))**2
        
print(min(dis))

Submission status: Wrong Answer

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+1):
    for j in range(n):
        y = (x[j] - (mi+i))**2
        z += y
    a.append(z)
    z = 0

print(min(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
x=sorted(x)
ans=10**5
count=0
a=x[0]
b=x[n-1]
d=b-a
for i in range(a,d):
  for j in range(n):
    count+=(x[j]-i)**2
  if ans>count:
    ans=count
  count=0
    
print(ans)

Submission status: Wrong Answer

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()))

Submission status: Wrong Answer

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(min(s1, s2))

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

Submission status: Wrong Answer

Solution code:
def f():
    people_num = int(input())
    people_coords = [int(i) for i in input().split()]
    sum_of_distances = 0
    meeting_coord = sum(people_coords) // people_num
    for person in people_coords:
        sum_of_distances += abs(meeting_coord - person) ** 2
    return sum_of_distances

print(f())

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(x) for x in input().split()]
print(x)
center = sum(x)//len(x)
center2 = center+1
ans, ans2 =0, 0
for i in x:
    ans += (i-center)**2
    ans2 += (i-center2)**2

print(ans) if ans<ans2 else print(ans2)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(x) for x in input().split()]
center = sum(x)//len(x)
ans =0
for i in x:
    ans += (i-center)**2
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
count=0
for i in range(N):
    count+=X[i]
P=count//N+1
result=0
for i in range(N):
    result+=(X[i]-P)**2
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

def test_coordinates(arr, coord):
    return sum([(x - coord) * (x - coord) for x in arr])
N = int(input())

coordinates = input().strip().split()
coordinates = [int(x) for x in coordinates]
costs = []

for i in range(max(coordinates)):
    costs.append(test_coordinates(coordinates, i))
print(min(costs))

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
ave=sum(X)//N
a=[(X[i]-ave)**2 for i in range(N)]
b=[(X[i]-ave+1)**2 for i in range(N)]
print(min(sum(a),sum(b)))

Submission status: Wrong Answer

Solution code:
import math

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

M = math.ceil(sum(X)/N)

ans = 0

for n in range(N):
    ans += (X[n]-M)*(X[n]-M)
    
print(ans)

Submission status: Wrong Answer

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

if N%2==0:
    av = sum(X)//N
else:
    av = (sum(X)//N)+1

total = 0

for i in X:
    total += ((i-av)**2)

print(total)

Submission status: Wrong Answer

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

if N%2==0:
    av = sum(X)/N
else:
    av = (sum(X)/N)+1
    
total = 0

for i in X:
    total += ((i-av)**2)

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
import math
av = math.ceil(sum(X)/N)
total = 0

for i in X:
    total += ((i-av)**2)

print(total)

Submission status: Wrong Answer

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

av = sum(X)//N
total = 0

for i in X:
    total += ((i-av)**2)
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 10**5
for i in range(input_x[0],input_x[-1]+1):
    cost_x = sum([(x-i)**2 for x in input_x])
    if cost_x < ans:
        ans = cost_x
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import math

def main():
    num = int(input())
    x_list = list(map(int, input().split()))
    min_num = 10**10    
    for i in range(max(x_list)):
        result = 0  
        for j in x_list:
            result += pow((i - j), 2)
        
        if result < min_num:
            min_num = result
    print(min_num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
T = 0
for i in range(N):
	T += X[i]
K = T/N
P = float(round(K))
Square_Total = 0
for i in range(N):
	Square_Total += X[i]**2
print(int(Square_Total + float(N)*((P-K)**2) - (T**2)/N))

Submission status: Wrong Answer

Solution code:
import os
import math

def main():
    num = int(input())
    x_list = list(map(int, input().split()))
    max_p = max(x_list)
    min_p = min(x_list)
    p = math.floor((max_p + min_p)/2)
    result = 0
    for i in range(num):
        result += pow((p - x_list[i]), 2)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import os
import math

def main():
    num = int(input())
    x_list = list(map(int, input().split()))

    p = math.ceil(sum(x_list)/len(x_list))
    result = 0
    for i in range(num):
        result += pow((p - x_list[i]), 2)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import os
import math

def main():
    num = int(input())
    x_list = list(map(int, input().split()))

    p = math.floor(sum(x_list)/len(x_list))
    
    p += 1
    result = 0
    for i in range(num):
        result += pow((p - x_list[i]), 2)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
sum0=1000000000
sum1=0
for i in range(1,x[n-1]+1):
  sum1=[0]*n
  for j in range(n):
    sum1[j]=(x[j]-i)**2
    
  if sum0>sum(sum1):
    sum0=sum(sum1)
    
print(sum0)

Submission status: Wrong Answer

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

mean = int(sum(h)/len(h))+1
#print(mean)
dist = 0
for i in range(len(h)):
    dist += (h[i]-mean)**2
print(dist)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
 
a = int(input())
b=list(map(int,input().split()))
sum = 0

for i in range(a):
    sum += b[i]


ans_pre = sum/a
ans = round(ans_pre)

print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
import math
n = int(input())
li = list(map(int,input().split()))
ans = 0
point = math.ceil(statistics.mean(li))
for i in li:
    ans += (i - point)**2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

minv = (max(X) - min(X))**2

for i in range(100):
    temp = 0

    for j in X:
        temp += (j - i) ** 2

    if minv > temp:
        minv = temp


print(minv)

Submission status: Wrong Answer

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

X.sort()

Ans=N*(X[-1]**2)
for i in range(X[-1]):
    Sum=0
    for j in range(N):
        Sum=Sum+(X[j]-i)**2
    if Sum<Ans:
        Ans=Sum

print(Ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
best_score = None
for i in range(np.min(X), np.max(X)+1):
    score = np.sum(np.power(X - i, 2))
    if best_score is None:
        best_score = score
    elif best_score > score:
        best_score = score

Submission status: Wrong Answer

Solution code:
a = int(input())
b = map(int, input().split())
ans_list =[]
list_b =list(b)
if a == 0:
    ans_list.append(0)
else:
    for i in range(list_b[a-1]+1):
        ene_list =map(lambda x: (x-i)**2, list_b)
        sum_ene= sum(list(ene_list))
        ans_list.append(sum_ene)

print(min(ans_list))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = map(int, input().split())
ans_list =[]
list_b =list(b)
for i in range(list_b[a-1]+1):
    ene_list =map(lambda x: (x-i)**2, list_b)
    sum_ene= sum(list(ene_list))
    ans_list.append(sum_ene)

print(min(ans_list))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = map(int, input().split())
ans_list =[]
list_b =list(b)
for i in range(list_b[a-1]):
    ene_list =map(lambda x: (x-i)**2, list_b)
    sum_ene= sum(list(ene_list))
    ans_list.append(sum_ene)

print(min(ans_list))

Submission status: Wrong Answer

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

def main():
    N = int(input())
    Xs = [int(s) for s in input().split()]
    maxX = max(Xs)
    
    min_sp_sum = 10000
    for i in range(1,maxX+1):
        sp_sum = 0
        for x in Xs:
            sp_sum += ((i-x)**2)
        min_sp_sum = min(min_sp_sum,sp_sum)
    
    print(min_sp_sum)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N= int(input())
X =list(map(int,input().split()))
P = [i for i in range(X[0],X[-1] + 1)]
MIN=-1
for p in P:
    total=0
    for x in X:
        total+=(x - p)**2
    if(MIN == -1):
        MIN=total
    else:
        MIN=min(MIN,total)
print(MIN)

Submission status: Wrong Answer

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


res = 10**100

avg = sum(xs)//N
mod = sum(xs)%N
for d in range(avg, avg+mod):
  r = 0
  for x in xs:
    r += (x-d) ** 2
  res = min(res, r)

print(res)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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

if N == 1:
    print(0)
    sys.exit()
    
a.sort()

line = []

for i in range(a[0],a[N-1]+1):
    line.append(i)

def calculation(hairetu,P): #Pにはline，すなわち数直線の値を入れる
    len_hairetu = len(hairetu)
    cal_result = 0
    for i in range(0,len_hairetu):
        cal_result += (hairetu[i] - P)**2
    return cal_result


def search_area(hairetu,line):
    length = len(line)
    if length < 5:
        return line
    
    half = length//2
    f_N = half//2

    f1 = half-f_N
    f3 = half+f_N
    if calculation(hairetu,f1) < calculation(hairetu,f3):
        line = line[0:half]
        search_area(hairetu,line)
    elif calculation(hairetu,f1) > calculation(hairetu,f3):
        line = line[half:length]
        search_area(hairetu,line)
    
search_area(a,line)

min = 1000000
for i in range(0,len(line)):
    if calculation(a, i) < min:
        min = calculation(a,i)

print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

a.sort()

line = []

for i in range(a[0],a[N-1]+1):
    line.append(i)

def calculation(hairetu,P): #Pにはline，すなわち数直線の値を入れる
    len_hairetu = len(hairetu)
    cal_result = 0
    for i in range(0,len_hairetu):
        cal_result += (hairetu[i] - P)**2
    return cal_result


def search_area(hairetu,line):
    length = len(line)
    if length < 5:
        return line
    
    half = length//2
    f_N = half//2

    f1 = half-f_N
    f3 = half+f_N
    if calculation(hairetu,f1) < calculation(hairetu,f3):
        line = line[0:half]
        search_area(hairetu,line)
    elif calculation(hairetu,f1) > calculation(hairetu,f3):
        line = line[half:length]
        search_area(hairetu,line)
    
search_area(a,line)

min = 1000000
for i in range(0,len(line)):
    if calculation(a, i) < min:
        min = calculation(a,i)

print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
X.sort()
min = 100*100
for t in range(1, 101):
    sum = 0
    for x in X:
        sum += (x - t)**2
    if sum < min: min = sum
print(min)

Submission status: Wrong Answer

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

if X_sum % N == 0:
    div = round(X_sum / N)
    ans = 0
    for i in range(N):
        ans += (X[i] - div) ** 2
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
x=list(map(int,input().split()))
num=math.ceil(sum(x)/n)
ans=0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
o1 = (sum(li))//n
o2 = o1 + 1
li1 = []
li2 = []
for i in range(n):
    li1.append((int(li[i]-o1))**2)
for j in range(n):
    li2.append((int(li[j]-o2))**2)
if sum(li1) >= sum(li2):
    print(sum(li2))
else:
    print(sum(li2))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L=min(X)
H=max(X)
smallest = 10**4
for p in range(L,H):
  sum=0
  #print(p)
  for j in range(N):
    sum=sum+(X[j]-p)**2
  #print(sum)
  if sum<smallest:
    smallest=sum

print(smallest)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

smallest = 10**4
for p in range(max(X)-min(X)):
  sum=0
  for j in range(N):
    sum=sum+(X[j]-p)**2
  #print(sum)
  if sum<smallest:
    smallest=sum

print(smallest)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = 69*100**3
for i in range(101):
  tmp = 0
  for j in range(n):
    tmp += (i-j)**2
  ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
cnt=0
P=sum(X)//N
for i in range(N):
    cnt += (i-P)**2
print(cnt)

Submission status: Wrong Answer

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

"""
    min(X) 以上、 max(X) 以下の整数を全探索
    1 <= X[i] <= 100 なので時間計算量は O(N(Xmax - Xmin)) <= O(N^2)
"""

X.sort()
ans = 10 ** 12
for p in range(X[0], X[N - 1]):
    total = 0
    for x in X:
        total += (x - p)** 2
    ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import mean
import math
N = (map(int, input().split()))
X = list(map(int, input().split()))
A = mean(X)
A = math.ceil(A)
a_list =[]
for i in range(0, len(X)):
    B = X[i] - A
    B =pow(B,2)
    a_list.append(B)
Sum = sum(a_list)
print(Sum)

Submission status: Wrong Answer

Solution code:
from statistics import mean
import math
N = (map(int, input().split()))
X = list(map(int, input().split()))
A = mean(X)
A = math.ceil(A)
list =[]
for i in range(0, len(X)):
    B = X[i] - A
    B =pow(B,2)
    list.append(B)
Sum = sum(list)
print(Sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
ans = 10**9
for i in range(max(s)):
  sum = 0
  for j in s:
    sum += (i-j)**2
  if sum < ans: ans = sum

print(ans)

Submission status: Wrong Answer

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

P = round(sum(X)/N)
print(sum([(x-P)**2 for x in X]))

Submission status: Wrong Answer

Solution code:
n = int(input())
X = list(map(int, input().split()))
dist = float("inf")
d = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin, xmax):
	d = 0
	for x in X:
		d += (x - i) ** 2
	if d < dist:
		dist = d
print(dist)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = list(map(int, input().split()))
dist = 1000000000
d = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin, xmax):
	for x in X:
		d += (x - i) ** 2
	if d < dist:
		dist = d
	d = 0
print(dist)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = list(map(int, input().split()))
dist = 1000000000
d = 0
for i in range(X[0], X[n - 1]):
	for x in X:
		d += (x - i) * (x - i)
	if d < dist:
		dist = d
	d = 0
print(dist)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = list(map(int, input().split()))
dist = 1000000
d = 0
for i in range(X[n - 1] + 1):
	for x in X:
		d += (x - i) * (x - i)
	if d < dist:
		dist = d
	d = 0
print(dist)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = list(map(int, input().split()))
dist = 1000000
d = 0
for i in range(X[n - 1]):
	for x in X:
		d += (x - i) * (x - i)
	if d < dist:
		dist = d
	d = 0
print(dist)

Submission status: Wrong Answer

Solution code:
n = int(input())
xs = list(map(int, input().split()))
xs_min = min(xs)
xs_max = max(xs)

fatigue_min = float("inf")

for i in range(xs_min, xs_max + 1):
  fatigue = 0
  for x in xs:
    fatigue += (x - i) ** 2
  if fatigue < fatigue_min:
    fatigue_min = fatigue
  else:
    print(fatigue_min)
    exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
address = list(map(int, input().split()))
sort_address = sorted(address)
sum = 0
sum_min = 100000

for i in range(sort_address[0], sort_address[-1] + 1):
    for j in sort_address:
        sum += (i - j)**2
    if sum < sum_min:
        sum_min = sum
    sum = 0
print(sum_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
address = list(map(int, input().split()))
sort_address = sorted(address)
sum = 0
sum_min = 100000

for i in range(sort_address[0], sort_address[-1]):
    for j in sort_address:
        sum += (i - j)**2
    if sum < sum_min:
        sum_min = sum
    sum = 0
print(sum_min)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

p = [int(np.mean(x)), int(np.mean(x)) + 1]
xnp = np.array(x)

min_xp = 0
for pi in p:
    if min_xp == 0:
        min_xp = np.square(xnp - pi).sum()
    elif min_xp > np.square(xnp - pi).sum():
        min_xp = np.square(xnp - pi).sum()
print(min_xp)

Submission status: Wrong Answer

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

zahyo = 10000
sum_x = sum(X)

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

Submission status: Wrong Answer

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, 100):
    for item in list1:
        c = c+ (item-j)**2
    list2.append(c)
l = len(list2)
for z in range(0, l-1):
    list3.append(list2[z+1]-list2[z])
list3.sort()
print(list3[0])