#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 20;
long long n, a[N], sum, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  sum /= n;
  for (int i = 0; i < n; i++) {
    ans += abs(a[i] - sum);
    a[i + 1] += a[i] - sum;
  }
  return cout << ans, 0;
}
