#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 11 to NN in order. Vilnius is city 11. 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 ii stops once every did_i cities, and its route contains xix_i stops (not including the starting city). If di=0d_i = 0, then the train starting from city ii is currently out of service, so you cannot ride it.

More precisely, if you board at city ii, you may get off at any city numbered i+tdii + t \cdot d_i, where 1txi1 \leq t \leq x_i. 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 NN.

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 109+710^9 + 7.

Input Format

The first line contains an integer NN.

The next NN lines each contain two integers di,xid_i, x_i.

Output Format

Output the number of routes modulo 109+710^9 + 7.

5
1 3
2 1
1 3
0 10
3 5
7

Hint

For the sample, there are the following seven routes:

  • 11.
  • 121 \rightarrow 2.
  • 1241 \rightarrow 2 \rightarrow 4.
  • 131 \rightarrow 3.
  • 1341 \rightarrow 3 \rightarrow 4.
  • 1351 \rightarrow 3 \rightarrow 5.
  • 141 \rightarrow 4.
Subtask ID Special property Points
11 n15n \leq 15 88
22 n104n \leq 10^4 1313
33 di=1d_i = 1 1616
44 xi=109x_i = 10^9 3434
55 No special property 2929

Constraints: for all testdata, it is guaranteed that 1N1051 \leq N \leq 10^5 and 0di,xi1090 \leq d_i, x_i \leq 10^9.

Translated by ChatGPT 5