'use strict';
function Main(input) {

  const n = Number(input[0]);
  const ary = (input[1].split(" ")).map(str => Number(str));
  const sum = ary.reduce((a,b) => a+b);
  const average = Math.round(sum/n);

  let result = 0;
  for (let i=0; i<n; i++) {
    result += (ary[i]-average)*(ary[i]-average);
  }

  console.log(result);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));
