#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int mod = 1e9 + 7;
template <class T>
inline void readInt(T &n) {
  n = 0;
  T ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  n = n * sign;
}
long long a[100005];
int main() {
  int flag = 0;
  long long sum = 0;
  long long n, k;
  cin >> n;
  for (int i = ((int)(0)); i < ((int)(n)); i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long ans = 0;
  long long avg = sum / n;
  for (int i = ((int)(0)); i < ((int)(n - 1)); i++) {
    if (a[i] == avg)
      continue;
    else {
      a[i + 1] = -avg + a[i] + a[i + 1];
      ans += abs(a[i] - avg);
      a[i] = avg;
    }
  }
  cout << ans << endl;
}
