P26320 [AtCoder] Rectangle β
NOI
题目描述

Problem Description

There are $ N $ rectangles, and the width and height of rectangle $ i $ are $ A_i $ and $ B_i $ respectively.

Snuke is trying to create a pattern by selecting some of these rectangles and stacking them in order. The rectangle placed in the $j\ (2\ \leq\ j)$ position must satisfy the following conditions:

  • It is completely contained within the rectangle placed in the $ j-1 $ position.
  • It must not touch the sides of the rectangle placed in the $ j-1 $ position.
  • Each side must be parallel to one of the sides of the rectangle placed in the $ j-1 $ position.

Note that the width and height of a rectangle can be swapped when placing it. Also, the order in which the rectangles are placed can be freely determined regardless of their numbers.

How many rectangles can Snuke stack at most?

Input Format

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

$ N $ $ A_1 $ $ B_1 $ $ A_2 $ $ B_2 $ $ : $ $ A_N $ $ B_N $

Output Format

Output the maximum number of rectangles that Snuke can stack.

Sample Input and Output

Sample Input #1

4
3 4
1 5
5 5
3 1

Sample Output #1

3

Sample Input #2

3
1000000000 1000000000
1000000000 1000000000
1000000000 1

Sample Output #2

1

Notes/Hints

Constraints

The input satisfies the following conditions:

  • $1\ \leq\ N\ \leq\ 2\ \times\ 10^5$
  • $1\ \leq\ A_i,B_i\ \leq\ 10^9$
  • All values in the input are integers

Sample Explanation 1

By placing rectangle $ 3 $, rectangle $ 1 $, and rectangle $ 4 $ in this order as shown in the figure, you can stack 3 rectangles. Note that swapping the width and height of a rectangle is allowed. d1833dc2257ec22da947ab7e7c018515.png

Sample Explanation 2

Note that the sides must not touch.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 3 4 1 5 5 5 3 1
样例输出
3