'use strict'

function main(s) {  
  
  const input = s.split('\n')[1].split(' ').map(x => Number(x));
  const avg = Math.round(input.reduce((a, b) => a + b) / input.length);
  const result = input.map(x => Math.pow(avg - x, 2)).reduce((a, b) => a + b);
  
  console.log(result);
}

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