#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, temp, b, x;
  cin >> n;
  a = 0;
  vector<int> lol;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    lol.push_back(temp);
    a += temp;
  }
  a /= n;
  temp = 0;
  b = a - lol[0];
  temp += abs(b);
  for (int i = 1; i < n; i++) {
    x = lol[i];
    x -= b;
    b = a - x;
    temp += abs(b);
  }
  cout << temp << endl;
  return 0;
}
