This page is still under construction.

Parts of this page are still being built. What you see may change.

Lampice

Time limit3sMemory limit1024 MB

Summary
Count axis-aligned rectangles with integer corners on an n by m terrace where, for each colour, both lamps are inside or both are outside.
Level

Hard8 of 10

Topics
Prefix sum, Dynamic programming, Math
Solved
No attempts yet

Problem

Christmas is coming! Teo has already decided to decorate his terrace.

Teo has a big rectangular terrace. It is nn meters long and mm meters wide. Instead of hanging Christmas lights on the edges of the terrace, he will put them on the floor.

Teo has 2k2k lamps, two for each of kk colours. He will put each lamp at some position (xi,yi)(x_i, y_i), where xix_i is the distance from the left side of the terrace and yiy_i is the distance from the bottom side.

Proud of how he decorated the terrace, he decided to take the rest of his day off. Soon he got bored and returned to the terrace. He started counting nice rectangles on the terrace. A rectangle is nice if for each colour, both lamps are either inside or outside of the rectangle. A lamp located on the edge of the rectangle counts as inside.

The left rectangle is not nice. One blue lamp is inside the rectangle and one is outside. The right rectangle is nice. The red and blue lamps are inside, and the yellow lamps are outside.

Teo has realized that counting nice rectangles is not an easy job. He wants to know how many nice rectangles there are whose corners have integer distances from the bottom and left sides of the terrace. All rectangles considered are parallel to the sides of the terrace. Your task is to count the nice rectangles.

Input

The first line contains three integers nn, mm, kk (1≤n≤1501 \le n \le 150, 1≤m≤10001 \le m \le 1000, 0≤k≤2000000 \le k \le 200000), the length and the width of the terrace, and the number of lamp colours.

The next kk lines contain four numbers x1x_1, y1y_1, x2x_2, y2y_2 (0≤x1,x2≤n0 \le x_1, x_2 \le n, 0≤y1,y2≤m0 \le y_1, y_2 \le m), the positions of the first and the second lamp of the ii-th colour.

Output

In a single line, output the number of nice rectangles.

Hint

Clarification of the first example: the image shows all nice rectangles from the first example.

Examples3

  1. Example 1

    Input
    2 2 1
    0 0 1 2
    
    Expected output
    3
    
  2. Example 2

    Input
    3 3 0
    
    Expected output
    36
    
  3. Example 3

    Input
    3 3 5
    0 0 0 0
    0 0 1 3
    0 0 3 1
    1 3 3 1
    1 3 3 1
    
    Expected output
    7