#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, sum = 0;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int el;       cin >> el, sum += el;       v.push_back(el);     }     sum = sum / n;     long long int res = 0, curr = 0;     for (long long int i = 0; i < n; i++) {       curr += v[i] - sum;       (curr > 0) ? res += curr : res -= curr;     }     cout << res;     return 0;   }   