Under construction

Still being built. Things may change

Unit Placement at the Sinchon Defense Headquarters

Time limit2.4sMemory limit1024 MB

Summary
Place the most elephants on empty cells that no soldier attacks, so that no two elephants attack each other, and print one optimal layout.
Level

Medium7 of 10

Topics
Graph, Matrix, Implementation
Solved
No attempts yet

Problem

On August 21, 2021, an unidentified organization attacked during the 2021 ICPC Sinchon Summer Algorithm Camp Contest. The Sinchon Defense Headquarters repelled the attack without any casualties and tracked down the organization's hideout.

The ICPC Sinchon Alliance decided to send countless elephants into a full assault on the hideout. Before the all-out attack, the alliance wants a stable unit formation made of elephants, soldiers, and alliance troops. There is no time to scrap the formation already built and start over. So the soldiers already placed stay where they are, and elephants go into the empty cells.

The formation is an N×MN \times M grid. The bottom-left cell is (1,1)(1,1), the top-left cell is (1,M)(1,M), the bottom-right cell is (N,1)(N,1), and the top-right cell is (N,M)(N,M). As the figure shows, an elephant attacks the cell one step forward and the cells two steps away diagonally. A soldier attacks the cell one step up and the cells one step to the left and right. When an elephant attacks, it can hurt the soldiers and elephants on its attack cells, so no soldier or elephant can be placed on those cells. Likewise, an elephant standing on a cell attacked by a soldier can be hurt, so no elephant can be placed on such a cell.

The alliance treats elephants as its most important tactical weapon, so it wants to place as many as possible. Find the maximum number of elephants that can be placed and their positions.

Input

The first line contains NN and MM, the size of the grid, and KK, the number of soldiers already placed. (1≤N,M≤3001 \le N, M \le 300, 0≤K≤NM0 \le K \le NM)

Each of the next KK lines contains xx and yy, the position of a soldier. (1≤x≤N1 \le x \le N, 1≤y≤M1 \le y \le M)

Output

Print the maximum number of elephants that can be placed. Then print their positions in the same way.

If there are several answers, print any of them.

Examples2

  1. Example 1

    Input
    5 5 4
    3 2
    2 3
    4 3
    3 4
    
    Expected output
    8
    1 2
    1 4
    2 1
    2 5
    4 1
    4 5
    5 2
    5 4
    
  2. Example 2

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