This page is still under construction.

Parts of this page are still being built. What you see may change.

Temperature

Time limit1sMemory limit128 MB

Summary
Each day gives an interval the temperature could lie in; find the longest run of consecutive days that can be assigned non-decreasing values.
Level

Medium6 of 10

Topics
Greedy, Two pointers, Intervals, Implementation
Solved
No attempts yet

Problem

The Byteotian Institute of Meteorology (BIM) measures the air temperature every day. The measurement is automatic and the result is printed immediately, but the printer's ink dried out long ago, so nothing was actually recorded. The staff noticed this only once the Byteotian Organisation for Meteorology (BOM) asked for the data.

Luckily, an intern named Byteasar had been diligently writing down the readings of two alcohol thermometers, one mounted on the north outside wall of the building and one on the south. It has long been known that the thermometer on the south wall never reads below the true temperature, while the one on the north wall never reads above it. So although the exact temperature on each day is unknown, the range it lay in is known.

BOM does not need the exact temperatures. It only wants the longest stretch of consecutive days during which the temperature was not dropping (each day at least as warm as the day before), and BIM would like that stretch reported as long as possible. Based on Byteasar's notes, determine the length of the longest such stretch. In other words, if the true temperature of each day may be chosen freely within that day's range, find the maximum number of consecutive days over which the temperatures can be made non-decreasing.

Input

The first line contains a single integer nn (1≤n≤1,000,0001 \le n \le 1{,}000{,}000), the number of days for which Byteasar took notes. Each of the next nn lines describes one day: the ii-th of them holds two integers xx and yy (−109≤x≤y≤109-10^9 \le x \le y \le 10^9), the minimum and maximum possible temperature on day ii as reported by the two thermometers.

In some of the inputs the temperature always stays between −50-50 and 5050 degrees Celsius (−50≤x≤y≤50-50 \le x \le y \le 50).

Output

Print a single integer: the maximum number of consecutive days during which the temperature in Byteotia could have been non-dropping.

Hint

Examples1

  1. Example 1

    Input
    6
    6 10
    1 5
    4 8
    2 5
    6 8
    3 5
    
    Expected output
    4