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 send any boats, should be larger than the number of boats sent by any school numbered less than , if any such school have chosen to send boats.
Task 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.
The first line of the input contains a single integer — the number of schools. The 'th of the next lines contains two integers and .
The output should consist of a single line with the remainder when the number of all possible cases the schools may send boats to the festival is divided by .
2 1 2 2 3
Explanation for Sample Output
There are ways where only one school sends boats and ways where both schools send boats and thus the answer is .
Subtask 1 (9 points):
and for all , .
Subtask 2 (22 points):
Subtask 3 (27 points):
Subtask 4 (42 points):