#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long x[n + 5];
  long long sum = 0;
  for (long long i = 0; i < n; i++) cin >> x[i], sum += x[i];
  long long t = 0;
  long long o = sum / n;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    x[i] = x[i] + t;
    ans += (abs(x[i] - o));
    t = x[i] - o;
  }
  cout << ans << endl;
}
