Given n orders, each order consist in pickup and delivery services.&nbsp;

Count all valid pickup/delivery possible sequences such that delivery(i) is always after of&nbsp;pickup(i).&nbsp;

Since the answer&nbsp;may be too large,&nbsp;return it modulo&nbsp;10^9 + 7.

&nbsp;
Example 1:

Input: n = 1
Output: 1
Explanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.


Example 2:

Input: n = 2
Output: 6
Explanation: All possible orders: 
(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).
This is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.


Example 3:

Input: n = 3
Output: 90


&nbsp;
Constraints:


	1 &lt;= n &lt;= 500


class Solution:
    def countOrders(self, n: int) -> int:
        total = 1
        mod = 10 ** 9 + 7
        for k in reversed(range(2, n + 1)):
            total = total * ((2 * k - 1) * (2 * k - 2) // 2 + 2 * k - 1)
            total = total % mod
        return total
class Solution {
    public int countOrders(int n) {
        long res = 1;
        long mod = 1000000007;
        for (int i = 1; i <= n; i++) {
            res = res * (2 * i - 1) * i % mod;
        }
        return (int)res;
    }
}
class Solution {
public:
    int countOrders(int n) {
        int mod = 1e9+7;
        long long ans = 1;
        for(int i=1;i<=n;i++){
            int m = 2*i-1;
            int p = (m*(m+1))/2;
            ans=(ans*p)%mod;
        }
        return ans;
    }
};
var countOrders = function(n) {
    let ans = 1; //for n=1, there will only be one valid pickup and delivery
    for(let i = 2; i<=n; i++){
        let validSlots = 2 * i -1; //calculating number of valid slots of new pickup in (n-1)th order
        validSlots =  (validSlots * (validSlots+1))/2; 
        ans = (ans * validSlots)%1000000007; //multiplying the ans of (n-1)th order to current order's valid slots
    }
    return ans;
};
Count All Valid Pickup and Delivery Options