Under construction

Still being built. Things may change

Sea Battle

Interview

Time limit2sMemory limit1024 MB

Summary
Given an n by m board and k ships, print INCORRECT if any ships overlap or touch, otherwise count the cells where a new 1x1 ship can go without touching any ship.
Level

Easy3 of 10

Topics
Matrix, Implementation
Solved
No attempts yet

Statement

Little Yan is writing an artificial intelligence for a game of Battleship.

Battleship is a two-player game. Each player has a rectangular grid of size n×mn \times m and places several ships on it. Each ship is a horizontal rectangle of height 1 or a vertical rectangle of width 1, and it covers several cells in full. Ships must not share any points, even on the border.

At some point in the game, one module of Yan's program must count the number of possible positions for an enemy ship of size 1×11 \times 1. At that moment, the positions of some other ships are already known. The module must check whether the opponent broke the placement rules. If not, it must count how many positions are available for one more 1×11 \times 1 ship.

Help Yan write this part of the program.

Input

The first line contains three integers nn, mm, and kk (1≤n,m≤10001 \le n, m \le 1000; 0≤k≤100000 \le k \le 10000), the board size and the number of known enemy ships.

Each of the next kk lines contains four integers x1x_1, y1y_1, x2x_2, y2y_2 (1≤x1≤x2≤n1 \le x_1 \le x_2 \le n; 1≤y1≤y2≤m1 \le y_1 \le y_2 \le m), the coordinates of the top-left and bottom-right cells of a ship.

If a ship is vertical, then y1=y2y_1 = y_2. If it is horizontal, then x1=x2x_1 = x_2.

Output

If two ships share a point (the opponent broke the rules), print the single word INCORRECT. Otherwise, print a single integer, the number of possible positions for one more enemy ship of size 1×11 \times 1.

Hint

The dots in the picture mark the possible positions of the enemy 1×11 \times 1 ship in the first example.

Examples2

  1. Example 1

    Input
    10 10 10
    1 1 1 2
    1 4 3 4
    1 7 1 10
    3 1 6 1
    3 6 3 8
    3 10 4 10
    6 6 7 6
    8 1 8 2
    8 10 8 10
    10 6 10 10
    
    Expected output
    17
    
  2. Example 2

    Input
    3 3 2
    1 1 1 1
    2 2 2 3
    
    Expected output
    INCORRECT