This page is still under construction.

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

Grade Book

Time limit1sMemory limit256 MB

Summary
Each lecture's grade is available in office p at minute t every day; starting anywhere at minute 1, find the fewest days to collect all grades.
Level

Medium7 of 10

Topics
Greedy, Sorting, Intervals, Binary search
Solved
No attempts yet

Problem

Maggy is a die hard: she still has a grade book and collects hand written grades from her lecturers. The lecturers' offices are numbered with consecutive natural numbers, starting from 11, and are located along an infinite corridor. The grade from each lecture can be picked up daily, but only in a specific office and only for one minute during the day. Receiving a grade takes a negligible amount of time, but moving between adjacent offices, in any direction, takes exactly 11 minute. A single lecturer can read several different lectures and then they may, although do not have to, give the grades for some of them at the same time; in such a case, receiving any number of grades still takes a negligible amount of time.

Maggy attended nn lectures and for each of them she knows in which office and in which minute of the day she can get the grade. Every day Maggy gets up early, so that in minute 11 she can be in any office. Help her determine the minimum number of days she needs to collect all the grades.

Input

The first line of the input contains one integer nn (1≤n≤500 0001 \leq n \leq 500\,000) denoting the number of lectures Maggy attended.

In each of the next nn lines there is a description of one lecture. One description consists of two integers p,tp, t (1≤p,t≤1091 \leq p, t \leq 10^9), separated by a single space, meaning that a grade from this lecture can be obtained daily in office pp in the tt-th minute counted from the beginning of each day.

Output

You should write one integer number in the first and only line of the output: the minimal number of days Maggy needs to pick up all grades.

Hint

On the first day Maggy can collect all grades from office number 1. On the second day she is able to collect grades in offices 2 and 3, and on the third day in offices 4 and 5.

Examples1

  1. Example 1

    Input
    7
    2 1
    1 4
    3 2
    1 1
    4 2
    5 3
    1 1
    
    Expected output
    3