C++ || Fenwick Tree
```\n void add(int N,vector&Fen){\n        while(N < Fen.size()){\n            Fen[N]++;\n            N += (N)&(-N);\n        }\n        \n        return;\n    
```\n void add(int N,vector<int>&Fen){\n        while(N < Fen.size()){\n            Fen[N]++;\n            N += (N)&(-N);\n        }\n        \n        return;\n    }\n    \n    int getVal(int N,vector<int>&Fen){\n        int res = 0;\n        \n        while(N > 0){\n            res += Fen[N];\n            N -= (N)&(-N);\n        }\n        \n        return res;\n    }\n    \n    int numTeams(vector<int>& rating) {\n        vector<int> Fen(100001,0);\n        \n        vector<int> Sorted = rating;\n        sort(Sorted.begin(),Sorted.end());\n        \n        int Ans = 0;\n        int cnt = 0;\n        int N = rating.size();\n        \n        for(auto x:rating){\n            cnt++;\n            \n            int val = getVal(x,Fen);\n            int ind = lower_bound(Sorted.begin(),Sorted.end(),x) - Sorted.begin();\n            int rem = N - ind - (cnt - val);\n            \n            add(x,Fen);\n            \n            Ans += val*(rem);  // for i < j < k\n            Ans += (cnt - val - 1)*(N - cnt - rem); // for i > j > k\n        }\n        \n        return Ans;\n    }\n\t
['Tree']