Python3 Solution
\n\nclass Solution:\n    def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n        mod=10**9+7\n        arr.sort()\n        ans=defaultdict(int)\n      
\n```\nclass Solution:\n    def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n        mod=10**9+7\n        arr.sort()\n        ans=defaultdict(int)\n        for a in arr:\n            tmp=1\n            for b in arr:\n                if b>a:\n                    break\n                tmp+=(ans[b]*ans[a/b])\n            ans[a]=tmp\n        return sum(ans.values())%mod            \n        \n```
['Python', 'Python3']