ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

USU Championship 2001

About     Problems     Submit solution     Judge status     Standings
Contest is over

B. Hopscotch

Time limit: 0.25 second
Memory limit: 64 MB
Nikifor likes to play hopscotch in the kindergarten. The playing field is a rectangle M × N partitioned into cells 1 × 1 meter. Nikifor hops from one cell to another possibly not adjacent cell. Each cell is colored black or white. Each time Nikifor hops into a cell, all cells whose centers are at an integer amount of meters away from Nikifor's cell center reverse their colors. You are given the final colors of the playing field cells. You also know the number of times Nikifor has been at each cell. Your task is to restore the initial colors of the cells.

Input

The first line contains two nonnegative integers M and N that do not exceed 50. The next M lines contain a character table M × N. This table describes the final coloring of the field. Character 'W' denotes the white color of the cell, and 'B' denotes the black color. There are no other characters in the table. The next M lines contain a matrix with nonnegative integer elements. Each element shows how many times Nikifor has been at the corresponding cell. Numbers in the lines are separated with a space and do not exceed 2∙109.

Output

should consist of M lines. The lines should contain a character table that shows the initial coloring of the playing field.

Sample

inputoutput
6 6
BWBBWW
BWBBWB
BBWWBW
BBBBBW
BBWWWW
BBWBBW
2 0 12 46 2 0
3 0 0 0 0 200
4 2 1 1 4 2
4 2 1 1 4 4
0 0 0 0 0 0
2 56 24 4 2 2
WWBBWW
WBWWBW
WBBBBW
WBWWBW
WBWWBW
WBWWBW
Problem Author: Dmitry Filimonenkov
Problem Source: VI Ural State University Collegiate Programming Contest (21.10.2001)
To submit the solution for this problem go to the Problem set: 1125. Hopscotch