#include <bits/stdc++.h>
using namespace std;
int n;
long long a[50005];
long long prumer;
long long moves;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    prumer += a[i];
  }
  prumer /= n;
  for (int i = 0; i < n - 1; i++) {
    moves += abs(a[i] - prumer);
    a[i + 1] += a[i] - prumer;
  }
  printf("%I64d\n", moves);
  return 0;
}
