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