#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, ans = 0, sum = 0;
  cin >> a;
  long long* q = new long long[a];
  for (int t = 0; t < a; t++) {
    cin >> q[t];
    sum += q[t];
  }
  sum /= a;
  for (long long t = 0; t < a - 1; t++) {
    q[t + 1] = q[t] + q[t + 1] - sum;
    ans += abs(sum - q[t]);
    q[t] = sum;
  }
  cout << ans;
  return 0;
}
