import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime;

void main() {
  auto N = readln.chomp.to!int;
  auto a = readln.split.to!(long[]);
  auto po = a.sum.to!double / N;
  auto u = cast(int)po.ceil;
  auto v = cast(int)po.floor;
  auto pe = a.map!(a => (a - u)^^2).array.sum;
  auto pa = a.map!(a => (a - v)^^2).array.sum;
  writeln(min(pe, pa));
}
