QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 256 MB 満点: 100

#939. The Great Fall

統計

Bajtek possesses a fairly large collection of $n$ dominoes of various heights, which he loves to set up in a row and watch as they fall one after another. For his latest construction (which he tentatively named "The Great Fall"), he decided to use all the dominoes he owns and set them up in a row, one after another, at certain positions that can be identified with integers on a number line.

When Bajtek finally managed to set up all the dominoes according to his plan, it turned out that his mother, as a birthday present, brought him two new boxes full of smaller dominoes. All dominoes in a box have the same height, are shorter than all the dominoes already set up, and, according to Bajtek's request, the height of the dominoes from one box is divisible by the height of the dominoes from the other box. Since Bajtek does not want to change the positions of the dominoes already set up, he decided to place the new dominoes in the empty positions.

According to the premise of The Great Fall project, when all the dominoes are set up, Bajtek wants to choose one of them and push it in a certain direction (right or left) so that as many dominoes as possible fall. Bajtek knows from experience that each falling domino will knock over all subsequent dominoes whose distance from the one currently falling is at most the height of the falling domino.

Bajtek is not quite sure what to do with the new dominoes. Help him and determine the maximum number of dominoes that can fall if Bajtek adds the new dominoes in appropriate positions.

Input

The first line of the input contains a single integer $n$ ($1 \le n \le 200\,000$) representing the number of dominoes that Bajtek originally had in his collection and set up in a row as part of The Great Fall project.

The next $n$ lines describe the arrangement of Bajtek's dominoes: the $i$-th of these lines contains two integers $x_i, h_i$ ($0 \le x_i \le 10^{18}$, $x_{i-1} < x_i$, $1 \le h_i \le 2\,000\,000$) separated by a single space, representing the position and height of the $i$-th domino, respectively.

The last line of the input contains four integers $N_1, H_1, N_2, H_2$ ($0 \le N_1, N_2 \le 10^{18}$, $1 \le H_1, H_2 \le 10^6$) separated by single spaces, representing the number and height of the dominoes in the first box and the number and height of the dominoes in the second box, respectively. The new dominoes are shorter than the old ones, so $H_1, H_2 < h_i$ for every $i$. According to Bajtek's request, divisibility also holds, so $H_2$ divides $H_1$ or $H_1$ divides $H_2$.

Output

Output a single integer representing the maximum number of dominoes that will fall as part of The Great Fall project.

Examples

Input 1

3
1 5
10 6
20 7
1 4 2 1

Output 1

5

Note 1

One possibility is to place a domino of height 4 at position 6, and dominoes of height 1 at positions 4 and 5, and then push the domino at position 1 to the right.

Subtasks

Subtask Conditions Points
1 $n \le 2000$ 25
2 $H_1 = H_2$ 25
3 no additional conditions 50

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.