[Python] Using counter O(n*m)
\n    def numTriplets(self, A: List[int], B: List[int]) -> int:\n        def getTriplets(A, B):\n            m, n = len(A), len(B)\n            ans = 0\n       
```\n    def numTriplets(self, A: List[int], B: List[int]) -> int:\n        def getTriplets(A, B):\n            m, n = len(A), len(B)\n            ans = 0\n            counter = Counter()\n            for j in range(n):\n                for k in range(j+1,n):\n                    prod = B[j]*B[k]\n                    counter[prod] += 1\n            for i in range(m):\n                prod = A[i]**2\n                ans += counter[prod]\n            return ans \n        return getTriplets(A,B) + getTriplets(B,A)\n```
['Python']