Under construction

Still being built. Things may change

Phoenix and Conquering the Earth

Time limit2sMemory limit1024 MB

Summary
Decide whether grid A can be turned into grid B by repeatedly adding or subtracting 1 on both cells of a free domino, where volcano cells cannot be used.
Level

Medium6 of 10

Topics
Graph, Union-find, Matrix
Solved
No attempts yet

Problem

Phoenix wants to reshape the terrain of the Earth as he likes so that he becomes its true ruler. The Earth is square, so it is represented as a grid with NN rows and MM columns, and the value of each cell is the height of that land. All heights are integers.

Using his palm, Phoenix can press down or lift the land, changing the heights of two adjacent cells forming a 1×21\times 2 or 2×12\times 1 shape by 11 or −1-1 at the same time.

However, KK cells contain erupted volcanoes. If either of the two cells to be changed contains a volcano, Phoenix is afraid his hand will get burned and does not perform that operation. Phoenix may perform the operation many times to change every height to the value he wants. Determine whether Phoenix can change the heights of the Earth as he wants and become its true ruler.

Input

The first line contains NN, MM, and KK, separated by spaces. (1≤N,M≤10001 \le N, M \le 1000, 0≤K≤N×M0 \le K \le N \times M)

From the second line, the next NN lines each contain MM integers AijA_{ij}, separated by spaces. AijA_{ij} is the current height of the cell in row ii and column jj.

From line N+2N+2, the next NN lines each contain MM integers BijB_{ij}, separated by spaces. BijB_{ij} is the height that Phoenix wants the cell in row ii and column jj to have. (−109≤Aij,Bij≤109-10^9 \le A_{ij}, B_{ij} \le 10^9)

From line 2N+22N+2, the next KK lines each contain two integers xx and yy, separated by a space, giving the position of a volcano. (1≤x≤N1 \le x \le N, 1≤y≤M1 \le y \le M)

All KK volcano positions are distinct.

Output

If Phoenix can perform the operations appropriately to change the heights from AA to BB, print Yes. Otherwise, print No.

Examples3

  1. Example 1

    Input
    2 3 0
    1 2 3
    1 2 3
    0 0 0
    0 0 0
    
    Expected output
    Yes
    
  2. Example 2

    Input
    3 3 3
    0 0 0
    0 0 0
    0 0 0
    -7 -8 0
    5 0 -100
    4 0 -100
    1 3
    2 2
    3 2
    
    Expected output
    Yes
    
  3. Example 3

    Input
    2 2 4
    0 0
    0 -1
    0 0
    0 0
    1 1
    1 2
    2 1
    2 2
    
    Expected output
    No