func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   const double PI = 2.0 * acos(0.0);   const int mx[] = {0, 1, 0, -1};   const int my[] = {-1, 0, 1, 0};   int n;   int P[1000050] = {0};   int T[1000050] = {0};   long long F[1000050] = {0};   long long C[1000050] = {0};   long long ans;   map<int, int> S;   map<int, int> R;   void update(long long B[], int x, int value) {     if (x == 0) return;     for (int s = x; s <= n; s += (s & -s)) B[s] += value;   }   long long query(long long B[], int x) {     long long sum = 0;     for (int s = x; s > 0; s -= (s & -s)) sum += B[s];     return sum;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , P + i), S[P[i]]++;     for (map<int, int>::iterator it = S.begin(); it != S.end(); it++)       T[it->second]++;     for (int i = 1; i <= n; i++) update(F, i, T[i] * (i - 1)), update(C, i, T[i]);     ans = 0;     for (int i = n; i >= 1; i--) {       int target = S[P[i]]--, frequency = ++R[P[i]];       update(F, target, -(target - 1));       update(F, target - 1, target - 2);       update(C, target, -1);       update(C, target - 1, 1);       ans += query(F, n) - query(F, frequency) -              (query(C, n) - query(C, frequency)) * (frequency - 1);     }     printf( %lld n , ans);     return 0;   }   