#include <bits/stdc++.h>
const long long int mrx = 1e6 + 5, M = 1e9 + 7, dm = 1e3 + 5;
long long int mx = -1e18, mn = 1e18;
int T = 1;
using namespace std;
void solve() {
  int a;
  cin >> a;
  int b = 0, c;
  for (int i = 0; i < a; i++) {
    cin >> c;
    b += c;
  }
  cout << (b % a) * (a - (b % a)) << "\n";
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL), cout.tie(NULL);
  cout << "\n";
  while (T--) {
    solve();
  }
  return 0;
}
