from sys import stdin
from math import ceil, floor
n = stdin.readline().rstrip()
data = [int(x) for x in stdin.readline().rstrip().split()]
m = sum(data) / len(data)
cm = ceil(m)
fm = floor(m)
ceil_m = floor_m = 0
for i in data:
    ceil_m += (i-cm)**2
    floor_m += (i-fm)**2
print(min(ceil_m, floor_m)) from sys import stdin from math import ceil, floor n = stdin.readline().rstrip() n stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x data = [int(x) for x in stdin.readline().rstrip().split()] data [int(x) for x in stdin.readline().rstrip().split()] m = sum(data) / len(data) m sum(data) / len(data) sum(data) sum data len(data) len data cm = ceil(m) cm ceil(m) ceil m fm = floor(m) fm floor(m) floor m ceil_m = floor_m = 0 ceil_m 0 = floor_m = 0 floor_m 0 for i in data:
    ceil_m += (i-cm)**2
    floor_m += (i-fm)**2 i data ceil_m += (i-cm)**2 ceil_m (i-cm)**2 i-cm i cm 2 floor_m += (i-fm)**2 floor_m (i-fm)**2 i-fm i fm 2 print(min(ceil_m, floor_m)) print min(ceil_m, floor_m) min ceil_m floor_m ceil_m = floor_m = 0 0 ceil_m floor_m = 0 0 floor_m n = stdin.readline().rstrip() stdin.readline().rstrip() n m = sum(data) / len(data) sum(data) / len(data) m ceil_m += (i-cm)**2 (i-cm)**2 ceil_m fm = floor(m) floor(m) fm floor_m += (i-fm)**2 (i-fm)**2 floor_m data = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] data cm = ceil(m) ceil(m) cm
from sys import stdin
from math import ceil, floor
n = stdin.readline().rstrip()
data = [int(x) for x in stdin.readline().rstrip().split()]
m = sum(data) / len(data)
cm = ceil(m)
fm = floor(m)
ceil_m = floor_m = 0
for i in data:
    ceil_m += (i-cm)**2
    floor_m += (i-fm)**2
print(min(ceil_m, floor_m))