There are n orders. Each order i has two events: a pickup P_i and a delivery D_i. A sequence is an ordering of all 2n events, with each event appearing exactly once.
A sequence is valid when, for every order i, the delivery D_i comes after the pickup P_i. Count the valid sequences. The answer can be large, so return it modulo 10^9 + 7.
Function Signature
def count_orders(n: int) -> int:
Rules
-
Two sequences are different when some position holds a different event. Orders are distinguishable, so
P1 P2 D1 D2
and
P2 P1 D1 D2
count separately.
-
Return the count reduced modulo
10^9 + 7
.
Constraints
Examples
Input: n = 2
Output: 6
The six valid sequences are 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. The other 18 orderings of the four events put at least one delivery before its pickup.
Input: n = 3
Output: 90
Of the 720 orderings of the six events, 90 have every delivery after its own pickup.
Input: n = 8
Output: 729647433
Before the modulus the count is 81729648000, and 81729648000 mod (10^9 + 7) = 729647433.