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

#PS0000249. Sơn chuồng bò (Painting the Barn)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Sơn chuồng bò (Painting the Barn)

Painting the Barn

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Farmer John paints one side of his barn, represented by a coordinate plane. In each of NN painting operations, one coat is applied to an axis-aligned rectangle with lower-left corner (x1,y1)(x_1,y_1) and upper-right corner (x2,y2)(x_2,y_2). Initially there are no coats. Find the area covered by exactly KK coats after all operations. Repeated rectangles count separately; boundaries have zero area.

Input

First line: integers N,KN,K. Each of the next NN lines contains four integers x1,y1,x2,y2x_1,y_1,x_2,y_2 for one painting operation.

Output

Print one integer: the area covered by exactly KK coats.

Subtasks

  • Subtask 1 (20 points): 1≤K≤N≤301\le K\le N\le 30; 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≤1000001\le K\le N\le 100000; 0≤x1<x2≤10000\le x_1<x_2\le 1000; 0≤y1<y2≤10000\le y_1<y_2\le 1000; K=NK=N.
  • Subtask 3 (50 points): 1≤K≤N≤1000001\le K\le N\le 100000; 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

3 2
1 1 5 5
4 4 7 6
3 3 8 7

Output

8

Explanation

Pairwise intersections have areas 1, 4 and 6, and the triple intersection has area 1. Exactly two coats cover area 1+4+6−3=8.

Example 2

Input

2 1
0 0 2 1
2 0 4 1

Output

4

Explanation

The rectangles touch only along an edge. Each has area 2; exactly one coat covers area 4.