func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   const int MAX_N = 1e6 + 5;   int fen[MAX_N];   int n;   int lowbit(int x) { return x & (-x); }   void add(int x, int val) {     for (int i = x; i <= n; i += lowbit(i)) fen[i] += val;   }   int sum(int x) {     int s = 0;     for (int i = x; i; i -= lowbit(i)) s += fen[i];     return s;   }   int sum(int l, int r) { return sum(r) - sum(l); }   map<int, int> cnt;   int pre[MAX_N];   int back[MAX_N];   int arr[MAX_N];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       cnt[arr[i]]++;       pre[i] = cnt[arr[i]];     }     cnt.clear();     for (int i = n - 1; i >= 0; i--) {       cnt[arr[i]]++;       back[i] = cnt[arr[i]];       add(back[i], 1);     }     ll ans = 0;     for (int i = 0; i < n; i++) {       add(back[i], -1);       ans += sum(pre[i] - 1);     }     cout << ans << endl;     return 0;   }   