#!/usr/bin/env python3
# @EXPECTED_RESULTS@: TIME_LIMIT_EXCEEDED, WRONG_ANSWER
n, xs, occupied = int(input()), list(map(int, input().split())), set()
for x in xs:
    diff, found = 0, False
    while not found:
        for new_x in (x - diff, x + diff):
            if new_x not in occupied:
                occupied.add(new_x)
                found = True
                break
        else: diff += 1
print(sum((a - b) ** 2 for a, b in zip(xs, sorted(occupied))))
