P23200 [AtCoder] [ABC038D] Presents
提高-
题目描述

Problem Description

Takahashi has been tasked with preparing presents. The contents of the presents are already decided, and all that's left is to prepare the boxes to put them in. Takahashi has $N$ boxes available, with the $i$-th box being sized $h_i$ cm × $w_i$ cm.

Takahashi thinks it would be more interesting if the presents were in as many boxes as possible. Therefore, he decided to nest as many boxes as possible and put the present in the innermost box. A box can only be placed in another box that is larger in both dimensions. Also, a box can contain at most one other box.

Determine the maximum number of nested boxes that can be used to enclose the present.

Input Format

The input is given from the standard input in the following format:

$ N $ $ w_1 $ $ h_1 $ $ w_2 $ $ h_2 $ : $ w_N $ $ h_N $

Output Format

Output the maximum number of boxes that can enclose the present in one line.

Sample Input and Output

Sample Input #1

3
3 3
1 1
2 2

Sample Output #1

3

Sample Input #2

2
4 5
4 3

Sample Output #2

1

Sample Input #3

4
2 5
3 3
4 5
6 6

Sample Output #3

3

Sample Input #4

5
8 8
5 3
2 2
4 2
2 1

Sample Output #4

4

Notes/Hints

Constraints

  • $ 1≦N≦10^5 $
  • $ 1≦h_i≦10^5 $
  • $ 1≦w_i≦10^5 $

Partial Points

  • If you correctly solve all test cases where $ N ≦ 1,000 $, you will be awarded 30 points as partial credit.

Sample Explanation 1

The present can be enclosed by the boxes in the order of box 1, box 3, and then box 2, from the outermost to the innermost.

Sample Explanation 2

Note that you cannot rotate the boxes 90 degrees. Also, a box cannot be placed in another box that has the same length in either dimension.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 3 1 1 2 2
样例输出
3