[Python] Easy O(N^2) DP solution
\nfrom collections import defaultdict\n\nclass Solution:\n    def numTeams(self, rating: List[int]) -> int:\n        if len(rating) < 3:\n            return 0\n
```\nfrom collections import defaultdict\n\nclass Solution:\n    def numTeams(self, rating: List[int]) -> int:\n        if len(rating) < 3:\n            return 0\n        \n        greater = defaultdict(int)\n        less = defaultdict(int)\n        res = 0\n        \n\t\t# greater[i] is the number of elements after index i greater than ratings[i]\n        for i in range(len(rating)-1):\n            for j in range(i+1, len(rating)):\n                if rating[j] > rating[i]:\n                    greater[i] += 1\n                else:\n                    less[i] += 1\n        \n\t\t# Accumulate counts\n        for i in range(len(rating)-2):\n            for j in range(i+1, len(rating)):\n                if rating[i] < rating[j]:\n                    res += greater[j]\n                else:\n                    res += less[j]\n        \n        return res\n```
[]