#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void mn(T& x, const T& y) {
  if (y < x) x = y;
}
template <typename T>
inline void mx(T& x, const T& y) {
  if (x < y) x = y;
}
template <typename T>
inline int sz(const T& x) {
  return (int)x.size();
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  long long s = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    s += a[i];
  }
  int k = s / n;
  long long ans = 0;
  long long add = 0;
  for (int i = 0; i < n; ++i) {
    long long x = a[i] + add;
    ans += llabs(x - k);
    add = x - k;
  }
  cout << ans << endl;
  return 0;
}
