Trains

시간 제한2초메모리 제한1024 MB

요약
1번 도시에서 시작해 i번 도시에서 i + t*d_i (1 ≤ t ≤ x_i)로 이동할 수 있을 때, 가능한 모든 도시 방문 순서의 가짓수를 1e9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 정수론, 조합론, 구현
정답자
아직 제출이 없습니다

문제

You have arrived in Vilnius and want to visit various cities in Lithuania.

Cities in Lithuania are located on a straight line and numbered from 11 to NN sequentially. Vilnius is assigned the number 11.

Each city has a train station with a single train route that operates from that station. You can only get on a train at the start of its route, though you can get off at any of its stops. Trains starting their route at the ii-th city make a stop every d_id\_i cities, and their route consists of x_ix\_i stops (not including the starting city). If d_i=0d\_i = 0, the trains operating from the ii-th city are currently out of service, so you cannot get on them.

To be more precise, if you get on a train in the ii-th city, you can get off the train in any city numbered i+t⋅d_ii + t \cdot d\_i, where 1≤t≤x_i1 ≤ t ≤ x\_i. Note that since you only want to visit cities in Lithuania, you won't ride further than the NN-th city, even if the train has more stops on its route.

You are going to visit some cities, using trains to travel between them. As you plan your trip, you start to wonder how many different options you have for your journey that starts at Vilnius. Two journeys are different if they make stops at different sequences of cities.

Calculate this number and print the answer modulo 109+710^9 + 7.

입력

The first line contains one integer NN – the number of cities.

Then NN lines follow. The ii-th of them contains two integers d_id\_i and x_ix\_i – the numbers describing the route starting in the ii-th city.

출력

Output a single integer – the number of ways you can visit some of the NN cities taken modulo 109+710^9 + 7.

제한

  • 1≤N≤1051 ≤ N ≤ 10^5
  • 0≤d_i≤1090 ≤ d\_i ≤ 10^9 (for each 1≤i≤N1 ≤ i ≤ N)
  • 0≤x_i≤1090 ≤ x\_i ≤ 10^9 (for each 1≤i≤N1 ≤ i ≤ N)

예제1

  1. 예제 1

    입력
    5
    1 3
    2 1
    1 3
    0 10
    3 5
    
    예상 출력
    7