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()))
ans = float('inf')
for i in range(1,N+1):
  tmp = 0
  for n in X:
    tmp+=(n-i)**2
  ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = il()
    x = sum(D)//N + 1
    ret = 0
    for d in D:
        ret += (d-x)**2
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
	n = int(input())
	A = list(map(int,input().split()))
	ma = max(A)
	ans = 100000
	for x in range(1,ma):
		tmp = 0
		for y in A:
			tmp2 = (y-x)*(y-x)
			tmp += tmp2
		ans = min(ans,tmp)
	
	print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median, mean

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

INF = float('inf')
res = INF
for a in range(min(X), max(X)):
  tmp = 0
  for x in X:
    tmp += (x-a) * (x-a)
  res = min(tmp, res)
  
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if len(set(l)) == len(l):
    mean = (sum(l))//len(l)
else:
    mean = (sum(set(l)))//(n-1)
print(sum(pow(i - mean, 2) for i in l))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    x = list(map(int, input().split()))
    min = 10001
    for point in range(x[-1]):
        s = sum([(i - point)**2 for i in x])
        if s < min:
            min = s
    print(min)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = list(map(int, input().split()))
    min = 10001
    for point in range(100):
        s = sum([(i - point)**2 for i in x])
        if s < min:
            min = s
    print(min)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = list(map(int, input().split()))
    min = 10001
    for point in range(10000):
        s = sum([(i - point)**2 for i in x])
        if s < min:
            min = s
    print(min)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = list(map(int, input().split()))
    min = 10001
    for point in range(10001):
        s = sum([(i - point)**2 for i in x])
        if s < min:
            min = s
    print(min)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a = sum(Xlist)

a_m = a//N
a_p = a_m + 1

if a - a_m < a_p - a:
    p = a_m
else:
    p = a_p

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

print(ans)

Submission status: Wrong Answer

Solution code:
#2
N = int(input())
an = list(map(int,input().split()))
Min = 10**10

for i in range(1,102):
    k = 0
    for j in an:
        k += (j-i)**2
    print(k)
    if Min >k:
        Min = k
        
print(Min)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
def sump(x,p):
  s=0
  for a in x:
    s+=(a-p)**2
  return s
m=min(x)
M=max(x)
ans=[]
for p in range(m,M+1):
  ans.append(sump(x,p))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    x = list(map(int, input().split()))
    x.sort()
    mt = 10**10
    print(x)
    for ii in range(x[0],x[-1]+1):
        ans = 0
        for i in x:
            ans += (i-ii)**2
        mt = min(mt,ans)
    print(mt)    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=10000
for i in range(1,101):
    t=0
    for j in x:
        t+=(j-i)**2
    if ans>t:
        ans=t
print(ans)

Submission status: Wrong Answer

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

min_ans = 10 ** 6
for i in range(1, N+1):
    ans = 0
    for x in x_list:
        ans += (i - x) ** 2
    min_ans = min(min_ans, ans)
print(min_ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 100000000

for p in range(X[0], X[N-1]): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Wrong Answer

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

ans = 100000000

for p in range(X[0], X[N-1]): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

p = X[0]
sum = 0
for x in X:
  sum += (x - p)**2
ans = sum

for p in range(X[0]+1, X[N-1]+1): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Wrong Answer

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

ans = 100000000

for p in range(X[0], X[N-1]): #Pの位置
  sum = 0
  for x in X: #Xの要素を１つずつ取得
    sum += (x - p)**2
  ans = min(sum, ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn = 100000
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()

Submission status: Wrong Answer

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

# M = int(statistics.median(X_list))

def pow(X_list, M):
    P = 0
    for X in X_list:
        P += (X-M)**2
    return P

min_X = min(X_list)
max_X = max(X_list) +1
pow_1=pow(X_list, max_X)
pow_2=0
for i in range(min_X,max_X,1):
    pow_2 = pow(X_list,i)
#    print(pow_2)
    if pow_2 >= pow_1:
        break
    pow_1 = pow_2
print(pow_1)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
ans = 1000000000000000000

for i in range(max(a)):
  x = 0
  for j in a:
    x += (i - j) ** 2
  ans = min([x, ans])

print(ans)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
ans = 10000000000

for i in range(max(a)):
  x = 0
  for j in a:
    x += (i - j) ** 2
  ans = min([x, ans])

print(ans)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
ans = 10000

for i in range(max(a)):
  x = 0
  for j in a:
    x += (i - j) ** 2
  ans = min(x, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 100

for i in range(max(a)):
  x = 0
  for j in a:
    x += (i - j) ** 2
  ans = min(x, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xlist = list(map(int, input().split()))
sumX = 0
for x in Xlist:
  sumX += x
average = int(sumX/N)
answer = 0
for x in Xlist:
  answer += (x-average)**2
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
Xlist = list(map(int, input().split()))
sumX = 0
for x in Xlist:
  sumX += x
average = (sumX/N)
answer = 0
for x in Xlist:
  answer += (x-average)**2
print(answer)

Submission status: Wrong Answer

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

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]

import math

N = int(input())
list_x = list(map(int, input().split()))
bar_x = sum(list_x)/N
ans = 0
for x in list_x:
    ans += x**2/N
ans = N*(ans-bar_x**2)
print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:

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

minX = min(X)
maxX = max(X)
if minX==maxX:
    print(X[0])
    quit()

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))

Submission status: Wrong Answer

Solution code:

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

minX = min(X)
maxX = max(X)
if minX==maxX:
    print(minX)
    quit()

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))

Submission status: Wrong Answer

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

x.sort()

mean = sum(x)/n
med = int(n / 2)
print(med)

if mean - int(mean) < 0.5:
    mean = int(mean)
elif mean - int(mean) > 0.5:
    mean = int(mean) + 1
else:
    if n % 2 == 0:
        if (x[med-1] + x[med])/2 <= mean:
            mean = int(mean)
        else:
            mean = int(mean) + 1
    else:
        if x[med] <= mean:
            mean = int(mean)
        else:
            mean = int(mean) + 1
sum = 0

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

print(sum)

Submission status: Wrong Answer

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

x.sort()

mean = sum(x)/n

if isinstance(mean,float):
    mean = int(mean) + 1

sum = 0

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

print(sum)

Submission status: Wrong Answer

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

x.sort()

mean = sum(x)/n

if isinstance(mean,float):
    mean = int(mean) + 1

print(mean)

sum = 0

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

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

hp = [0 for i in range(101)]
for i in range(101):
    for j, x in enumerate(X):
        hp[i] = hp[i] + (x-(i+1))**2

print(hp)
print(min(hp))

Submission status: Wrong Answer

Solution code:
import math

N = input()
xs = [int(i) for i in input().split()]
p = round(sum(xs)/len(xs))

print(sum(math.pow(x-p, 2) for x in xs))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
xs = [int(i) for i in input().split()]
p = int(sum(xs) / len(xs))

print(int(sum([math.pow(x-p, 2) for x in xs])))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
xs = [int(i) for i in input().split()]
p = sum(xs) / len(xs)

print(sum([math.pow(x-p, 2) for x in xs]))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
abc = list(map(int, input().split()))
P = 0
for a in range(len(abc)):
  P += abc[a]
P = math.ceil(P/len(abc))
print(P)
total = 0
for i in range(len(abc)):
  distance = (abc[i] - P)**2
  print(distance)
  total += distance
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
abc = list(map(int, input().split()))
total = 0
for i in range(len(abc)):
  distance = (abc[i] - N)**2
  total += distance
print(total)

Submission status: Wrong Answer

Solution code:
import math

def main():
    num = int(input())
    l = list(map(int, input().split()))
    l.sort()
    last_num = l[num - 1]

    ans_list = []



    
    for i in range(last_num):
        sum = 0
        for x in l:
            sum = sum + ((x - i) * (x - i))
        ans_list.append(sum)
    
    ans_list.sort()
    print(ans_list[0])


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
lists = list(input().split())
ave_sum = 0
for i in lists:
  ave_sum = ave_sum + int(i)
ave = int(ave_sum / N)
nijyo = 0
for i in lists:
  nijyo = nijyo + (int(i) - ave_sum) ** 2
print(str(nijyo))

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    l = list(map(int, input().split()))
    l_sum = 0
    ans = 0
    for i in l:
        l_sum = l_sum + i
    divide = l_sum // num
    for x in l:
        ans = ans + ((x - divide)*(x - divide))
    print(ans)

main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if n == 1:
    print(0)
ans = 10**10
for i in range(0,102):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
print(ans)

Submission status: Wrong Answer

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

if n == 1:
    print(0)
ans = 10**10
for i in range(1,102):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
print(ans)

Submission status: Wrong Answer

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

if n == 1:
    print(0)
ans = 10**6
for i in range(1,101):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
print(ans)

Submission status: Wrong Answer

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

ans = 10**5
for i in range(1,101):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
print(ans)

Submission status: Wrong Answer

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

ans = 10 ** 5
for p in range(1, 101):
  t = 0
  for i in range(n):
    t += (x[i] - p) ** 2
  ans = min(ans, t)
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    sum = 0
    p = 0
    ans = 0
    anss = 0
    for i in range(N):
        sum = sum + Xs[i]
    if sum % N == 0:
        p = sum / N
        ps = p
    else:
        p = sum // N
        ps = -(-sum // N)
    for i in range(N):
        ans = ans + ((p - Xs[i]) * (p - Xs[i]))
        anss = anss + ((ps - Xs[i]) * (ps - Xs[i]))
    if ans > anss:
        ans = anss
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:

def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    sum = 0
    p = 0
    ans = 0
    anss = 0
    for i in range(N):
        sum = sum + Xs[i]
    if sum % N == 0:
        p = sum / N
    else:
        p = sum // N
    ps = -(-sum // N)
    for i in range(N):
        ans = ans + ((p - Xs[i]) * (p - Xs[i]))
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    sum = 0
    p = 0
    ans = 0
    anss = 0
    for i in range(N):
        sum = sum + Xs[i]
    if sum % N == 0:
        p = sum / N
    else:
        p = sum // N
    ps = -(-sum // N)
    for i in range(N):
        ans = ans + ((p - Xs[i]) * (p - Xs[i]))
        anss = anss + ((ps - Xs[i]) * (ps - Xs[i]))
    if ans > anss:
        ans = anss
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input().strip())
    Xs = list(map(int, input().strip().split(' ')))
    sum = 0
    p = 0
    ans = 0
    anss = 0
    for i in range(N):
        sum = sum + Xs[i]
    if sum % N == 0:
        p = sum / N
    else:
        p = sum // N
    for i in range(N):
        ans = ans + ((p - Xs[i]) * (p - Xs[i]))
        anss = anss + ((p + 1 - Xs[i]) * (p + 1 - Xs[i]))
    if ans > anss:
        ans = anss
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
ans = 10**9+7
for i in range(X[0],X[-1]):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(51):
    num = 0
    for xx in x:
        num += (xx-i)**2
    if num < best:
        best = num

print(best)

Submission status: Wrong Answer

Solution code:
def cal_cost(X, P):
    cost = 0
    for x in X:
        cost += (x - P) ** 2
    return cost


def main(N, X):
    if N == 1:
        return 0
    return min(cal_cost(X, p) for p in range(max(X)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Submission status: Wrong Answer

Solution code:
def cal_cost(X, P):
    cost = 0
    for x in X:
        cost += (x - P) ** 2
    return cost


def main(N, X):
    """
    >>> main(2, [1, 4])
    5
    >>> main(7, [14, 14, 2, 13, 56, 2, 37])
    2354
    """
    return min(cal_cost(X, p) for p in range(max(X)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Submission status: Wrong Answer

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod
 
    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)
 
def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)

###################################################################
def main():
    #CODE GOES HERE:
    n=ii()
    x=li()
    l,r=min(x),max(x)
    answer0=float("inf")
    for s in range(l,r):
        answer0=min(answer0,sum([(i-s)*(i-s) for i in x]))
    print(answer0)
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
 
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
 
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
 
class IOWrapper(IOBase):
 
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
 
""" main function"""
 
if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()