input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
line = lines.shift().split(' ')
sum = 0
for (i=0; i<N; i++) {
    sum += line[i] * 1
}
ave = Math.round(sum / N)
ans = 0
for (i=0; i<N; i++) {
    ans += Math.pow(line[i] * 1 - ave, 2)
}
console.log(ans)