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

#CC0000082. Ghép kín thành một hình chữ nhật (Perfect Rectangle)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ghép kín thành một hình chữ nhật (Perfect Rectangle)

Perfect Rectangle

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given axis-aligned rectangles, determine whether they form an exact rectangular cover: there must be neither any uncovered holes nor any positive-area overlaps.

Input

The first line contains nn, followed by nn lines x1,y1,x2,y2x_1,y_1,x_2,y_2. This is the stdin/stdout adaptation.

Output

Print YES if the rectangles form a perfect rectangular cover, otherwise NO.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; −105≤x1<x2≤105-10^5\le x_1<x_2\le10^5; −105≤y1<y2≤105-10^5\le y_1<y_2\le10^5.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; −105≤x1<x2≤105-10^5\le x_1<x_2\le10^5; −105≤y1<y2≤105-10^5\le y_1<y_2\le10^5.
  • Subtask 3 (50 points): 1≤n≤200001\le n\le 20000; −105≤x1<x2≤105-10^5\le x_1<x_2\le10^5; −105≤y1<y2≤105-10^5\le y_1<y_2\le10^5.

Examples

Input

5
1 1 3 3
3 1 4 2
3 2 4 4
1 3 2 4
2 3 3 4

Output

YES

Explanation

The five rectangles fill the bounding box from (1,1)(1,1) to (4,4)(4,4) exactly, with area 99 and no gaps or overlaps.