process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  var n = Number(lines[0]);
  var info = lines[1].split(' ');
  var info = info.map(function(str) { return Number(str)});
  var sum = 0;
  var ans = 0;
  
  for(i=0; i<n; i++){
    sum += info[i];
  }
  var ave = Math.round(sum / n);

  for(i=0; i<n; i++){
    var sa = (info[i] - ave) * (info[i] -ave);
    
    ans += sa
  }
  console.log(ans);
  
 
});