این مسابقه در تاریخ پنج شنبه ۱۴ دی به صورت حضوری در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار شد.
Saman loves brackets (or parentheses). He calls a sequence of ‘(’ and ‘)’ characters a “valid bracket sequence” if either:
For example, (())
and ()()
are both valid, while )(
and ())(()
are not.
Furthermore, he calls a string of parentheses “-valid” if, f, after adding open brackets to its left and closed brackets to its right, it is valid (either because it was valid before, or because it became valid). For example )(
and ())(()
are both -valid, while ))((
is 2-valid.
Saman is curious to find for any given and how many bracket sequences there are with length that are -valid. Because the result may be very large, Saman is only interested in its remainder after dividing it by .
Help Saman by writing a program that quickly calculates this number for different queries.
The first line contains one integer , the number of queries Saman is interested in.
The next lines contain each a pair of integers and .
You need to write lines containing each the result of the -th query: for each query, print the number of strings of length that are -valid, modulo