QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 10

#10380. Climbing [B]

الإحصائيات

The Byteburg University holds a climbing course. 2$ n $ students can attend the course simultaneously. Each of the climbers has their own separate climbing route along which they can go either upwards or downwards. The climbers are divided into $ n $ pairs, with the climbers in each pair climbing on adjacent routes and attached to the same belay rope. Each rope is attached at the top of the wall in a point lying between two routes and should be tense at all times.

The length of each rope is not greater than the height of the climbing wall. When one climber in a pair has reached the top of the wall, the other climber from the pair cannot go downwards.

problem_10380_1.gif

Figure: A pair of climbers attached to a single rope.

Every climber has exactly one adjacent climber to the left and to the right apart from the leftmost and the rightmost climbers who have just one adjacent climber. The climbing instructor has given an exercise to his students: they are to adjust their heights in such a way that there are as many pairs of adjacent climbers from different ropes hanging at the same heights as possible. Help the climbers and find the maximum number of such adjacent climbers.

Input Format

The first line of the standard input contains one integer $ n $ (1 ≤ $ n $ ≤ 500 00) that denotes the number of pairs of climbers. The following $ n $ lines contain descriptions of climbers from the respective pairs, given from left to right. Each line contains two integers $ a $, $ b $ (0 ≤ $ a $, $ b $ ≤ 10^{9}) that denote the distances of the climbers in the pair from the point where their rope is attached.

Output Format

The first and only line of the standard output should contain one integer equal to the maximum number of adjacent pairs of climbers from different ropes that can align at the same height.

Example

Input

3
1 1
3 2
1 4

Output

2
problem_10380_2.gif
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.