Under construction

Still being built. Things may change

Grindelwald Photofit

Time limit2sMemory limit1024 MB

Summary
Check whether every painted pixel in grid p is allowed by its restriction in grid c, and print correct or incorrect.
Level

Easy1 of 10

Topics
Implementation, Matrix
Solved
No attempts yet

Statement

The Ministry of Magic wants to put Grindelwald's photofit on the city's main electronic display. They ran into trouble with this.

The electronic photofit is a table pp with nn rows and mm columns. Each cell pi,jp_{i,j} is the color of the pixel at row ii, column jj: R (red), G (green), B (blue), or . if the pixel must be left unpainted.

The display is also n×mn \times m, but it is old. Each pixel (i,j)(i, j) has a restriction ci,jc_{i,j}:

  • ci,j=0c_{i,j} = 0: the pixel is broken and can only be left unpainted.
  • ci,j=1c_{i,j} = 1: the pixel can only be painted red or left unpainted.
  • ci,j=2c_{i,j} = 2: the pixel can only be painted green or left unpainted.
  • ci,j=3c_{i,j} = 3: the pixel can be painted red or green, or left unpainted.
  • ci,j=4c_{i,j} = 4: the pixel can only be painted blue or left unpainted.
  • ci,j=5c_{i,j} = 5: the pixel can be painted red or blue, or left unpainted.
  • ci,j=6c_{i,j} = 6: the pixel can be painted green or blue, or left unpainted.
  • ci,j=7c_{i,j} = 7: the pixel can be painted red, green, or blue, or left unpainted.

The Ministry needs to determine whether the photofit can be placed on the display while satisfying all restrictions. Help them.

Input

The first line contains two integers nn and mm separated by a space (1≤n,m≤1001 \le n, m \le 100), the number of rows and columns.

The next nn lines each contain a string of mm characters. The jj-th character of the ii-th line is pi,jp_{i,j} (pi,j∈{.,R,G,B}p_{i,j} \in \{., R, G, B\}).

After that, the next nn lines each contain a string of mm characters. The jj-th character of the ii-th line is ci,jc_{i,j} (0≤ci,j≤70 \le c_{i,j} \le 7).

Output

Print correct if the photofit pp satisfies all restrictions cc. Otherwise, print incorrect.

Examples2

  1. Example 1

    Input
    3 3
    R.B
    RBG
    ..G
    117
    346
    006
    
    Expected output
    correct
    
  2. Example 2

    Input
    3 3
    R.B
    RBG
    ..G
    117
    346
    005
    
    Expected output
    incorrect