#P3643. [APIO2016] 划艇
[APIO2016] 划艇
Description
In the city of Seoul, the Han River runs east to west. On its north bank, from west to east, there are rowing schools, numbered to . Each school owns several boats. All boats from the same school share the same color, and different schools have different colors. Boats of the same color are considered identical. Each school may choose to send some boats to the festival, or choose not to send any. If school chooses to participate, it may send any number of boats between and inclusive ().
Importantly, if school participates, the number of boats it sends must be greater than the number sent by any participating school with a smaller index.
Given all and , determine how many possible participation configurations there are, with at least one boat participating. Two configurations are different if and only if there exists some color (i.e., some school) for which the number of participating boats differs.
Input Format
The first line contains an integer , the number of schools.
The next lines each describe one school. Line contains two positive integers and ().
Output Format
Output a single line with one integer: the number of possible configurations modulo .
2
1 2
2 3
7
Hint
Sample explanation:
- When only one school participates, there are configurations.
- When both schools participate, there are configurations.
- Therefore, the answer is .
Constraints:
- Subtask (9 points): and for all .
- Subtask (22 points): and .
- Subtask (27 points): .
- Subtask (42 points): .
Translated by ChatGPT 5
京公网安备 11011102002149号