loj#P2567. 「APIO2016」划艇
「APIO2016」划艇
Description
In the city of Seoul, a river called the Han River flows in the east-west direction. On the northern shore of the river there are boating schools numbered from to as you move from the western end to the eastern end of the shore. All boats from the same school have the exact same color and thus are indistinguishable. The boats from different schools always have different colors and thus are always distinguishable. The school numbered may choose to not send any boats to the festival. If it chooses to send boats to the festival it may send any number of boats from to , inclusive.
One key condition is that the number of boats sent by the school numbered , if it has chosen to sendany boats, should be larger than the number of boats sent by any school numbered less than , if anysuch school have chosen to send boats.
Given 's and 's for all schools, find the number of all possible ways the schools may send boats to the festival, under the condition that at least one school chooses to send boats.
Input
The first line of the input contains a single integer -- the number of schools. The 'th of the next lines contains two integers and .
Output
The output should consist of a single line with the remainder when the number of all possible cases theschools may send boats to the festival is divided by .
2
1 2
2 3
7
Limits And Hints
Subtask 1 (9 points): and for all .
Subtask 2 (22 points): and .
Subtask 3 (27 points): .
Subtask 4 (42 points): .