Python - Optimal solution easy to understand
python\nclass Solution:\n    def numTeams(self, rating: List[int]) -> int:\n        N = len(rating)\n\t\tif N < 3:\n            return 0\n        num_teams = 0\
```python\nclass Solution:\n    def numTeams(self, rating: List[int]) -> int:\n        N = len(rating)\n\t\tif N < 3:\n            return 0\n        num_teams = 0\n        for i in range(1, N - 1):\n            middle = rating[i]\n            inferiors_left, inferiors_right, superiors_left, superiors_right = 0, 0, 0, 0\n            for j in range(0, i):\n                if rating[j] < middle:\n                    inferiors_left += 1\n                else:\n                    superiors_left += 1\n            for k in range(i + 1, N):\n                if rating[k] < middle:\n                    inferiors_right += 1\n                else:\n                    superiors_right += 1\n            num_teams += inferiors_left * superiors_right +  superiors_left * inferiors_right\n        return num_teams\n```
[]