#P10761. [BalticOI 2024] Trains
[BalticOI 2024] Trains
Background
Translated from BalticOI 2024 Day1 T3.
Problem Description
You have arrived in Vilnius and want to visit different cities in Lithuania. The cities of Lithuania lie on a straight line and are numbered from to in order. Vilnius is city . Each city has a train station, and there is a monorail train route operating starting from that station. You can only board the train in the city where the route starts, but you may get off at any of its stops. A train starting from city stops once every cities, and its route contains stops (not including the starting city). If , then the train starting from city is currently out of service, so you cannot ride it.
More precisely, if you board at city , you may get off at any city numbered , where . Note that since you only want to visit cities in Lithuania, even if the train has more stops on its route, you will not get off beyond city .
You plan to use trains to visit some cities. While planning your trip, you start thinking about how many different journeys are possible starting from Vilnius. If two journeys stop in different sequences of cities, they are considered different. Output the answer modulo .
Input Format
The first line contains an integer .
The next lines each contain two integers .
Output Format
Output the number of routes modulo .
5
1 3
2 1
1 3
0 10
3 5
7
Hint
For the sample, there are the following seven routes:
- .
- .
- .
- .
- .
- .
- .
| Subtask ID | Special property | Points |
|---|---|---|
| No special property |
Constraints: for all testdata, it is guaranteed that and .
Translated by ChatGPT 5