problems / 213

Theater Entry/Exit Sequences

easy bracket-sequences combinatorics dp math 1000 ms · 256 MB

Theater Entry/Exit Sequences

A theater has a line of people wanting to watch a show. Each person must enter the theater, then later exit it. The entry/exit log records a sequence of E (enter) and X (exit) events.

A valid entry/exit sequence must satisfy two rules:

  1. At any point while reading left to right, the number of exits never exceeds the number of entries (you can't exit if nobody is inside).
  2. The total number of entries equals the total number of exits.

Given that n people enter and n people exit, count the number of distinct valid entry/exit sequences.

Input

The first line contains an integer n (1 ≤ n ≤ 35).

Output

Print the count of valid entry/exit sequences of length 2n with n entries and n exits, modulo 10^9 + 7.

Notes

A valid sequence of length 2 (n=1) is just EX (one person enters, then exits). There is 1 such sequence.

For n=2, valid sequences are EEXX, EXEX. There are 2 sequences (sequences where someone exits before both have entered, like XEEX or EXXE, are invalid).

Example 1

Input

1

Output

1

Example 2

Input

2

Output

2

Hints · reveal one at a time if you're stuck

Hint 1

Read E as an opening bracket and X as a closing one. Which sequences of entries and exits are allowed, and how many people are inside after each step?

Hint 2

Count valid sequences by splitting each one at the first point where the number inside returns to zero. That gives a recurrence over smaller sizes, and with n at most 35 a table of values is fast. Remember to take the result modulo 10^9 + 7.

report an issue Prefer your own editor? sooks prep 213 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.