Simple Python Solution O(n^2)
Code\n\nclass Solution(object):\n    def numOfWays(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        self.ans 
# Code\n```\nclass Solution(object):\n    def numOfWays(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        self.ans = 1\n        mod = 1000000007\n        class BST:\n            self.right = None\n            self.left = None\n            self.val = None\n            self.below_count = None\n            self.cont_ans = None\n\n            def __init__(self,left=None,right=None,val=None):\n                self.right = right\n                self.left = left\n                self.val = val\n\n        def insert(root,val):\n            if root.val == None:\n                root.val = val\n                return\n            if val < root.val:\n                if root.left == None:\n                    root.left = BST(val=val)\n                else:\n                    insert(root.left,val)\n            else:\n                if root.right == None:\n                    root.right = BST(val=val)\n                else:\n                    insert(root.right,val)\n\n        def bel_count(root):\n            if root is None:\n                return 0\n            root.below_count = 1\n            root.below_count += bel_count(root.left)\n            root.below_count += bel_count(root.right)\n            return root.below_count\n\n        def iot(root):\n            if root is None:\n                return\n            iot(root.left)\n            self.ans = (self.ans*root.cont_ans)%mod\n            iot(root.right)\n\n\n        def nck(n,k):\n            if n<=0 or k<=0 or k>=n:\n                return 1\n            return factorial(n)/(factorial(k)*(factorial(n-k)))\n\n\n        def get_ans(root,remain):\n            if root is None:\n                return\n            root.cont_ans = 1\n            root.cont_ans *= nck(remain,root.below_count)%mod\n            root.cont_ans = root.cont_ans%mod\n            get_ans(root.left,root.below_count-1)\n            remain1 = root.below_count-1\n            if root.left is not None:\n                remain1 = remain1 - root.left.below_count\n            get_ans(root.right,remain1)\n\n        root = BST()\n        for num in nums:\n            insert(root,num)\n        bel_count(root)\n        get_ans(root,len(nums))\n        iot(root)\n\n        return self.ans-1\n\n\n```
['Binary Search Tree', 'Combinatorics', 'Python']