func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   constexpr ll INF = (1LL << 30) - 1LL;   constexpr ll LINF = (1LL << 60) - 1LL;   constexpr ll MOD = 1e9 + 7;   template <typename T>   void chmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chmax(T &a, T b) {     a = max(a, b);   }   template <typename T>   struct Median {     priority_queue<T> smq;     priority_queue<T, vector<T>, greater<T>> lgq;     void push(T x) {       if (smq.empty()) {         smq.push(x);         return;       }       T t = smq.top();       if (smq.size() > lgq.size()) {         if (t <= x) {           lgq.push(x);         } else {           lgq.push(t);           smq.pop();           smq.push(x);         }       } else {         if (t >= x) {           smq.push(x);         } else {           lgq.push(x);           smq.push(lgq.top());           lgq.pop();         }       }     }     inline T get() { return smq.top(); }   };   template <typename T>   struct BinaryIndexedTree {     vector<T> node;     int n;     BinaryIndexedTree(int n) : n(n) { node.assign(++n, 0); }     void add(int k, T x) {       for (++k; k < n; k += k & -k) {         node[k] += x;       }     }     T sum(int k) {       if (k < 0) {         return 0;       }       T res = 0;       for (++k; k > 0; k -= k & -k) {         res += node[k];       }       return res;     }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> p(n), pos(n + 1);     for (int i = 0; i < n; i++) {       cin >> p[i];       pos[p[i]] = i;     }     BinaryIndexedTree<ll> bit(n + 1), bit2(n + 1);     for (int i = 0; i < n; i++) {       bit2.add(i, 1);     }     ll res = 0;     Median<ll> med;     for (int k = 1; k <= n; k++) {       res += bit.sum(n - 1) - bit.sum(pos[k]);       res -= min(bit.sum(pos[k] - 1), bit.sum(n - 1) - bit.sum(pos[k]));       bit.add(pos[k], 1);       bit2.add(pos[k], -1);       int t;       if (k % 2 > 0) {         med.push(pos[k]);       }       if (k > 1) {         t = med.get();         if (t < pos[k]) {           res += bit2.sum(pos[k]) - bit2.sum(t - 1);         } else {           res += bit2.sum(t) - bit2.sum(pos[k] - 1);         }         if (k % 2 == 0) {           med.push(pos[k]);         }       }       cout << res;       if (k < n) {         cout <<    ;       } else {         cout << endl;       }     }   }   