Signal Flood

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
PyPy 3 2.0s
Python 3 2.0s
Memory limit: 977M

Problem type

The central district of Neon City is covered by a swarm of emergency transmitters. Each transmitter floods an axis-aligned rectangular region of the ground with radio noise.

Your repair drone can only land in places receiving exactly K simultaneous broadcasts. After all N transmitters are active, determine the total area where the signal strength is exactly K.

Model the district as the 2D x-y plane. Each transmitter is described by the coordinates of the lower-left and upper-right corners of its rectangular coverage zone.

Input

The first line contains two integers N and K.

Each of the next N lines contains four integers x_1, y_1, x_2, y_2, describing a rectangle with lower-left corner  (x_1, y_1) and upper-right corner  (x_2, y_2) .

Output

Output a single integer: the area covered by exactly K transmitters.

Constraints

  • 1 \le K \le N \le 10^5
  • 0 \le x_1 < x_2 \le 1000
  • 0 \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

Exactly eight unit squares are covered by two transmitters.

Example 2

Input
4 1
0 0 2 3
2 0 4 3
1 1 3 2
0 3 4 4
Output
14
Explanation

The third rectangle overlaps one unit square from each of the first two rectangles. Those two overlapped squares have coverage 2, so the remaining 14 units of area have coverage exactly 1.


Comments

There are no comments at the moment.