python bisect and insort
\ndef numTeams(self, r: List[int]) -> int:\n        def nteams(r):\n            a, res = [], 0\n            left, right = [0] * len(r), [0] * len(r) \n         
```\ndef numTeams(self, r: List[int]) -> int:\n        def nteams(r):\n            a, res = [], 0\n            left, right = [0] * len(r), [0] * len(r) \n            for i in range(len(r)):\n                left[i] = bisect_left(a, r[i]) \n                bisect.insort(a, r[i])\n            a = []\n            for i in range(len(r)-1, -1, -1):\n                right[i] = len(a) - bisect_right(a, r[i])\n                bisect.insort(a, r[i])\n            for i in range(len(r)):\n                if left[i] != 0 and right[i] != 0:\n                    res += (left[i] * right[i])\n            return res\n        return nteams(r) + nteams(r[::-1]) \n```
[]