"use strict";
main(
  require("fs")
    .readFileSync("/dev/stdin", "UTF-8")
    .trim()
    .split("\n")
);

/**
 *
 * num
 * array
 *
 */

function main(input) {
  const num = parseInt(input.shift());
  input = input[0].split(" ").map(Number);

  let sumPosition = 0;

  for (let i = 0; i < num; i++ || 0) {
    sumPosition += input[i];
  }

  let avgPosition = Math.ceil(sumPosition / num);
  let result = 0;

  for (let i = 0; i < num; i++ || 0) {
    result += Math.pow(input[i] - avgPosition, 2);
  }

  console.log(result);
}
