Under construction

Still being built. Things may change

Painting

Interview

Time limit2sMemory limit1024 MB

Summary
After each flip on a checkerboard grid, report the fewest cells to recolor so that black cells form a top block and white cells form the rest.
Level

Medium5 of 10

Topics
Segment tree, Prefix sum, Implementation
Solved
No attempts yet

Problem

Magni and Modi got bored while waiting for the battle with Kratos, so they decided to have some fun with coloring. The coloring is an n×mn \times m rectangle split into nmnm unit squares. Rows are numbered from 11 to nn, and columns are numbered from 11 to mm. Denote by (a,b)(a, b) the cell at the intersection of row aa and column bb. Initially the rectangle has a checkerboard pattern: cell (a,b)(a, b) is white if a+ba + b is even, and black otherwise. Modi likes order. He calls the simplicity of a coloring the minimum number of cells that must be recolored (turning a black cell white and a white cell black) so that there is an integer tt where cell (a,b)(a, b) is black if a≤ta \le t and white otherwise. In other words, the simplicity is the minimum number of cells whose color must change so that a line parallel to the side of length mm can be drawn with every cell above it black and every cell below it white. Magni likes creativity more than order. From time to time he flips the color of one cell, turning black into white and white into black. After each flip, Modi wants to know the simplicity of the resulting coloring. Magni makes qq flips in total, and at the ii-th flip he flips cell (ai,bi)(a_i, b_i). Since Magni acts very fast, Modi asked you to write a program that helps him.

Input

The first line contains two integers nn and mm, the dimensions of the coloring (1≤n≤200 0001 \le n \le 200\,000, 1≤m≤101 \le m \le 10). The second line contains a single integer qq, the number of flips Magni made (1≤q≤200 0001 \le q \le 200\,000). Each of the next qq lines contains two integers aia_i and bib_i, the coordinates of the cell flipped by the ii-th action (1≤ai≤n1 \le a_i \le n, 1≤bi≤m1 \le b_i \le m).

Output

Print qq lines. For each action of Magni, print the simplicity of the coloring after that action.

Examples1

  1. Example 1

    Input
    5 4
    4
    1 1
    5 1
    1 3
    2 3
    
    Expected output
    9
    8
    7
    8