function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0], 10);
  var ints = input[1].split(" ").map((n) => parseInt(n, 10));

  var mean = 0;
  var ans = 0;
  for (var i = 0; i < N; i++) {
    mean += ints[i];
  }
  mean = Math.round(mean / N);

  for (var i = 0; i < N; i++) {
    var int = Math.abs(mean - ints[i]);
    var pow = Math.pow(int, 2);
    ans += pow;
  }
  console.log(ans);
}

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