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_ceil_mean = math.ceil(statistics.mean(xl))
xl_floor_mean =math.floor(statistics.mean(xl))

sigma_pow1 = sum([(x-xl_ceil_mean)**2 for x in xl])
sigma_pow2 = sum([(x-xl_floor_mean)**2 for x in xl])

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

sigma_pow1 = sum([(x-xl_ceil_mean)**2 for x in xl])
sigma_pow2 = sum([(x-xl_floor_mean)**2 for x in xl])

if sigma_pow1 > sigma_pow2:
    print(sigma_pow2)
else:
    print(sigma_pow1)