#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50005;
int n, in[MAXN];
long long average, ans = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> in[i];
    average += in[i];
  }
  average /= n;
  long long c = in[0] - average;
  for (int i = 1; i < n; ++i) {
    ans += abs(c);
    c += in[i] - average;
  }
  cout << ans << endl;
  return 0;
}
