Under construction

Still being built. Things may change

The Mirror Cat Leaves a Mirror Behind When It Dies

Time limit1sMemory limit1024 MB

Summary
Given N cats in fire order, each living cat emits beams in four directions blocked by any mirror; a cat dies if hit, leaving a mirror below its cell; count survivors.
Level

Medium6 of 10

Topics
Simulation, Hash map, Sorting, Implementation
Solved
No attempts yet

Problem

On an island in the grid-based Didimon Adventure, mirror cats live together. While surveying their ecosystem, Didi discovered a shocking fact. A mirror cat fires a beam that melts every living creature it touches in the four cardinal directions. That beam passes through other mirror cats and reaches the edge of the grid no matter where it is fired from. Mirror cats evolved to carry a mirror on their tail to protect their own body from companions, and that mirror is always located in the cell just below the mirror cat. The mirror blocks the beam and is not melted by it. Also, since matte is the trend these days, the mirror does not reflect the beam. Because a mirror cat leaves a mirror behind when it dies, the mirror stays in its place even after the mirror cat is melted away.

Didi found out that the order in which the mirror cats fire their beams is fixed. However, a mirror cat that has already disappeared to someone's beam cannot fire its beam even when its turn comes. When all living mirror cats have each fired a beam once in order, write a program to find the number of mirror cats that survive to the end.

Input

The first line gives the integer NN, the number of mirror cats (1≤N≤2×1051 \le N \le 2 \times 10^5).

From the second line, NN lines give the grid positions Ri,CiR_i, C_i of the mirror cats in the order they fire their beams, separated by spaces (1≤Ri,Ci≤1051 \le R_i, C_i \le 10^5). It is guaranteed that no two mirror cats share a position, and that no mirror cat's position coincides with any mirror's position.

Output

Output the number of mirror cats that survive to the end.

Examples2

  1. Example 1

    Input
    3
    1 1
    1 4
    1 3
    
    Expected output
    1
    
  2. Example 2

    Input
    2
    3 2
    1 2
    
    Expected output
    2