Python in 6 short lines with easy explanation
We separate all the elements into two lists, depending on whether they are less than or more than the root.  Then we recurse on those left and right sublists.  
We separate all the elements into two lists, depending on whether they are less than or more than the root.  Then we recurse on those left and right sublists.  The combination is for the macro ordering between left and right, and the recursive factors are for the internal ordering of left and right themselves.  I minus 1 from the result because we don\'t count the original ordering.\n\n```\ndef numOfWays(self, nums: List[int]) -> int:\n    def f(nums):\n        if len(nums) <= 2: return 1\n        left = [v for v in nums if v < nums[0]]\n        right = [v for v in nums if v > nums[0]]\n        return comb(len(left)+len(right), len(right)) * f(left) * f(right)\n    return (f(nums)-1) % (10**9+7)\n```
[]