func_code_string: #include <bits/stdc++.h>   using namespace std;   struct segtree {     int n;     vector<long long> tree;     void init(int s) {       n = s;       tree.resize(4 * s);     }     long long qry(int i, int j) { return qry(i, j, 1, 0, n - 1); }     void upd(int i, long long v) { upd(i, v, 1, 0, n - 1); }     long long qry(int i, int j, int x, int nowi, int nowj) {       if (i <= nowi && nowj <= j) return tree[x];       if (nowi > j || nowj < i) return 0;       int m = (nowi + nowj) / 2;       return qry(i, j, 2 * x, nowi, m) + qry(i, j, 2 * x + 1, m + 1, nowj);     }     void upd(int i, long long v, int x, int nowi, int nowj) {       if (nowi == i && nowj == i) {         tree[x] = v;         return;       }       if (nowi > i || nowj < i) return;       int m = (nowi + nowj) / 2;       upd(i, v, 2 * x, nowi, m);       upd(i, v, 2 * x + 1, m + 1, nowj);       tree[x] = tree[2 * x] + tree[2 * x + 1];     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, ans = 0;     cin >> n;     n *= 2;     vector<int> a(n), p(n + 1, -1), v(n + 1);     for (auto &i : a) cin >> i;     for (int i = 0; i < n; ++i) {       if (p[a[i]] == -1) p[a[i]] = i;       v[i] = p[a[i]];     }     segtree s;     s.init(n);     for (int i = n - 1; ~i; --i) {       s.upd(v[i], 1);       if (v[i]) ans += s.qry(0, v[i] - 1);     }     cout << ans;   }   