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