Python3 solution
\nclass node:\n    def __init__(self, val):\n        self.val = val\n        self.left = None\n        self.right = None\n\nclass Solution:\n    def BST(self, r
```\nclass node:\n    def __init__(self, val):\n        self.val = val\n        self.left = None\n        self.right = None\n\nclass Solution:\n    def BST(self, root, cur):\n        if cur.val < root.val:\n            if root.left == None:\n                root.left = cur\n                return\n            else:\n                self.BST(root.left, cur)\n        elif cur.val > root.val:\n            if root.right == None:\n                root.right = cur\n                return\n            else:\n                self.BST(root.right, cur)\n    \n    def solve(self, root):\n        if root.left == None and root.right == None:\n            return 1\n        left = 0 ; right = 0\n        if root.left is not None:\n            left = self.solve(root.left)\n        if root.right is not None:\n            right = self.solve(root.right)\n        self.total *= math.comb(left + right, left)\n        return left + right + 1\n    \n    def numOfWays(self, nums: List[int]) -> int:\n        import math\n        self.total = 1\n        root = node(nums[0])\n        for i in range(1, len(nums)):\n            self.BST(root, node(nums[i]))\n        self.solve(root)\n        return (self.total - 1) % (int(1e9) + 7)\n```
['Python', 'Python3']