cswork / OAOpen practice workspace

AmazonOA #313

Count Idle Warehouse Robots

Estimated MediumJudge-ready

Topics (AI-labelled)HashingIn-place Arrays

n robots stand at distinct integer coordinates. A robot is idle if another robot is to its left and another to its right in the same row, and another is above it and another below it in the same column. These robots do not need to be at distance 1, and there may be gaps in between. Find the number of idle robots.

Input

The first line contains n, followed by n lines of x y. The original bounds are 1≤n≤100000, −10^9≤x,y≤10^9, and the coordinate pairs are distinct.

Output

Output a single integer, the answer.

Example 1

Input:

5
0 0
-2 0
2 0
0 -3
0 3

Output:

1

Example 2

Input:

3
0 0
1 0
2 0

Output:

0

Example 3

Input:

4
0 0
1 0
0 1
1 1

Output:

0

Example notes

The answers are 1, 0 and 0. In the first example no neighbor needs to be at distance 1, and the center robot is still idle.

Editorial

Loading solution…