import sys

l = sys.stdin.readline().strip()

N = int(l)

l = sys.stdin.readline().strip()

nums = list(map(int, l.split()))

nums = sorted(nums)

start = nums[0]

end = nums[-1] + 1

mi = float("INF")

def compute_dist(p):

  dist = 0

  for n in nums:

    dist += (n-p) ** 2

  return dist

for i in range(start, end):

  d = compute_dist(i)

  if d < mi:

    mi = d

print(mi)
import sys

l = sys.stdin.readline().strip()

N = int(l)

l = sys.stdin.readline().strip()

nums = list(map(int, l.split()))

a = sum(nums) / len(nums)

a1 = int(a)

a2 = int(a) + 1

def count(p):

    d = 0

    for n in nums:

        d += (n-p)**2

    return d

print((min(count(a1), count(a2))))

import sys

l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
nums = sorted(nums)
start = nums[0]
end = nums[-1] + 1
mi = float("INF")


def compute_dist(p):
    dist = 0
    for n in nums:
        dist += (n - p) ** 2
    return dist


for i in range(start, end):
    d = compute_dist(i)
    if d < mi:
        mi = d
print(mi)

import sys

l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1


def count(p):
    d = 0
    for n in nums:
        d += (n - p) ** 2
    return d


print((min(count(a1), count(a2))))

-nums = sorted(nums) -start = nums[0] -end = nums[-1] + 1 -mi = float("INF") +a = sum(nums) / len(nums) +a1 = int(a) +a2 = int(a) + 1 -def compute_dist(p): -    dist = 0 +def count(p): +    d = 0 -        dist += (n - p) ** 2 -    return dist +        d += (n - p) ** 2 +    return d -for i in range(start, end): -    d = compute_dist(i) -    if d < mi: -        mi = d -print(mi) +print((min(count(a1), count(a2))))