C# solution using Dictionary
\npublic int NumTriplets(int[] nums1, int[] nums2) {\n        int w1 = GetWays(nums1, nums2);\n        int w2 = GetWays(nums2, nums1);\n        return w1 + w2;\
```\npublic int NumTriplets(int[] nums1, int[] nums2) {\n        int w1 = GetWays(nums1, nums2);\n        int w2 = GetWays(nums2, nums1);\n        return w1 + w2;\n    }\n    \n    public int GetWays(int[] nums1, int[] nums2) {\n        int numWays = 0;\n        long product = 0;\n        \n        Dictionary<long, int> d = new Dictionary<long, int>();\n        for(int i = 0; i < nums1.Length; i++) {\n            product = (long)nums1[i] * (long)nums1[i];\n            if(d.ContainsKey(product))\n                d[product]++;\n            else {\n                d.Add(product,1);\n            }\n        }\n    \n        for(int j = 0; j < nums2.Length-1; j++) {\n            for(int k = j+1; k < nums2.Length; k++) {\n                product = (long)nums2[j]*(long)nums2[k];\n                if(d.ContainsKey(product)) {\n                    numWays += d[product];\n                } \n            }\n\n        }\n            \n        return numWays;\n    }\n    \n```\n
[]