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:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
import math
import statistics
n = I()
xl = LI()

# n人が消費する体力の総和の最小値
# 数直線上にn人が住んでいる
# i番目がXi
# n人全員が参加する集会
# 任意の整数値の座標で集会を開く。座標pで集会を開くときはi番目の人は(Xi-p))**2の体力を消費する。

xl_mean = math.ceil(statistics.mean(xl))

sigma_pow = sum([(x-xl_mean)**2 for x in xl])

print(sigma_pow)

Submission status: Wrong Answer

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

ans=10**1000
for p in range(X[0],X[-1]):
    tmp=0
    for x in X:
        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()))
X.sort()

ans=10**10
for p in range(X[0],X[-1]):
    tmp=0
    for x in X:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
input()
x=list(map(int,input().split()))
r=10**9
for i in range(min(x),max(x)):
	s=0
	for j in x:
		s+=(i-j)**2
	r=min(r,s)
print(r)

Submission status: Wrong Answer

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

total = 0
m = round(sum(X) / N)
print(m)
for i in X:
    total += (m - i) ** 2
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
small = 10000000
temp = 0
p_max = max(X)

for p in range(1, p_max + 1):
  for i in range(N):
    temp += (X[i] - p)**2
    
  if temp < small:
    small = temp
    
print(small)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
small = 100000000
temp = 0

for p in range(1, 101):
  for i in range(N):
    temp += (X[i] - p)**2
    
  if temp < small:
    small = temp
    
print(small)

Submission status: Wrong Answer

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

min_x = 100 * 100
for p in range(1, 100+1, 1):
  total = 0
  for xi in x:
    total += (xi - p) ** 2

  min_x = min([min_x, total])

print(min_x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def stamina(x, p):
    return (x - p) ** 2


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

    min_sum = 100 ** 2
    for p in range(1, 101):
        s_sum = 0
        for p_x in Xs:
            s_sum += stamina(p_x, p)

        min_sum = min(min_sum, s_sum)

    print(min_sum)
resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 10000
for p in range(1,101):
  d = 0
  for x in l:
    d += (x-p)**2
  ans = min(d,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(val)

Submission status: Wrong Answer

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

ave = sum(x) // n
ans1 = sum((xi - ave)**2 for xi in x)
ans2 = sum((xi - ave - 1)**2 for xi in x)
print(min(ans1, ans2))

if n==2:
    print(n)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls)):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Submission status: Wrong Answer

Solution code:
num = int(input())
pos = list(map(int,input().split()))
maxpos = max(pos)
minhealth = 1e9
count = 0
for i in range(maxpos):
    for j in pos:
        count += (j-i)**2
    minhealth = min(minhealth, count)
    count = 0
print(minhealth)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
answer = 10**4
for p in range(1, 100):
  power = 0
  for j in range(N):
    power += (p-nums[j])**2
  answer = min(answer, power)
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
answer = 10**4
for i in range(N):
  power = 0
  for j in range(N):
    if i == j:
      continue
    else:
      power += (nums[i]-nums[j])**2
  answer = min(answer, power)
print(answer)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=int(sum(b)/a)
d=0
for i in range(a):
  d=d+(b[i]-c)**2
print(d)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))
p = sum(data) / n
 
Sum = 0
for i in data:
	Sum  += (i - p) ** 2 
print(Sum)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))
Sum = sum(data)
a = Sum / n

print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())

PosList = []
TempSum = 0
ReturnSum = 0

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


for pos in range(1,max(PosList)):
    TempSum = 0
    for nPos in range(n):
        TempSum += (pos - PosList[nPos])**2
    if pos == 1:
        ReturnSum = TempSum
    elif ReturnSum > TempSum:
        ReturnSum = TempSum
    """
    print("Position = "+str(pos))
    print("TempSum = "+ str(TempSum))
    print("ReturnSum = " + str(ReturnSum))
    print("----------------------------")
    """

print(ReturnSum)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())

PosList = []
TempSum = 0
ReturnSum = 0

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


for pos in range(max(PosList)):
    TempSum = 0
    for nPos in range(n):
        TempSum += (pos - PosList[nPos])**2
    if pos == 0:
        ReturnSum = TempSum
    elif ReturnSum > TempSum:
        ReturnSum = TempSum
    """
    print("Position = "+str(pos))
    print("TempSum = "+ str(TempSum))
    print("ReturnSum = " + str(ReturnSum))
    print("----------------------------")
    """

print(ReturnSum)

Submission status: Wrong Answer

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

a=sum(x)/len(x)
b=min(sum(x)//len(x)-a,sum(x)//len(x)+1-a)

c=0

for i in x:
    c+=(i-b)**2

print(int(c))

Submission status: Wrong Answer

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

a=sum(x)/len(x)
c=0

for i in x:
    c+=(i-a)**2

print(int(c)+1)

Submission status: Wrong Answer

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

ans = 10**4+1

for i in range(X_list_min[0], X_list_min[-1]+1):
    ans_temp = 0
    for j in range(N):
        ans_temp += (X_list_min[j] - i)**2
    ans = min(ans, ans_temp)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
l=len(X)
s=10**10
for i in range(min(X),max(X)):
    x=[]
    for j in range(l):
        x.append((X[j]-i)**2)
    if s>sum(x):
        s=sum(x)
print(s)

Submission status: Wrong Answer

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

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


print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = list(map(int, input().split()))
min_dist = 10**9
for i in range(max(line)):
  sum_dist = 0
  for j in range(n):
    sum_dist += (line[j] - i)**2
  if sum_dist < min_dist:
    min_dist = sum_dist
print(min_dist)

Submission status: Wrong Answer

Solution code:
import math

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

min_hp = math.inf

for i in range(address[0], address[-1]+1):
	if sum(map(lambda x: (x - i) ** 2, address)) < min_hp:
		min_hp = sum(map(lambda x: (x - i) ** 2, address))
		
print(min_hp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min_n = min(lst)
max_n = max(lst)
min_count = 100000
for i in range(min_n, max_n + 1):
  count = 0
  for j in range(n):
    count += (lst[j] - i) ** 2
  if count < min_count:
    min_count = count
print(min_count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for x in range(max(X)+1):
  ans_temp = 0
  for i in range(N):
    ans_temp += (X[i]-x)**2
  ans = max(ans, ans_temp)
print(ans)

Submission status: Wrong Answer

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

ans = 10**18
ans_ = 0

for P in range(-N, N + 1):
    ans_ = 0
    for x in X:
        ans_ += (x - P) ** 2
        ans = min(ans, ans_)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

N=int(input())
X = list(map(int,input().split()))
print(X)
s=0
for i in range(len(X)):
    s+=X[i]
P=int(s/N)

Sum_round_down=0
Sum_round_up=0
for i in range(len(X)):
    Sum_round_down+=(P-X[i])**2
    Sum_round_up+=(P+1-X[i])**2
if(Sum_round_down>=Sum_round_up):
    Sum=Sum_round_up
else:
    Sum=Sum=Sum_round_down
print(int(Sum))

Submission status: Wrong Answer

Solution code:
"""Boot-camp-for-Beginners_002_C_Rally_19-August-2020.py"""
import numpy as np
import sys

N=int(input())
X = list(map(int,input().split()))
print(X)
s=0
for i in range(len(X)):
    s+=X[i]
P=s/N

Sum=0
for i in range(len(X)):
    Sum+=(P-X[i])**2
print(int(Sum)+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
mid = (arr[0]+arr[-1])//2
small = 0
large = 0
for i in arr:
    if i < mid:
        small += 1
    else:
        large += 1


ans = float('inf')
if large < small:
    for i in range(mid, -1, -1):
        g = 0
        for j in arr:
            g += (j-i)**2
        if g < ans:
            ans = g
        else:
            break

else:
    for i in range(mid, arr[-1]):
        g = 0
        for j in arr:
            g += (j-i)**2
        if g < ans:
            ans = g
        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
arr = list(map(int, input().split()))
mid = math.ceil(sum(arr)/n)
s = 0
for i in arr:
    s += (i-mid)**2
print(s)

Submission status: Wrong Answer

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

for i in range(min(X), max(X)+1):
    s = 0
    for j in range(N):
        s += (X[j] - i)**2
    
    if s < sum_min:
        sum_min = s

print(sum_min)

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = sum(a) // n
ans = 0
for i in a:
    ans += (i - x) * (i - x)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = sum(a) / n
ans = 0
for i in a:
    ans += (i - x) ** 2
print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = math.ceil(sum(a) / n)
ans = 0
for i in a:
    ans += (i - x) ** 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
x = math.ceil(sum(a) // n) + 1
ans = 0
for i in a:
    ans += (i - x) ** 2
print(ans)

Submission status: Wrong Answer

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

cnt = 0
mini = float('inf')

P = max(X)

for i in range(P):
    for j in range(len(X)):
        cnt += (X[j] - i)**2
    if cnt < mini:
        mini = cnt
    cnt = 0

print(mini)

Submission status: Wrong Answer

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

cnt = 0
mini = float('inf')

P = max(X)

for i in range(1, P):
    for j in range(len(X)):
        cnt += (X[j] - i)**2
    if cnt < mini:
        mini = cnt
    cnt = 0

print(mini)

Submission status: Wrong Answer

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

cnt = 0
P = sum(X) // len(X)

for i in range(len(X)):
    cnt += (X[i] - P - 1)**2 

print(cnt)

Submission status: Wrong Answer

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

costs = []
for i in range(max(X)):
  costs.append(sum(map(lambda x: (x - i)**2, X)))

print(min(costs))

Submission status: Wrong Answer

Solution code:
N = int(input())
cc = list(map(int,input().split()))
count = 0
min_sum = float('inf')
for i in range(1,101):
  for j in cc:
    count += (i-j)**2
  min_sum = min(min_sum,count)
print(min_sum)

Submission status: Wrong Answer

Solution code:
def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = 100**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost)

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

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

min_x = X[0]
max_x = X[0]
for i in range(N):
  if X[i] > max_x: max_x = X[i]
  if X[i] < min_x: min_x = X[i]

ans = 100000
for p in range(min_x, max_x+1):
  ans_p = 0
  for x in X:
    ans_p += (x-p)**2
  if ans > ans_p: ans = ans_p

print(ans)

Submission status: Wrong Answer

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

min_=min(x)
max_=max(x)

xy=round((min_+max_)/2)

ans=0
for xx in x:
  ans+=(xx-xy)**2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
C=list(map(int,input().split()))
Cmin,Cmax = min(C),max(C)
Sums=[]
for i in range(Cmin,Cmax+1):
  for j in range(len(C)):
    Sums.append((C[j]-i)^2)
print(min(Sums))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
res = 10**7
pre = 10**7
for i in range(x[0],x[-1]):
  tmp = 0
  for j in x:
    tmp += (j-i)**2
  res = min(tmp,res)
  if pre<tmp:
    break
  pre = tmp
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
mid = x[len(x)//2]
strt = mid
res = 10**7
if strt>x[-1]//2:
  strt = x[-1]//2
  for i in range(strt,x[-1]):
    tmp = 0
    for j in x:
      tmp += (j-i)**2
    res = min(tmp,res)
else:
  strt = 0
  for i in range(strt,mid):
    tmp = 0
    for j in x:
      tmp += (j-i)**2
    res = min(tmp,res)
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
mid = x[len(x)//2]
strt = mid
res = 10**7
if strt>n//2:
  strt = n//2
  for i in range(strt,x[-1]):
    tmp = 0
    for j in x:
      tmp += (j-i)**2
    res = min(tmp,res)
else:
  strt = 0
  for i in range(strt,mid):
    tmp = 0
    for j in x:
      tmp += (j-i)**2
    res = min(tmp,res)
print(res)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
x = list(map(int,input().split(" ")))
a=math.ceil(sum(x)/n)
s = sum((xx - a)**2 for xx in x)
print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int, input().split()))
 
ans =100000000000
tmp=0
cnt=0
 
for i in range(X[0],X[-1]+1):
    for j in range(len(X)):
        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()))

ans =100000000000
tmp=0
cnt=0

for i in range(X[0],X[-1]+1):
    for j in range(len(X)):
        tmp += (X[j]-i)**2
    if ans > tmp:
        ans =tmp
        tmp=0
print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import average

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

p=int(average(x))

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

print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import average

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

p=int(average(x))

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=10**12
cou=0

for i in range(min(x),max(x)):
  for j in range(n):
    cou+=(x[j]-i)**2
  if cou<ans:
    ans=cou
  cou=0  
print(ans)

Submission status: Wrong Answer

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

sumx=sum(x)
if sumx%n<5:
  ave=sumx//n
else:
  ave=(sumx//n)+1

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

Submission status: Wrong Answer

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

sumx=sum(x)
if sumx%n==0:
  ave=sumx//n
else:
  ave=(sumx//n)+1
  
for i in range(n):
  ans+=(ave-x[i])**2
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
k = 10**6

for i in range(a[0],(a[-1]+1)//2+1):
  total = 0
  for s in a:
    total +=(i-s)**2
  #print(total)
  k = min(k,total)
print(k)

Submission status: Wrong Answer

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

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

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

print(min(sl))

Submission status: Wrong Answer

Solution code:
import sys

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

if x.count(1) == n:
    print(1)
    sys.exit()


x_min = x[0]
x_max = x[n-1]
min_sum = 10000000
for p in range(x_min, x_max):

    sum = 0
    for e in x:
        len = (e - p)**2
        sum += len
    # print("p", p, "sum", sum, "min_sum", min_sum)
    if sum <= min_sum:
        min_sum = sum
print(min_sum)

Submission status: Wrong Answer

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

x_min = x[0]
x_max = x[n-1]
min_sum = 10000000
for p in range(x_min, x_max):

    sum = 0
    for e in x:
        len = (e - p)**2
        sum += len
    # print("p", p, "sum", sum, "min_sum", min_sum)
    if sum <= min_sum:
        min_sum = sum
print(min_sum)

Submission status: Wrong Answer

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

ans = 1000000000

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

print(ans)

Submission status: Wrong Answer

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

ans = 10000000

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
hp_min = 10000 * n
for i in range(min(x), max(x)):
    hp = sum([(x[j] - i) ** 2 for j in range(len(x))])
    if hp < hp_min:
        hp_min = hp
print(hp_min)

Submission status: Wrong Answer

Solution code:
def dist(x, p):
    return (x - p)**2


n = int(input())
x = [int(i) for i in input().split()]
index = len(x) // 2
new_x = sorted(x)
p1 = - (- sum(x) // len(x))
p2 = sum(x) // len(x)
ans = [0, 0]
for i in new_x:
    ans[0] += dist(i, p1)
    ans[1] += dist(i, p2)
print(ans)

Submission status: Wrong Answer

Solution code:
def dist(x, p):
    return (x - p)**2


n = int(input())
x = [int(i) for i in input().split()]
index = len(x) // 2
new_x = sorted(x)
p = - (- sum(x) // len(x))
ans = 0
for i in new_x:
    ans += dist(i, p)
print(ans)

Submission status: Wrong Answer

Solution code:
input()
*X,=sorted(map(int,input().split()))
a=10**4
for p in range(X[0], X[-1]+1):
 a=min(a, sum((n-p)**2 for n in X))
print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int, input().strip().split()))
X=0
for i in range(n):
    X+=x[i]
XX=0
for i in range(n):
    XX+=(x[i])**2
s=X//n
t=s+1
S=XX-n*(s**2)
T=n*(t**2)-2*t*X+XX
print(min(S,T))

Submission status: Wrong Answer

Solution code:

N = int(input())
X = list(map(int, input().split()))
ans = 10e9
for i in range(1,max(X)):
    tmp = 0
    for j in range(N):
        tmp += (X[j]-i)**2
    if tmp < ans:
        ans = tmp
#    print(tmp)
print(ans)

Submission status: Wrong Answer

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

for i in range(1,101):
	result = 0
	for j in range(n):
		result += (x[j] - i) ** 2
	if answer == 0 or answer > result:
		answer = result

print(answer)

Submission status: Wrong Answer

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

print(min(ans))

Submission status: Wrong Answer

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

print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
l = np.array(list(map(int,input().split())))
min_sum = 10**9
for i in range(np.min(l),np.max(l)+1):
    square_list = np.square(l - i)
    min_sum = min(min_sum,np.sum(square_list))

Submission status: Wrong Answer

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

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

INF = pow(10,5)

# @njit
def solve(n,a):
  res = INF
  for i in range(1,101):
    res = min(res,sum(pow(i-x,2) for x in a))
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

print(numpy.sum(square_list))

Submission status: Wrong Answer

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

minimum = 10000000

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

minX = X[0]
maxX = X[-1]
ans = 999999999

for i in range(minX+1, maxX, 1):
    x = (X - i) ** 2
    total = np.sum(x)
    ans = min(ans, total)

print(ans)

Submission status: Wrong Answer

Solution code:
n, x = int(input()), list(map(int, input().split()))
px = 0
a = 100 * 100
for i in range(100):
  s = 0
  for j in x:
    s += (i-j) ** 2
  if a > s:
    a = s
print(a)

Submission status: Wrong Answer

Solution code:
n, x = int(input()), list(map(int, input().split()))
px = 0
a = 100 * 100
for i in range(100):
  s = 0
  for j in x:
    s += (i-j) ** 2
  if a < s:
    break
  else:
    a = s
print(a)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

p = int(sum(x)/n)
q = p+1

a = sum([(i-p)**2 for i in x])
b = sum([(i-q)**2 for i in x])

print(p,q,a,b)

print(min([a,b]))

Submission status: Wrong Answer

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

ans = 10**18
ans_ = 0

for P in range(1, N + 1):
	ans_ = 0
	for x in X:
		ans_ += (x - P)**2
	if ans > ans_:
		ans = ans_

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def Rally(n, array):
    min_ = max(np.array(array)*10000000000000)
    for i in range(0,max(np.array(array))):
        if min_ > sum((np.array(array)-i)**2):
            min_ = sum((np.array(array)-i)**2)
    return min_

n = int(input())
array = list(map(int,input().split()))
print(Rally(n, array))

Submission status: Wrong Answer

Solution code:
import numpy as np

def Rally(n, array):
    min_ = max(np.array(array)*1000000)
    for i in range(0,max(np.array(array))):
        if min_ > sum((np.array(array)-i)**2):
            min_ = sum((np.array(array)-i)**2)
    return min_

n = int(input())
array = list(map(int,input().split()))
print(Rally(n, array))

Submission status: Wrong Answer

Solution code:
import numpy as np

def Rally(n, array):
    min_ = max(np.array(array)*100)
    for i in range(0,max(np.array(array))):
        if min_ > sum((np.array(array)-i)**2):
            min_ = sum((np.array(array)-i)**2)
    return min_

n = int(input())
array = list(map(int,input().split()))
print(Rally(n, array))

Submission status: Wrong Answer

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

print(sum([(x-mtg_p)**2 for x in l_x]))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
x=list(map(int,input().split()))
b=math.ceil(sum(x)/n)
a=[(b-z)**2 for z in x]
print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min_p = (1 / n) * sum(x)

stamina = sum((x[i] - min_p) ** 2 for i in range(n))

print(stamina)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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