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