Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/kombinatorika-katalan-soni

Number of balanced bracket sequences

Medium 1000 ms 128 MB 66%
Share

Find how many balanced bracket sequences can be made from $n$ pairs of brackets (( and )). A sequence is balanced if it has $n$ characters ( and $n$ characters ) and in every prefix of it the number of ( is not less than the number of ).

All balanced bracket sequences of three pairs of brackets

Input

One positive integer $n$.

Output

One integer — the number of sequences modulo $10^{9} + 7$.

Note

$1 \le n \le 5 * 10^{5}$

Examples

Input #1
3
Output #1
5
Input #2
1
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.