## APIO '16 P1 - Boat

View as PDF

Points: 20 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem types
Allowed languages
C, C++, Java, Pascal

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.

#### Input Specification

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 Specification

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 .

#### Sample Input

2
1 2
2 3

#### Sample Output

7

#### 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 .

and for all , .

and .