Python3 original counting and if we want to print all bst list
\nclass Solution:\n    def numOfWays(self, nums: List[int]) -> int:\n        \n        # Time O(N^2)\n        # Space O(N) for recursion stack\n        \n      
```\nclass Solution:\n    def numOfWays(self, nums: List[int]) -> int:\n        \n        # Time O(N^2)\n        # Space O(N) for recursion stack\n        \n        def combine(n, k):\n            \n            def fac(n):\n                s = 1\n                for i in range(1, n + 1):\n                    s *= i\n                return s\n            \n            return fac(n) // (fac(n - k) * fac(k))\n        \n            \n        def recur(nums):\n            if len(nums) <= 2: \n                return 1\n            left = []\n            right = []\n            for n in nums[1:]:\n                if n < nums[0]:\n                    left.append(n)\n                elif n > nums[0]:\n                    right.append(n)\n            curr = combine(len(left)+len(right), len(right))\n            return curr * recur(left) * recur(right)\n        \n        return (recur(nums)-1) % (10**9+7)\n    \n        """\n        print all bst\n        # Time O(2^N)\n        # Space O(2^N)\n        def get_all_bst(nums):\n            candidates = []\n            \n            def recur(l, li, r, ri, temp):\n                nonlocal candidates\n                \n                if len(temp) == len(l) + len(r):\n                    candidates.append(temp[:])\n                    return\n                if li < len(l):\n                    temp.append(l[li])\n                    recur(l, li+1, r, ri, temp)\n                    temp.pop()\n                if ri < len(r):\n                    temp.append(r[ri])\n                    recur(l, li, r, ri+1, temp)\n                    temp.pop()\n            \n            start = nums[0]\n            left = [v for v in nums if v < start]\n            right = [v for v in nums if v > start]\n            recur(left, 0, right, 0, [])\n            res = []\n            for candidate in candidates:\n                r = [start] + candidate\n                if r != nums:\n                    res.append(r)\n            \n            return res\n        """\n```
[]