#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], each;
long long total;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    total += a[i];
  }
  each = total / n;
  long long cur = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    a[i] += cur;
    ans += abs(a[i] - each);
    cur = a[i] - each;
  }
  cout << ans << endl;
  return 0;
}
