#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, a, x = 0, y = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    x += a*a;
    y += a;
  }
  a = y/n + (y%n > n/2);
  printf("%d\n", x + (n*a - 2*y)*a);
}
