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:
def main(n,x):
    if n == 1:
        return x[0]
    res = 10**31-1
    for point in range(min(x), max(x)):
        val = 0
        for i in range(len(x)):
            val += (x[i] - point)**2
        res = min(res, val)
    return res

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

Submission status: Wrong Answer

Solution code:

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


sumDist = sum(x_list)
p = sumDist // N

ans = 0
for i in range(N):
    ans += (x_list[i] - p)**2
print(ans)

Submission status: Wrong Answer

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

L = min(X)
R = max(X)

ans = 10000000
for P in range(L, R - L + 1):
    tmp = 0
    for Xi in X:
        tmp += (Xi - P) ** 2
    ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math

def solve(N: int, X: "List[int]"):
    p = sum(X) / N
    print(math.ceil(sum([(x-p)**2 for x in X])))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = 10**9+7
for i in range(max(X)):
  point = 0
  for j in X:
    point += ((j-i)**2)
  if point < ans:
    ans = point
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]

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

Submission status: Wrong Answer

Solution code:
import math
def solve():
    N = int(input())
    X = list(map(int, input().split()))
    mn = sum(X) / N 
    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: Wrong Answer

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

min_goukei = 250 * 100

for i in range(100):
    goukei = 0
    for j in range(n):
        goukei += (x_list[j] - i)**2
    if goukei < min_goukei:
        min_goukei = goukei

print(min_goukei)

Submission status: Wrong Answer

Solution code:

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

    mu = sum(x)/len(x)
    res = 0
    for i in x:
        res += (i - mu)**2

    print(int(res+1))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
result=0
for p in range(1,max(x)):
  s=0
  for i in range(0,n):
    s+=(x[i]-p)**2
  if p==1:
    result=s
  else:
    if s<result:
      result=s
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = 10**5
for i in range(max(X)):
  point = 0
  for j in X:
    point += ((j-i)**2)
  if point < ans:
    ans = point
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
import numpy as np

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

    minpower = np.inf
    for P in range(max(X)):
        minpower = min(sum([(x-P)**2 for x in X]), minpower)

    print(minpower)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
n=int(input())
x=list(map(int,input().split()))

a=sum(x)//n+1
s=0
for i in range(n):
    s+=(x[i]-a)**2

print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
cost = 10**36
for i in range(min(List),max(List)):
  temp = 0
  for item in List:
    temp += (item - i)**2
  if temp <= cost:
    cost = temp
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
print(X)
ans = 10**5
for i in range(max(X)):
  point = 0
  for j in X:
    point += ((j-i)**2)
  if point < ans:
    ans = point
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = input().split()
X = [int(s) for s in X]
if N == 1:
    print(0)
else:
    X = sorted(X)
    range_X = X[-1] - X [0]

    E_min = 10000000000000000000000
    for p in range(range_X):
        E = 0
        for x in X:
            E += (x-p)**2
        if E < E_min:
            E_min = E
    print(E_min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m = -(-sum(x) // len(x))
ans = 0
for xi in x:
    ans += (xi - m)**2

print(ans)

Submission status: Wrong Answer

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

phy = []
tmp = 0
max = 100000000000000

for i in range(101):
    phy.append(i*i)

for j in range(1,x[n-1]):
    for k in range(n):
        tmp += phy[abs((j-x[k]))]
    if(max > tmp):
        max = tmp
    tmp = 0

print(max)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math

def solve(N: int, X: "List[int]"):
    p = math.ceil(sum(X) / N)
    print(sum([(x-p)**2 for x in X]))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

s = sum(x)
N = len(x)
mean = s / N
mean = math.ceil(mean)
r = 0

for i in range(n):
    r = r + (x[i] - mean) * (x[i] - mean)

print(r)

Submission status: Wrong Answer

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

min = min(x_list)
max = max(x_list)

sum_min = 10000000000
for target_i in range(min, max):
    sum_tmp = 0
    for i in range(n):
        sum_tmp += (target_i - x_list[i]) ** 2
    if sum_min >= sum_tmp:
        sum_min = sum_tmp

print(sum_min)

Submission status: Wrong Answer

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

INF = 10**7

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

X.sort()
ans = INF
for p in range(X[0],X[N-1]):
    sum = 0
    for i in range(N):
        sum += cost(X[i],p)
    ans = min(ans,sum)

print(ans)

Submission status: Wrong Answer

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

ave = int(sum(x)/len(x))+1

cout = 0

for i in range(len(x)):
    cout = cout + (ave-x[i])*(ave-x[i])

print(cout)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math
N = int(input())
X = list(map(int, input().split()))
if len(X) % 2 == 0:
    mean = math.floor(sum(X) / len(X))
else:
    mean = math.ceil(sum(X) / len(X))
print(sum([(i - mean)**2 for i in X]))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
X = sorted(list(map(int, input().split())))
start = X[0]
end = X[-1]

ans = 100001
for i in range(start, end+1):
    tmp = sum([(x-i)**2 for x in X])
    ans = min(tmp,ans) 
print(ans)

Submission status: Wrong Answer

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

for i in range(min(X),max(X)):
    sum_pw = 0
    for x in X:
        sum_pw += (i-x)**2
    if sum_pw < min_pw:
        min_pw = sum_pw

print(min_pw)

Submission status: Wrong Answer

Solution code:
from math import ceil

from numpy import average

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

p = ceil(average(x))

result = 0
for i in range(n):
    result += ((x[i] - p) ** 2)

print(result)

Submission status: Wrong Answer

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

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

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split(' ')))
length = len(X)
distlist = [10000] * 101
for P in range(1, 101):
    dist = 0
    for i in range(length):
        dist += (X[i] - P) ** 2
    distlist[P] = dist
print(min(distlist))

Submission status: Wrong Answer

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

ans=100000
f=0
for p in range(1,101):
  f=0
  for y in x:
    f+=(y-p)*(y-p)
  ans=min(ans,f)



print(ans)

Submission status: Wrong Answer

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

if (len(set(x)) == 1):
  print(x[0])
else:
  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: Wrong Answer

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

Submission status: Wrong Answer

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

Solution code:
N = int(input())
X = list(map(int, input().split()))
X_max = max(X)
ans = float('inf')
for i in range(X_max):
    tmp_ans = 0
    for x in X:
        tmp_ans += (x - i) ** 2
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]

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

Submission status: Wrong Answer

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

del x[n:]

print(x)

now = float('inf')
new = 0

for i in range(100):
  new = 0
  for j in range(len(x)):
    new += (x[j] - (i + 1))** 2
  if new < now:
    now = new

print(now)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
Xl = list(map(int, input().split()))
Xl.sort()
minx = Xl[0]
maxx = Xl[-1]
minsum = sys.maxsize
for i in range(minx, maxx):
    sumd = 0
    for x in Xl:
        sumd += (x - i)**2
    if sumd < minsum:
        minsum = sumd
print(minsum)

Submission status: Wrong Answer

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

n = input()
X = input().rstrip().split(' ')

n = int(n)
x = [0 for _ in range(n)]

for a in range(n):
    x[a] = int(X[a])
    
x.sort()

count = 1000000
tei = 0

for a in range(x[0],x[len(x)-1]):
    tei = 0
    for b in x:
        tei += (b-a)**2
    count = min(tei,count)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    import math
    n = int(input())
    x = list(map(int,input().split()))
    b =  math.ceil(sum(x)/n)
    m = 0
    for i in x:
        m += (i-b) * (i-b)
    print(m)
resolve()

Submission status: Wrong Answer

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

ave = math.ceil(sum(a) / len(a))

print(sum([(i-ave)**2 for i in a]))

Submission status: Wrong Answer

Solution code:
N = int(input())
Xs = list(map(int, input().split()))
max_dis = 10**18
for i in range(max(Xs)):
  sum_dis = sum([(x-i)**2 for x in Xs])
  if sum_dis<max_dis:
    max_dis = sum_dis
print(max_dis)

Submission status: Wrong Answer

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

X = sorted(X)
range_X = X[-1] - X [0]

E_min = 10000000000000
for p in range(range_X):
    E = 0
    for x in X:
        E += (x-p)**2
    if E < E_min:
        E_min = E
print(E_min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[int(i) for i in input().split(" ")]
x=sorted(x)
mind=-1
for i in range(x[0],x[len(x)-1]):
    sum=0
    for j in x:
        sum+=(j-i)**2
    if mind>sum or mind==-1:
        mind=sum

print(mind)

Submission status: Wrong Answer

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

s = sum(x)
N = len(x)
mean = s / N
mean = math.ceil(mean)
r = 0

print(mean)

for i in range(n):
    r = r + (x[i] - mean) * (x[i] - mean)

print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
cost = 10**18
for i in range(min(List),max(List)):
  temp = 0
  for item in List:
    temp += (item - i)**2
  if temp < cost:
    cost = temp
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xl = list(map(int, input().split()))
Xl.sort()
minx = Xl[0]
maxx = Xl[-1]
minsum = 1000000
for i in range(minx, maxx):
    sumd = 0
    for x in Xl:
        sumd += (x - i)**2
    if sumd < minsum:
        minsum = sumd
print(minsum)

Submission status: Wrong Answer

Solution code:
#!python3.4
# -*- coding: utf-8 -*-
# abc156/abc156_c
import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    X = i2nn()
    ave = math.ceil(sum(X) / N)
    print(sum(map(lambda x: (x - ave)**2, X)))
    return

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
ans = 999999999
for i in range(1,100):
    tmp = 0
    for j in X:
        tmp += (i-j)**2
    if tmp < ans:
        ans = tmp
        ans = i
print(ans)

Submission status: Wrong Answer

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

anc = float('inf')
tmp = 0
for p in range(min(c),max(c)):
    for i in c:
        tmp += (i-p)**2
    if tmp < anc:
        anc = tmp
    tmp = 0
print(anc)

Submission status: Wrong Answer

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


MaxCoo = max(X)
MinCoo = min(X)
ave = (MaxCoo+MinCoo)//2
Range = MaxCoo-MinCoo
MinCost = 10**10
for i in range(Range//2):
    pos = ave+i
    cost = 0
    for member in X:
        cost += (member-pos)**2
    if cost < MinCost:
        MinCost = cost

    pos = ave-i
    cost = 0
    for member in X:
        cost += (member-pos)**2
    if cost < MinCost:
        MinCost = cost
print(MinCost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[int(i) for i in input().split(" ")]
x=sorted(x)
mind=-1
for i in range(x[0],int(x[len(x)-1]/2+1)):
    sum=0
    for j in x:
        sum+=(j-i)**2
    if mind>sum or mind==-1:
        mind=sum

print(mind)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
from sys import stdin


def get_result(data):
    N, X = data[0][0], data[1:][0]
    X = np.array(X)
    max_X = max(X)
    tmp = np.zeros(max_X)
    for i in range(max_X):
        tmp[i] = np.sum((X - i) ** 2)
    return int(min(tmp))

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = list(map(int, input().split()))

left = min(x)
right = max(x)

min_cost = 100000000000000
min_pos=-1

for i in range(left,right+1):
  cost=0
  for j in range(n):
    cost = cost + (x[j]-i)*(x[j]-i)
  if min_cost>cost:
    min_cost=cost
    min_pos=i

print(min_pos)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

p = ceil(sum(x) / n)
result = 0
for i in range(n):
    result += (x[i] - p) ** 2

print(result)

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, X):
    ans = float("inf")
    for i in range(max(X)):
        cost = 0
        for x_i in X:
            cost +=  (x_i - i) ** 2
        ans = min(ans, cost)
    print(ans)

if __name__ == '__main__':
    N = int(sys.stdin.readline().strip())
    X = list(map(int,sys.stdin.readline().strip().split(" ")))
    
    solve(N, X)

Submission status: Wrong Answer

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

p_min = min(data)
p_max = max(data)

ans_min = 100000000000000

for i in range(p_min, p_max):
  ans = 0

  for d in data:
    ans += (i-d)**2

  if ans < ans_min:
    ans_min = ans

print(ans_min)

Submission status: Wrong Answer

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

for i in range(max(X)):
    tmp_ans = 0
    for xi in X:
        tmp_ans += (xi - i) ** 2
    ans = min(ans, tmp_ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
min_d = 10**18

for p in range(x[0],x[n-1]):
    sm = 0
    for j in range(n):
        sm += (x[j] - p)**2
    else:
        min_d = min(min_d,sm)
print(min_d)

Submission status: Wrong Answer

Solution code:
#!python3.4.3
import statistics
import math

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

mean = statistics.mean(x_list)
mean = math.ceil(mean)

result = 0

for x in x_list:
  result += (x - mean)**2
  
print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

n = input()
xs = map(int, raw_input().split())

avg = 1.0 * sum(xs) / n


mindist = math.ceil(sum((x - avg) ** 2 for x in xs))
print int(mindist)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=sorted(list(map(int,input().split())))
ans=10**10
for P in range(L[0],L[-1]):
    temp=0
    for l in L:
        temp+=(l-P)**2
    ans=min(temp,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
t=sum(a)/n
s=0
for i in range(n):
    s+=math.pow(t-a[i],2)
if s==int(s):
    print(int(s))
else:
    print(int(s)+1)

Submission status: Wrong Answer

Solution code:
def main(n, x):
    ans = []

    for p in range(1, n + 101):
        t = 0
        for _x in x:
            t += (_x - p) ** 2

        ans.append(t)

    print(min(ans))


if __name__ == "__main__":
    n = int(input())
    x = list(map(int, input().split()))

Submission status: Wrong Answer

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

mini = min(X)
maxi = max(X)
consume = 10000

for i in range(mini, maxi):
    pos = i
    total = sum([(pos - j) ** 2 for j in X])
    consume = min(total, consume)

print(consume)

Submission status: Wrong Answer

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

mean = np.mean(a)

mean1 = int(mean)
mean2 = mean + 1
mean3 = mean - 1

ans1 = 0
ans2 = 0
ans3 = 0
for i in range(n):
    ans1 += (a[i] - mean1)**2
    ans2 += (a[i] - mean2)**2
    ans3 += (a[i] - mean3)**2



print(min(ans1, ans2,ans3))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ll = len(l)
res = 0
ans = 10000

for i in range(1, 101):
    for j in range(ll):
        res += (l[j] - i)**2
    ans = min(ans, res)
    res = 0

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, X: "List[int]"):
    st=min(X)
    end=max(X)
    costmin=1000000
    for p in range(st,end-st+1):
        cost=0
        for i in range(N):
            cost+=(p-X[i])**2
        if cost<costmin: costmin=cost
    print(costmin)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
x = map(int, input().split())
hp_list = [sum([(xx-p)**2 for xx in x]) for p in range(1, 101)]
print(min(hp_list))

Submission status: Wrong Answer

Solution code:
N=int(input())
#N,K=map(int,input().split())
X=list(map(int,input().split()))
P=[]
for p in range(max(X)):
    a=0
    for x in X:
        a+=(p-x)**2

    P.append(a)

print(min(P))

Submission status: Wrong Answer

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

ma = max(X)
mi = min(X)

ans = 10**9

for n in range(mi, ma):
  count = 0
  
  for x in X:
    count += abs(x-n)**2

  if ans > count:
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
INF = pow(10,9)
_min = INF

for p in range(max(x)):
  total = 0
  for xi in x:    
    total += pow((xi-p),2)
  if total < _min:
    _min = total
print(_min)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
mid=sum(X)//N+1

ans=0

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

Submission status: Wrong Answer

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
n = int(input())
x = list(map(int, input().split()))

s = 10000000000
for p in range(max(x)):
    sss = 0
    for i in range(n):
        a = (x[i]-p)**2
        sss += a
    if sss < s:
        s = sss
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=list(map(int,input().split()))
ans=10**10
for P in range(L[0],L[-1]):
    temp=0
    for l in L:
        temp+=(l-P)**2
    ans=min(temp,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
X = list(map(int, input().split()))
sorted(X)
start = X[0]
end = X[-1]

ans = 100001
for i in range(start, end+1):
    tmp = sum([(x-i)**2 for x in X])
    ans = min(tmp,ans) 
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int,input().split()))
tmp = 0
mi =100000000000
for i in range(1,101):
  for k in range(N):
    tmp = (X[k] - i)**2
  if tmp < mi:
    mi = tmp
print(mi)

Submission status: Wrong Answer

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

avg = sum(x_list)/ len(x_list)
avg_up = math.ceil(avg)
avg_down = math.floor(avg)

up_sum = 0
down_sum = 0
for i in x_list:
    up_sum += (i - avg_up)**2
    down_sum += (i - avg_up)**2
    
print(min(up_sum,down_sum))

Submission status: Wrong Answer

Solution code:
"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
# from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
from fractions import Fraction
mod = int(pow(10, 9)+7)


def ii(): return int(input())


def si(): return str(input())


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


def li(): return list(mi())


def fii(): return int(stdin.readline())


def fsi(): return str(stdin.readline())


def fmi(): return map(int, stdin.readline().split())


def fli(): return list(fmi())


abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}


def getKey(item): return item[0]


def sort2(l): return sorted(l, key=getKey)


def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]


def isPowerOfTwo(x): return (x and (not (x & (x - 1))))


def decimalToBinary(n): return bin(n).replace("0b", "")


def ntl(n): return [int(i) for i in str(n)]


def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res


graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000


def bfs(d, v):
    q = []
    q.append(v)
    visited[v] = 1
    while len(q) != 0:
        x = q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i] != 1:
                visited[i] = 1
                q.append(i)
        print(x)


def make_graph(e):
    d = {}
    for i in range(e):
        x, y = mi()
        if x not in d:
            d[x] = [y]
        else:
            d[x].append(y)
        if y not in d:
            d[y] = [x]
        else:
            d[y].append(x)
    return d


def gr2(n):
    d = defaultdict(list)
    for i in range(n):
        x, y = mi()
        d[x].append(y)
    return d


def connected_components(graph):
    seen = set()

    def dfs(v):
        vs = set([v])
        component = []
        while vs:
            v = vs.pop()
            seen.add(v)
            vs |= set(graph[v]) - seen
            component.append(v)
        return component

    ans = []
    for v in graph:
        if v not in seen:
            d = dfs(v)
            ans.append(d)
    return ans


def primeFactors(n):
    s = set()
    while n % 2 == 0:
        s.add(2)
        n = n // 2
    for i in range(3, int(sqrt(n)) + 1, 2):
        while n % i == 0:
            s.add(i)
            n = n // i
    if n > 2:
        s.add(n)
    return s


def find_all(a_str, sub):
    start = 0
    while True:
        start = a_str.find(sub, start)
        if start == -1:
            return
        yield start
        start += len(sub)


def SieveOfEratosthenes(n, isPrime):
    isPrime[0] = isPrime[1] = False
    for i in range(2, n):
        isPrime[i] = True
    p = 2
    while (p * p <= n):
        if (isPrime[p] == True):
            i = p * p
            while (i <= n):
                isPrime[i] = False
                i += p
        p += 1
    return isPrime


def dijkstra(edges, f, t):
    g = defaultdict(list)
    for l, r, c in edges:
        g[l].append((c, r))

    q, seen, mins = [(0, f, ())], set(), {f: 0}
    while q:
        (cost, v1, path) = heappop(q)
        if v1 not in seen:
            seen.add(v1)
            path = (v1, path)
            if v1 == t:
                return (cost, path)

            for c, v2 in g.get(v1, ()):
                if v2 in seen:
                    continue
                prev = mins.get(v2, None)
                next = cost + c
                if prev is None or next < prev:
                    mins[v2] = next
                    heappush(q, (next, v2, path))
    return float("inf")


def binsearch(a, l, r, x):
    while l <= r:
        mid = l + (r-1)//2
        if a[mid]:
            return mid
        elif a[mid] > x:
            l = mid-1
        else:
            r = mid+1
    return -1


def reVal(num):

    if (num >= 0 and num <= 9):
        return chr(num + ord('0'))
    else:
        return chr(num - 10 + ord('A'))

# Utility function to reverse a string


def strev(str):

    len = len(str)
    for i in range(int(len / 2)):
        temp = str[i]
        str[i] = str[len - i - 1]
        str[len - i - 1] = temp

# Function to convert a given decimal
# number to a base 'base' and


def fromDeci(res, base, inputNum):

    index = 0  # Initialize index of result

    # Convert input number is given base
    # by repeatedly dividing it by base
    # and taking remainder
    while (inputNum > 0):
        res += reVal(inputNum % base)
        inputNum = int(inputNum / base)

    # Reverse the result
    res = res[::-1]

    return res


n = ii()
l = li()
print((min(l)+max(l))//2)

Submission status: Wrong Answer

Solution code:
# C
N = int(input())
A = list(map(int,input().split()))
mi = min(A)
ma = max(A)
ans = 10 ** 12
for i in range(mi,ma):
    su = 0
    for j in A:
        su += (i-j)**2
    ans = min(ans,su)
print(ans)

Submission status: Wrong Answer

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

ls = sorted(ls)

ans = 10000000000000
x = 0
for i in range(ls[0],ls[-1]+1):
  tmp = 0
  for a in ls:
    tmp += (a-i)**2
  if ans > tmp:
    x = i
    ans = tmp
print(x)

Submission status: Wrong Answer

Solution code:
def main(n,x):
    res = 10**31-1
    for point in range(min(x), max(x)):
        val = 0
        for i in range(len(x)):
            val += (abs(x[i] - point)**2)
        res = min(res, val)
    return res

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