"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const a = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    let list = [];

    for(let i=a[0]; i<a[a.length - 1]; i++) {
        let temp = 0;
        
        for(let j in a) {
            temp += Math.pow(a[j] - i, 2);
        }
        
        list.push(temp);
    }
    
    if(list.length) {
        console.log(Math.min(...list));
    } else {
        console.log(0);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));