atcoder#ABC205F. [ABC205F] Grid and Tokens

[ABC205F] Grid and Tokens

Score : 600600 points

Problem Statement

There is a grid with HH rows and WW columns. Let (r,c)(r, c) denote the square at the rr-th row from the top and cc-th column from the left.

We have NN pieces. For the ii-th piece, we can choose to do one of the following:

  • Put it at a square (r,c)(r, c) such that AirCiA_i \leq r \leq C_i and BicDiB_i \leq c \leq D_i.
  • Do not put it on the grid.

However, we cannot put two pieces in the same row or the same column.

At most how many pieces can we put on the grid?

Constraints

  • 1H,W,N1001 \leq H, W, N \leq 100
  • 1AiCiH1 \leq A_i \leq C_i \leq H
  • 1BiDiW1 \leq B_i \leq D_i \leq W
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW NN

A1A_1 B1B_1 C1C_1 D1D_1

A2A_2 B2B_2 C2C_2 D2D_2

\vdots

ANA_N BNB_N CNC_N DND_N

Output

Print the answer.

2 3 3
1 1 2 2
1 2 2 3
1 1 1 3
2

By putting the first piece at (1,1)(1, 1), the second piece at (2,2)(2, 2), and not putting the third piece on the grid, we can put two pieces on the grid. We cannot put three, so we should print 22.

5 5 3
1 1 5 5
1 1 4 4
2 2 3 3
3