function *main() {
  
  const N = +(yield);
  const A = (yield).split(" ").map(s => +s);
  
  const avg = A.reduce((a, b) => a + b) / N;
  const P = Math.round(avg);
  
  const sum = A.reduce((t, x) => t + (x - P)**2, 0);
  
  console.log(sum);
  
}

const iter = main();
iter.next();
require("readline").createInterface({input: process.stdin}).on("line", s => iter.next(s));
