Ruby From Editorial, (somewhat) easy to understand
\nMOD = 10 ** 9 + 7\n\ndef factorial (n)\n    n.downto(1).inject(:*) || 1\nend \n\ndef comb (n, k)\n    return factorial(n) / (factorial(k) * factorial(n - k))\
```\nMOD = 10 ** 9 + 7\n\ndef factorial (n)\n    n.downto(1).inject(:*) || 1\nend \n\ndef comb (n, k)\n    return factorial(n) / (factorial(k) * factorial(n - k))\nend\n\ndef dfs(nums)\n    return 1 if (nums.length < 3)\n    left_nodes = nums.filter {|a| a < nums[0]}\n    right_nodes = nums.filter {|a| a > nums[0]}\n    return dfs(left_nodes) * dfs(right_nodes) * comb(nums.length - 1, left_nodes.length) % MOD\nend \n\ndef num_of_ways(nums)\n    (dfs(nums) - 1) % MOD\nend\n```
['Ruby']