PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000145. Xoay các hình chữ nhật (Turn the Rectangles)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xoay các hình chữ nhật (Turn the Rectangles)

Turn the Rectangles

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn rectangles arranged in a fixed order. Each rectangle may be kept unchanged or rotated by 90∘90^\circ, exchanging its width and height.

Determine whether their selected heights can be non-increasing from the first rectangle to the last.

Input

The first line contains nn. The next nn lines contain wi,hiw_i,h_i, the width and height of each rectangle.

Output

Print YES if a non-increasing sequence of heights can be obtained, otherwise print NO.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤wi,hi≤1091\le w_i,h_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000; 1≤wi,hi≤1091\le w_i,h_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤wi,hi≤1091\le w_i,h_i\le10^9.

Examples

Input

3
3 4
4 6
3 5

Output

YES

Explanation

Choosing heights 4,4,34,4,3 is possible by rotating the second and third rectangles. Since 4≥4≥34\ge4\ge3, the answer is YES.