QOJ.ac

QOJ

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

#10380. Climbing [B]

Statistics

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

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.