function main(input) {
    const numbers = input.split("\n")[0];
    const list = input.split("\n")[1].split(" ").map(v => Number(v));

    const maxList = Math.max(...list);
    const minList = Math.min(...list);
    const calcCost = (org, mod) => (org - mod) ** 2;

    const costs = [];
    for (let testNumber = minList; testNumber <= maxList; testNumber++) {
        let cost = 0;
        for (let i = 0; i < list.length; i++) {
            cost += calcCost(list[i], testNumber);
        }
        costs.push({ testNumber, cost });
    }
    let costsSort = costs.sort((a, b) => a.cost - b.cost)
    // console.log('costsSort', costsSort);
    console.log(costsSort[0]);

}

// let input = "2"+ '\n' + "4 8"; //8
// let input = "3" + '\n' + "1 1 3"; //3
// let input = "3" + '\n' + "4 2 5"; //5
// let input = "4" + '\n' + "-100 -100 -100 -100"; //0

// main(input);
main(require("fs").readFileSync("/dev/stdin","utf8"));
  