"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[1].split(" ").map(Number)
    var N = data.length
    data = data.sort((a,b) => b - a )
    var sum = 0
    for (var i = 0; i < data.length; i++) {
        sum += data[i]
    }
    var tmp = Math.floor(sum / N)
    // console.log(tmp)
    console.log(Math.min(
        calc(data, tmp),
        calc(data, tmp + 1)
    ))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function calc(data, p) {
    var sum = 0
    for (var i = 0; i < data.length; i++) {
        sum += Math.pow((data[i] - p), 2)
    }
    return sum
}