TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Byteazar has decided on going to Mars to tour the space stations there being in existence. All marsian space stations lie on a circumference of a circle. Byteazar lands in one of them and then moves around by means of a special vehicle which is powered by an appropriate fuel. A litre of this fuel allows him to travel one meter. However, the provisions of the fuel are meagre, different quantities of it are available in each space station. Byteazar may refuel in the space station he is currently in, though he cannot get more fuel than it is available in that very place (the capacity of his fuel tank is unlimited). This quantity of fuel should allow him to reach the next space station. Byteazar has to decide where to land, so that he can visit all of the space stations. In the end he has to return to the space station in which he has landed. During his journey Byteazar has to travel on the circumference of the circle, constantly in one of the two possible directions.


Write a programme which:

  • reads from the standard input the number of space stations, distances between them and the amount of fuel available in each of them,

  • for each of the space stations checks, whether Byteazar can land there i.e. whether by starting in that very station and travelling in a freely chosen direction he is able to visit all of the space stations and return to his spaceship,

  • writes the outcome to the standard output.

Input Format

There are multiple test cases in the input file, terminated by EOF. For every test case, the first line contains an integer N (3<= N<= 100,000). It denotes the number of space stations on Mars. The space stations are numbered from 1 to N. In the next N lines there is a description of all the stations and the distances between them. The (i+1)'st line contains two integers p_i and d_i (p_i >=0, d_i >0). The first one denotes the amount of fuel (in litres) available in the i'th space station. The other denotes the distance (in meter) between the i'th and (i+1)'th space station (obviously the N'th one denotes the distance between N'th and 1st station). The total amount of available fuel, as well as the sum of all distances between the space stations does not exceed 2,000,000,000.

Output Format

For each test case please output an integer denotes the number of stations Byteasar can land in.

Sample Input 1

5
3 1
1 2
5 2
0 1
5 4

Sample Output 1

3

Hints

For sample input, Byteasar can land in 1st, 3rd, 5th station.

Problem Source

Migrated from old NTUJ.

POI12th stage II

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 200