#include <bits/stdc++.h>
using namespace std;
long long N, A[50010], S[50010];
int main() {
  int i;
  scanf("%I64d", &N);
  for (i = 1; i <= N; i++) scanf("%I64d", &A[i]);
  S[0] = 0;
  for (i = 1; i <= N; i++) S[i] = S[i - 1] + A[i];
  long long ans = 0;
  for (i = 1; i <= N - 1; i++) ans += abs((S[N] / N * i) - S[i]);
  printf("%I64d\n", ans);
}
