# The problem statement is at
# https://cw.felk.cvut.cz/brute/data/ae/release/2019l_be5b33pge/pge19/evaluation/input.php?task=sensitive
# and also at the end of this file as a comment.
import time
N = 0
M = 0
inMatrix = []
# The line in which a search is performed
# is defined by start coordinatrs and the
# pair od y- and x- directions defining
# the coordinates of the next visited cell:
# (y_next, x_next) = ( y_current + dy, x_current_dx)
# In matrix setting, it is usual to use identifiers (i, j) instead of (y, x)
def doLine( mx, S, starti, startj, di, dj, endi, endj ):
i = starti; j = startj
parity = mx[i][j]
i += di; j += dj
nextParity = mx[i][j]
if nextParity != parity: return
while True:
i += di; j += dj
if i == endi or j == endj: break;
nextParity = mx[i][j]
S[i][j] = "X "
if nextParity != parity: break
# -----------------------------------------------------------------------
# M A I N
# -----------------------------------------------------------------------
t1 = time.time()
# load and precompute
# All values in the loaded matrix are immediately reduced
# to just their parities.
M, N = map(int, input().split())
for i in range(M):
row = [ (x % 2) for x in list( map( int, input().split() ) ) ]
inMatrix.append(row)
outMatrix = [['. '] * N for i in range(M)]
#process
for i in range(M):
doLine(inMatrix, outMatrix, i, 0, 0, 1, -2, N)
doLine(inMatrix, outMatrix, i, N-1, 0, -1, -2, -1)
for j in range(N):
doLine(inMatrix, outMatrix, 0, j, 1, 0, M, -2)
doLine(inMatrix, outMatrix, M-1, j, -1, 0, -1, -2)
# output
for line in outMatrix:
for x in line:
print( x, sep = '', end = '' )
print()
t2 = time.time()
#print("time:", t2 -t1)
# ---------------------------------------------------------------------------
# P R O B L E M S T A T E M E N T
# with examples
# ---------------------------------------------------------------------------
'''
Parity Sensitive Matrix Elements
In this problem, we consider integer rectangular matrices consisting of M×N cells.
The indices of the rows and the columns are 0,1,2, ..., M−1 and 0,1,2, ..., N−1, respectively.
The parity of an integer value x is the reminder of integer division x / 2,
that is, the parity of x is 1 when x is odd and the parity of x is 0 when x is even.
A cell C with with coordinates [r][c] is said to be parity sensitive
if at least one of the four following conditions is satisfied:
1. There are at least two cells in row r to the right of C.
The parity of all values in row r to the right of C is the same.
2. There are at least two cells in row r to the left of C.
The parity of all values in row r to the left of C is the same.
3. There are at least two cells in column c above C.
The parity of all values in column c above C is the same.
4. There are at least two cells in column c below C.
The parity of all values in column c below C is the same.
A parity sensitive representation of matrix A is another matrix B
of the same size as matrix A. The entries in the matrix B are defined as follows:
B[r][c] = 'X' if A[r][c] is parity sensitive.
B[r][c] = '.' if A[r][c] is not parity sensitive.
The task
--------
Print parity sensitive representation of an input matrix.
Input
The first input line contains two integers M and N representing
the number of rows and the number of columns of the input matrix.
Next, there are exactly M lines. Each line contains N values,
the values correspond to the values in a particular row in the matrix.
All values are separated by single space.
It holds 2 ≤ M, N ≤ 1000, all values in the matrix are positive integers less than 100.
Output
------
The output contains M lines representing the parity sensitive representation
of the input matrix. Consecutive values in one line are separated by single space.
Example 1
Input
6 7
2 3 4 5 5 5 1
2 2 2 1 1 1 1
3 1 3 1 3 1 4
5 2 2 2 3 3 3
2 6 1 1 3 2 2
5 5 5 2 2 2 1
Output
. . X X X . .
. . X X X . .
X . X X X X X
. . X X X X .
. . X . X X .
. . X X X . .
Example 2
Input
8 8
2 3 4 8 7 9 7 1
3 1 5 6 2 4 1 9
1 9 1 1 6 2 2 1
2 3 7 6 5 3 8 2
8 8 5 7 6 1 3 7
8 9 2 8 5 5 3 7
4 4 6 1 9 7 9 7
3 8 9 4 6 4 4 6
Output
. . . X X X . .
. . X X . X . .
. X X X X . X X
. X . . . X . X
. X X . X X . .
. X . X X X . .
. . X X X X . .
. . X X X X . .
Example 3
Input
10 10
9 1 3 2 6 3 6 7 1 5
5 4 1 4 2 3 1 6 8 9
7 4 6 3 6 3 5 8 8 1
8 9 2 7 4 9 3 6 7 2
2 1 5 9 4 4 2 1 3 4
5 7 5 8 9 6 4 7 2 5
2 2 8 6 3 3 2 3 1 7
4 8 2 5 1 7 3 6 2 5
3 7 9 8 1 5 7 5 9 6
9 4 2 6 7 2 1 5 8 5
Output
. . X X . . X X . .
. . . . . . . . . .
X . X X X X . . . X
X . . . X X . . . X
. . . . X X . . . .
. . X X X . . . . .
. . X X X . X X . .
X . X X X . X X . .
. . X X . . . . . .
. . . . . . . . . .
'''