Under construction

Still being built. Things may change

Binary Table

Interview

Time limit6sMemory limit1024 MB

Summary
Given a binary table and rectangle flips, report after each flip the fewest top-left rectangle flips needed to reset the table to all zeros.
Level

Medium6 of 10

Topics
Matrix, Prefix sum
Solved
No attempts yet

Statement

You are given a table AA with nn rows and mm columns. Each cell holds a 0 or a 1. Rows are numbered 1,…,n1, \ldots, n from top to bottom, and columns are numbered 1,…,m1, \ldots, m from left to right. The cell in row ii and column jj has coordinates (i,j)(i, j). The figure below also shows this.

The table supports a flip operation on a rectangle. Each operation is given by four numbers i1,j1,i2,j2i_1, j_1, i_2, j_2. The rectangle has opposite corners at (i1,j1)(i_1, j_1) and (i2,j2)(i_2, j_2). Every cell inside it changes from 0 to 1 or from 1 to 0.

An operation is called simple if its top left corner is the top left corner of the table, that is, i1=j1=1i_1 = j_1 = 1.

Initially every number in the table is 0. Then qq operations are applied, each changing the table. After each operation, find how many more simple operations would be needed to turn every number in the table back to 0.

Input

The first line contains three integers nn, mm, and qq (1≤n,m≤10001 \le n, m \le 1000, 1≤q≤1000001 \le q \le 100000), the table size and the number of operations.

Each of the next qq lines describes one operation with four integers i1i_1, j1j_1, i2i_2, j2j_2 (1≤i1≤i2≤n1 \le i_1 \le i_2 \le n, 1≤j1≤j2≤m1 \le j_1 \le j_2 \le m).

Output

Print exactly qq lines. The ii-th line contains the minimum number of simple operations needed to turn every number in the table to 0, after the first ii operations from the input have been applied.

Hint

The top row of the figure shows the table AA after the three operations from the input, applied in order. Each column shows the table being reset to zeros with the minimum number of simple operations.

Examples1

  1. Example 1

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