[Python/Java] O(n^2) Easy to understand solution
The ides of this solution is to fix the middle one(pivot) and count the left ones which are less/greater than the pivot. After that we can update the combinatio
The ides of this solution is to fix the middle one(pivot) and count the left ones which are less/greater than the pivot. After that we can update the combination with `left`  * `right`.\n\nExample:\n`rating` = `[2,1,3,4,7,6,8]`\n\nwhen `pivot = 4`, `less = [3, 3]`, then we can count the total combination of `(x, 4, x)` is 9 in ascending order.\nOn the other hand, `greater[0, 0]` will represent the descending order but in this case the total combination of this order is 0.\n\n**Python**\n```python\nclass Solution:\n    def numTeams(self, rating: List[int]) -> int:\n        res = 0\n        for i in range(1, len(rating) - 1):\n            less, greater = [0, 0], [0, 0]\n            for j in range(i):\n                if rating[j] < rating[i]:\n                    less[0] += 1\n                else:\n                    greater[0] += 1\n            \n            for k in range(i+1, len(rating)):\n                if rating[i] < rating[k]:\n                    less[1] += 1\n                else:\n                    greater[1] += 1\n            res += less[0] * less[1] + greater[0] * greater[1]\n        return res\n```\n\n**Java**\n```\nclass Solution {\n    public int numTeams(int[] rating) {\n        int res = 0;\n        for (int i = 1; i < rating.length - 1; i++) {\n            int[] less = new int[2], greater = new int[2];\n            for (int j = 0; j < i; j++) {\n                if (rating[j] < rating[i]) {\n                    less[0]++;\n                } else {\n                    greater[0]++;\n                }\n            }\n            \n            for (int k = i + 1; k < rating.length; k++) {\n                if (rating[i] < rating[k]) {\n                    less[1]++;\n                } else {\n                    greater[1]++;\n                }\n            }\n            res += less[0] * less[1] + greater[0] * greater[1];\n        }\n        return res;\n    }\n}\n```
['Python', 'Java']