Under construction

Still being built. Things may change

Carpets

Interview

Time limit1sMemory limit1024 MB

Summary
Given up to three axis-aligned rectangles, find the total area of their union.
Level

Easy3 of 10

Topics
Geometry, Implementation, Math, Brute force
Solved
No attempts yet

Problem

The grandest hall of Prince Ville's new castle has a rectangular floor. Its walls run North-South and East-West. Ville's advisors have proposed covering parts of the floor with carpets and have even suggested a specific arrangement.

Caring mostly about the size of the deal, Ville wants to know the total area of the floor covered by the carpets in this arrangement. Where carpets overlap, the shared region is counted only once.

Input

The first line contains three space-separated integers KK, LL, and PP: the number of carpets KK (1≤K≤31 \le K \le 3), the distance LL from the East wall to the West wall (1≤L≤1061 \le L \le 10^6), and the distance PP from the North wall to the South wall (1≤P≤1061 \le P \le 10^6).

Each of the next KK lines contains four space-separated integers NN, SS, EE, and WW describing one carpet. The carpet's edges are parallel to the walls, and NN, SS, EE, and WW give the distance of the carpet's North, South, East, and West edge from the corresponding wall, respectively. Carpets may overlap partially or fully. All distances are in metres.

Output

Print a single integer SS: the total area of the floor covered by carpets, in square metres.

Examples2

  1. Example 1

    Input
    2 8 9
    3 3 3 0
    5 1 2 4
    
    Expected output
    20
    
  2. Example 2

    Input
    3 5 5
    3 1 1 3
    1 3 3 1
    3 1 3 1
    
    Expected output
    3