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

#PS0000270. Diện tích phủ ít nhất K hình (Area Covered at Least K Times)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Diện tích phủ ít nhất K hình (Area Covered at Least K Times)

Area Covered at Least K Times

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given NN axis-aligned rectangles, each covering [x1,x2)×[y1,y2)[x_1,x_2)\times[y_1,y_2), find the area covered by at least KK rectangles. Identical rectangles count separately; boundaries have zero area.

Input

First line: N,KN,K. Next NN lines: x1,y1,x2,y2x_1,y_1,x_2,y_2.

Output

Print the required area.

Subtasks

  • Subtask 1 (20 points): 1≤K≤N≤201\le K\le N\le 20; 0≤x1<x2≤300\le x_1<x_2\le 30; 0≤y1<y2≤300\le y_1<y_2\le 30.
  • Subtask 2 (30 points): 1≤K≤N≤5001\le K\le N\le 500; 0≤x1<x2≤10000\le x_1<x_2\le 1000; 0≤y1<y2≤10000\le y_1<y_2\le 1000; K=1K=1.
  • Subtask 3 (50 points): 1≤K≤N≤5001\le K\le N\le 500; 0≤x1<x2≤10000\le x_1<x_2\le 1000; 0≤y1<y2≤10000\le y_1<y_2\le 1000.

Example 1

Input

2 2
0 0 3 2
1 1 4 3

Output

2

Explanation

The intersection is [1,3)×[1,2)[1,3)\times[1,2), with area 2.

Example 2

Input

2 1
0 0 2 2
2 0 4 2

Output

8

Explanation

The rectangles only touch at an edge, so the area is 4+4=84+4=8.