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())
X = list(map(int,input().split(" ")))





S = []
for p in range(1,N+1):
    #pで開催する時の消費体力の総和
    sum_power = 0
    for x in X[:]:
        sum_power += (x-p)**2
    S.append(sum_power)


print(min(S))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
cen = sorted(X)[int(-len(X)/2)]
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
            all = False
ans = 0
for b in X:
    ans = ans + (b-cen)**2
if all == True:
    ans = 0
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

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

print(min(ans))

Submission status: Wrong Answer

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





S = []
for p in range(1,N+1):
    #pで開催する時の消費体力の総和
    sum_power = 0

    for x in X:
        sum_power += (x-p)**2
    S.append(sum_power)


print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 0
ans_sum = 0

for P in range(Xmin,Xmax+1):
  for i in range(N):
    cal = (X[i] - P)**2
    ans_sum = ans_sum + cal
  if P == Xmin:
    ans = ans_sum
    ans_sum = 0
  elif ans >= ans_sum:
    ans = ans_sum
  else :
    ans_sum = 0
print(ans)

Submission status: Wrong Answer

Solution code:
def solv_quadratic_equation(a, b, c):
    """ 2次方程式を解く  """
    D = (b**2 - 4*a*c) ** (1/2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2

import numpy as np

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

a_1 = sum(num_list)
a_2 = sum(num_list**2)

ans_num = int(np.ceil((-(a_1)**2/len_val)+a_2))

ans_1, ans_2 = solv_quadratic_equation(len_val, -2*a_1, a_2-ans_num)

if str(ans_1)[-1] == '0' or str(ans_2)[-1] == '0':
    print(ans_num)
else:
    while str(ans_1)[-1] == '0' or str(ans_2)[-1] == '0':
        ans_num += 1
        ans_1, ans_2 = solv_quadratic_equation(len_val, -2*a_1, a_2-ans_num)
    print(ans_num)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
n = input().split()
total = 0
for i in n: 
  if int(i) == N:
    continue
  else:
    total = total + pow((int(i)-N),2)
print(total)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
xLst = list(map(int, input().split()))
sm = 0
ans = int(sys.maxsize)

#開催する座標
for i in range(1, n + 1):
    #全員の体力の計算
    sm = sum((xLst[ii] - i)**2 for ii in range(n))
    if ans > sm:
        ans = sm        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
z = 10000
for p in range(x[0],x[-1]+1):
    temp = 0
    for xx in x:
        temp += (xx-p)**2
    z = min(temp,z)
print(z)

Submission status: Wrong Answer

Solution code:
#import math

N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
P = 0
while P < xList[-1]:
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)
  P +=1

result = min(dList)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
z = 10000
for p in range(x[0],x[-1]):
    temp = 0
    for xx in x:
        temp += (xx-p)**2
    z = min(temp,z)
print(z)

Submission status: Wrong Answer

Solution code:
import math
from statistics import mean, median,variance,stdev
N = int(input())
X = list(map(int,input().split()))
a = sum(X)
ave = round(a/N)
b = 0
for i in range(N):
    b +=(X[i]-20)**2
print(b)

Submission status: Wrong Answer

Solution code:
#import math

N = int(input())
XXX = input().split()

xList = []
for i in XXX:
  xList.append(int(i))

dList = []
P = 0
while P < xList[-1]:
  D = 0
  for xi in xList:
    D += (xi - P)*(xi - P)
  dList.append(D)
  P +=1

result = dList.index(min(dList))

print(result)

Submission status: Wrong Answer

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

sum = 0
max = 0
minn = 100

for i in range(1,1000):
  sum = 0
  for j in range(n):
    sum += (x[j]-i)**2
  if minn > sum:
    minn = sum

print(minn)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
n = input().split()
total = 0
for i in n: 
  total = total + pow((int(i)-N),2)
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xn = [int(x) for x in input().split()]
P = max(Xn)
ans = float('inf')

for j in range(1,P):
  pos = 0
  for i in Xn:
    pos += float((i-j)**2)
    ans = min(pos, ans)

print(ans)

Submission status: Wrong Answer

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

mean = sum(L) / len(L)
r = round(mean)
La = list(map(lambda x: (x - r)^2, L))

print(sum(La))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
x=list(map(int,input().split()))
x=np.array(x)
ans=10**100
for i in range(np.min(x),np.max(x),1):
  d=np.sum( (x-i)**2)
  ans=min(ans,d)
print(ans)

Submission status: Wrong Answer

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

sum = 0
max = 0
minn = 100

for i in range(100):
  sum = 0
  for j in range(n):
    sum += (x[j]-i)**2
  if minn > sum:
    minn = sum

print(minn)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np 
N = int(input())
X = np.array(list(map(int, input().split())))
sums = []
for i in range(N):
        sums.append(np.sum((X-(i+1))**2))

print(min(sums))

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
s=0
sum=0
for i in X:
    sum+=i

sum=round(sum/len(X),0)
for i in X:
    tmp=(i-sum)**2
    s=s+tmp
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xn = [int(x) for x in input().split()]
P = max(Xn)
ans = float('inf')
for j in range(1,P):
    pos = 0
    for i in Xn:
        pos += int(i-j)**2
    ans = min(pos, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int,input().split()))
s=0
sum=0
for i in X:
    sum+=i

sum=round(sum/len(X),0)
print(sum)
for i in X:
    tmp=(i-sum)**2
    s=s+tmp
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
temp = [int(s) for s in input().split()]
rarry = 0
min = 100000007
min_temp = 0
for n_ in range(max(temp)):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
max = 0
for a in X:
    sum = sum + a
    if max < a:
        max = a -1
    for c in X:
        if(a != c):
            all = False
ans = 0
for b in X:
    ans = ans + (b-math.ceil(max))**2
if all == True:
    ans = 0
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import statistics

def cal_hp(p, num_list):
    total = 0
    for num in num_list:
        temp = (num - p) ** 2
        total = total + temp
    return total

line1 = input()
line2 = input()

num_list = line2.split(" ")
num_list = [int(n) for n in num_list]
ans_list = []
for i in range(0, max(num_list)):
    ans_list.append(cal_hp(i, num_list))
print(min(ans_list))

Submission status: Wrong Answer

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



S = []
for p in range(1,N+1):
    #pで開催する時の消費体力の総和
    sum_power = 0
    for x in X:
        sum_power += (x-p)**2
    S.append(sum_power)


print(min(S))

Submission status: Wrong Answer

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

min = 0
result = 0
for i in range(N):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
l1 = min(x)
l2 = max(x)
ans,sum = 100000000,0
for i in range(l1, l2+1):
    for j in x:
        sum += (i-j)**2
    if sum < ans:
        ans = sum
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
max = 0
for a in X:
    sum = sum + a
    if max <= a:
        max = a
    for c in X:
        if(a != c):
            all = False
ans = 0
for b in X:
    ans = ans + (b-math.ceil(max))**2
if all == True:
    ans = 0
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

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

mean = sum(L) / len(L)
r = round(mean)
La = list(map(lambda x: (x - r)^2, L))

result = sum(La)

print(result)

Submission status: Wrong Answer

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

min = 0
result = 0
for i in range(N):
    for j in X:
        print(j)
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
l1 = min(x)
l2 = max(x)
ans,sum = 0,0
for i in range(l1, l2+1):
    for j in x:
        sum += (i-j)**2
    if sum < ans:
        ans = sum
print(ans)

Submission status: Wrong Answer

Solution code:
MAX_Xi = 101

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


def cost(live_pos, held_pos):
    return (live_pos - held_pos) ** 2

min_cost = 100000
for held_pos in range(MAX_Xi):
    total_cost = sum(map(lambda live_pos: cost(live_pos, held_pos), live_pos_list))
    if total_cost < min_cost:
        min_cost = total_cost

print(min_cost)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
l1 = min(x)
l2 = max(x)
ans, sum = 0, 0
for i in range(l1, l2+1):
    for j in x:
        sum += (i-j) * (i-j)
    if sum > ans:
        ans = sum
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

Xn = [int(x) for x in input().split()]
P = max(Xn)
ans = float('inf')##[0] * P
for j in range(1,P):
    pos = 0
    for i in Xn:
        pos += (i-j)**2
    ans = min(pos, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
temp = list(map(int, input().split()))
rarry = 0
min = 100000007
min_temp = 0
for n_ in range(max(temp)):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Submission status: Wrong Answer

Solution code:
N = int(input())
x  = [int(x) for x in input().split()]
x.sort()
ans = 0
le = len(x)//2-1
a = (sum(x)+N-1)//N
for i in x:
  ans+=(i-a)**2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) #1行目のNを取得する
x = list(map(int, input().split())) #s_1 s_2を分割して取得し、sに値を入れる

m = 0
for p in range(N):
	s = 0
	for i in range(N):
		s += (x[i] - (p + 1)) ** 2
		print(s)
    
	if p == 0 or s < m:
		m = s

print(m)

Submission status: Wrong Answer

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

sumlist = []

if len(set(x)) == 1:
    print(n * (x[0] - n) ** 2)
else:
    for i in range(1, max(max(x), n)):
        s = 0
        for j in range(n):
            s += (x[j] - i) ** 2
        sumlist.append(s)

    if sumlist == []:
        print((x[0] - n) ** 2)
    else:
        print(min(sumlist))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import statistics
from scipy.stats.mstats import gmean

N=int(input())
X=list(map(int,input().split()))
X.sort()
#print(X)
#med=int(statistics.median(X))
#med=int((X[0]+X[N-1])/2)
med=gmean(X)

min=10**10
sum=0
while True:
    sum=0
    for i in range(N):
        sum+=(X[i]-med)**2
    if sum<min:
        min=sum
        prev=sum
        med+=1
    else:
        break

print(int(prev))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
pivot = (x[0] + x[-1]) // 2
Sum = 0
Min = 99999
for i in range(-1000,1001):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
temp = list(map(int, input().split()))
rarry = 0
min = 100000007
min_temp = 0
for n_ in range(max(temp)):
    for i in temp:
        min_temp += ((i - n_) ** 2)
    #print(min_temp)
    if(min > min_temp):
        min = min_temp
    min_temp = 0


print("{}".format(str(min)))

Submission status: Wrong Answer

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

Physical_strength = 0
flag = 0
n=0
while 1:
    n += 1
    flag=0
    for Xi in X:
        flag += (Xi-n)**2
    if Physical_strength > flag or Physical_strength==0:
        Physical_strength = flag
    elif Physical_strength < flag and n > N:
        break

print(Physical_strength)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
CCC = 0
j = 1
max_A = max(A)
for j in range(101):#部屋の座標最大値までのループ
    if j == 0:
        continue
    CCC = 0
    if N == 1:
        B.append(A[0])
        break
    for k in range(N):#各部屋からの計算
        CCC += (A[k] - j) ** 2
    B.append(CCC)
x = min(B)
print(x)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
        if(a != c):
            all = False
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-math.ceil(C))**2
if all == True:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
CCC = 0
j = 1
max_A = max(A)
for j in range(101):#部屋の座標最大値までのループ
    if j == 0:
        continue
    CCC = 0
    if N == 1:
        B.append(A[0])
        break
    for k in range(N):#各部屋からの計算
        CCC += (A[k] - j) ** 2
    B.append(CCC)
x = min(B)
print(len(B))
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())

Xn = [int(x) for x in input().split()]
P = max(Xn)
ans = float('inf')##[0] * P
for j in range(1,P):
    pos = 0
    for i in Xn:
        pos1 = (i-j)**2
        if pos1 > 0:
            pos += pos1

    ans = min(pos, ans)


print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdin

n = int(input())
x_list_str = stdin.readline().rstrip().split()
x_list = [int(i) for i in x_list_str]

# 体力のリスト
sum_hp_list = []

min_x = min(x_list)
max_x = max(x_list)

if min_x == max_x:
    print(0)
    exit()
for i in range(min_x, max_x):
    print(i)
    sum_hp = 0
    for x in x_list:
        sum_hp += (x-i)**2
    sum_hp_list.append(sum_hp)

print(min(sum_hp_list))

Submission status: Wrong Answer

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

Physical_strength = 0
flag = 0
n=0
while 1:
    n += 1
    flag=0
    for Xi in X:
        flag += (Xi-n)**2
    if Physical_strength > flag or Physical_strength==0:
        Physical_strength = flag
    elif Physical_strength < flag:
        break

print(Physical_strength)

Submission status: Wrong Answer

Solution code:
import math
import sys
X = int(input())
L = list(map(int,input().split()))
if(X == 1):
    print(0)
    sys.exit()
ans = []
tmp = sum(L)/len(L)
#tmp = int(tmp)
#print("tmp",tmp)
anser = map(lambda x:(x-tmp)**2,L)
print(math.ceil(sum(anser)))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0

x_sum = sum(x_list)


x_amari = x_sum%n
x_sum = x_sum // n
if x_amari != 0:
    x_sum += 1

for x in x_list:
    ans += (x-x_sum)**2
    continue

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
CCC = 0
j = 1
max_A = max(A)
for j in range(100):#部屋の座標最大値までのループ
    if j == 0:
        continue
    CCC = 0
    if N == 1:
        B.append(A[0])
        break
    for k in range(N):#各部屋からの計算
        CCC += (A[k] - j) ** 2
    B.append(CCC)
x = min(B)
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_1 = sum(num_list)
a_2 = sum(num_list**2)

ans_num = (-(a_1)**2/len_val)+a_2
print(int(np.ceil(ans_num)))

Submission status: Wrong Answer

Solution code:


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

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

    print(int(res))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import sys
X = int(input())
L = list(map(int,input().split()))
if(X == 1):
    print(L[0]**2)
    sys.exit()
ans = []
tmp = sum(L)/len(L)
#tmp = int(tmp)
#print("tmp",tmp)
anser = map(lambda x:(x-tmp)**2,L)
print(math.ceil(sum(anser)))

Submission status: Wrong Answer

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

mean = sum(L) / len(L)
r = round(mean)

Submission status: Wrong Answer

Solution code:
import statistics
import math
import numpy as np

N=int(input())
X=list(map(int,input().split()))
X.sort()
#print(X)
med=int(statistics.median(X))

min=10**10
sum=0
while True:
    sum=0
    for i in range(N):
        sum+=(X[i]-med)**2
    if sum<min:
        min=sum
        prev=sum
        med+=1
    else:
        break

print(prev)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = []
for P in range(1,X[N-1]+1):
    for i in range(N):
        A.append((X[i]-P)**2)
    if sum(A[0:N]) <= sum(A[N:2*N]) or len(A) == N:
        A = A[0:N]
    else:
        A = A[N:2*N]
print(sum(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
CCC = 0
j = 1
max_A = max(A)
for j in range(max_A + 1):#部屋の座標最大値までのループ
    if j == 0:
        continue
    CCC = 0
    if N == 1:
        B.append(A[0])
        break
    for k in range(N):#各部屋からの計算
        CCC += (A[k] - j) ** 2
    B.append(CCC)
x = min(B)
print(x)

Submission status: Wrong Answer

Solution code:
def minus(x,y):
    return (x - y) ** 2

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

min = 0
result = 0
for i in range(N):
    for j in X:
        result += (i + 1 - j) ** 2
    if min > result:
        min = result
    if min == 0:
        min = result
    result = 0

print(min)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
    for c in X:
        if(a != c):
            all = False
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-C)**2
if all == True:
    print(0)
else:
    print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
from statistics import median, mean


def main():
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    avg = math.ceil((sum(x)/len(x)))
    result = 0

    if n % 2 == 0:
        med = median(x)
    else:
        med = median(x)

    for i in x:
        result += (i - avg) ** 2
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

c=max(list)
l=len(list)
m=100000000
j=1

while(j<c):
  r=0
  i=0
  while(i<l):
    r+=(list[i]-j) ** 2
    i+=1
  if(r<m):
    m=r
  j+=1

print(m)

Submission status: Wrong Answer

Solution code:
import math
X = int(input())
L = list(map(int,input().split()))
ans = []
tmp = sum(L)/len(L)
#tmp = int(tmp)
#print("tmp",tmp)
anser = map(lambda x:(x-tmp)**2,L)
print(math.ceil(sum(anser)))

Submission status: Wrong Answer

Solution code:


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

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

    print(int(res))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# Initializing variables
people = int(input())
coordinates = list(map(int, input().split()))
max_ = max(coordinates)
min_ = min(coordinates)
ans = 0

# Calculating the minimum total of stamina
for i in range(min_, max_ + 1):
    currentMin = 0
    for j in range(people):
        currentMin += (coordinates[j] - i) ** 2
        print("coordinates[j]: " + str(coordinates[j]))
        print("J loop currentMin: " + str(currentMin))
        print("J: " + str(j))
        print("i in J loop:" + str(i))
        print()
    print("CurrentMin: " + str(currentMin))
    if i == min_:
        ans = currentMin
        print("if i == min_: " + str(ans))
        print()
    elif currentMin < ans:
        ans = currentMin
        print("elif currentMin < ans: " + str(ans))
        print()

print(ans)

# Check out my Youtube channel! https://www.youtube.com/channel/UCMOKVyAbTZOpKikTrX5dy_A

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calcLen (N,X,ptr):
    len = 0
    for i in range(N):
    	len += (X[i]-ptr)**2
    return len
        
N = int(input())
X = input().split()
X = [int(i) for i in X]

minX = min(X)
maxX = max(X)

curPtr = (maxX + minX) // 2
minLen = 100000000
curLen =  calcLen(N,X,curPtr)
left = minX
right= maxX
while True:

  if left == curPtr or right==curPtr:
    print(curLen)
    break
  
  lLen = calcLen(N,X,left)
  rLen = calcLen(N,X,right)
  curLen = calcLen(N,X,curPtr)
  if right-left < 3:
    print (min([lLen,rLen,curLen]))
    break
           
  if lLen == curPtr:
    print(curLen)
    break
  if rLen == curPtr:
    print(curLen)
    break
    
  if lLen < rLen:
    right = curPtr
    curPtr = (left+right)//2
    
  if rLen < lLen:
    left = curPtr
    curPtr = (left+right)//2

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


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

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

    print(res)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

p = sum(x) / n

ans = 0
for x_i in x:
	ans = (x_i - p) * (x_i - p)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_n = [int(i) for i in input().split()]
result = list()
tem = 0
for num in range(1, n + 1):
    for data in list_n:
        tem = tem + (data - num) ** 2

    result.append(tem)
    tem = 0

result.sort()
print(result[0])

Submission status: Wrong Answer

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

p_min = 10000
for i in range(201):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)

Submission status: Wrong Answer

Solution code:
P=int(input())
X=list(map(int,input().split()))
l=[]
mini=10000000000000000000000
for j in range(min(X),max(X)):
    ans = [(i-j)**2 for i in X ]
    if sum(ans)<mini:
        mini = sum(ans)
print(mini)

Submission status: Wrong Answer

Solution code:
import statistics
n=int(input())
x=[int(_) for _ in input().split()]
mid=int(statistics.mean(x))
mmid=mid-1
cnt=0
cntm=0
for i in range(len(x)):
  cnt+= (x[i]-mid)**2
  cntm+=(x[i]-mmid)**2
print(min(cnt,cntm))

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    mean = round(np.mean(A))
    x = np.array(A) - mean
    print(np.dot(x, x))

main()

Submission status: Wrong Answer

Solution code:
P=int(input())
X=list(map(int,input().split()))
l=[]
mini=100000
for j in range(min(X),max(X)):
    ans = [(i-j)**2 for i in X ]
    if sum(ans)<mini:
        mini = sum(ans)
print(mini)

Submission status: Wrong Answer

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

m = 100 * 100 * n
sumlist = []

if len(set(x)) == 1:
    print(n * (x[0] - n) ** 2)
else:
    for i in range(1, max(x) + 1):
        s = 0
        for j in range(n):
            s += (x[j] - i) ** 2
            # print(s)
        sumlist.append(s)

    if sumlist == []:
        print((x[0] - n) ** 2)
    else:
        print(min(sumlist))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
li = list(map(int,input().split()))
ave = math.ceil(sum(li) / N)
ans = 0
for i in range(N):
    t = (li[i] - ave) ** 2
    ans += t
print(ans)

Submission status: Wrong Answer

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

A = []
for P in range(X[N-1]+1):
    for i in range(N):
        A.append((X[i]-P)**2)
    if sum(A[0:N]) < sum(A[N:2*N]) or len(A) == N:
        A = A[0:N]
    else:
        A = A[N:2*N]
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = float("inf")
for i in range(x[0], x[-1]):
    t = 0
    for q in range(n):
        t += (i - x[q]) ** 2
    else:
        if ans > t:
            ans = t

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
pivot = (x[0] + x[-1]) // 2
Sum = 0
Min = 99999
for i in range(-100,101):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)

Submission status: Wrong Answer

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

print(max(x),min(x))

min_hp = 1000000000000000
for p in range(min(x),max(x)+1):
    hp = 0
    for i in x:
        hp +=(i-p)**2
        # print(p,i,hp)
    if min_hp > hp:
        min_hp = hp

print(min_hp)

Submission status: Wrong Answer

Solution code:
b=input()
b=int(b)
a = input().split()
a=[int(i) for i in a]
a.sort()
c=0
d=9999999999
e=a[0]
f=a[b-1]
for p in range (e,f):
    for x in range (0,b):
        c = c+(a[x]-p)**2
        

    if d>c:
        d=c
        c=0

print(d)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    mean = int(np.mean(A))
    x = np.array(A) - mean
    print(np.dot(x, x))

main()

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    N = int(stdin.readline().rstrip())
    l = list(map(int, stdin.readline().rstrip().split()))
    result = 1000000
    for i in range(0, max(l)):
        sum = 0
        for x in l:
            sum += (x - i)**2
        if result > sum:
            result = sum
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

stamina = 0
total = 0

for i in K:
  total = total + i

midPoint = total/N

number_dec = str(midPoint-int(midPoint))[1:]

number_dec_split = int(number_dec.split('.')[1])

if (number_dec_split >=5 ):
  midPoint = int(midPoint) + 1
else:
  midPoint = int(midPoint) 

for i in K:
  eachPersonStamina = (i - midPoint) ** 2
  stamina = stamina + eachPersonStamina

print(stamina)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    xx = [0 for i in range(n)]
    for i,j in enumerate(x):
        xx[i] = j**2
    minp = 100
    p = 0
    for i in range(max(x)):
        k = i*(n*i - 2*sum(x))
        if k < minp:
            minp = k
            p = i
    print(sum(xx)-2*p*sum(x)+n*(p**2))