very simple clear code with O(n^2)
class Solution {\npublic:\n    int numTeams(vector& rating) {\n        \n        int smaller1=0,greater1=0,smaller2=0,greater2=0;\n        int sum=0;\n        \
class Solution {\npublic:\n    int numTeams(vector<int>& rating) {\n        \n        int smaller1=0,greater1=0,smaller2=0,greater2=0;\n        int sum=0;\n        \n        for(int i=0;i<rating.size();i++)\n        {\n            smaller1=0;greater1=0;smaller2=0;greater2=0;\n            \n            for(int j=0;j<i;j++)\n            {\n               if(rating[i]>rating[j])\n                   smaller1++;\n                else\n                   greater1++;       \n            }\n            \n             for(int j=i+1;j<rating.size();j++)\n            {\n               if(rating[i]>rating[j])\n                   smaller2++;\n                else\n                   greater2++;       \n            }\n            \n            sum=sum+(smaller1*greater2)+(greater1*smaller2);\n        }\n        \n        \n        return sum;\n    }\n};
[]