#P11543. Matrix Transformation

    ID: 13632 Type: Default 1000ms 256MiB

Matrix Transformation

Matrix Transformation

Penguin Doudou has two $01$ matrices, \(\mathbf{A}\) and \(\mathbf{B}\), of the same size. He can perform the following two types of operations on matrix \(\mathbf{A}\):

  1. Select a row in \(\mathbf{A}\) and flip every element in that row (i.e. change each \(0\) to \(1\) and each \(1\) to \(0\)).
  2. Select a column in \(\mathbf{A}\) and flip every element in that column.

The goal is to determine whether it is possible to transform \(\mathbf{A}\) into \(\mathbf{B}\) by performing a series of these operations.

In other words, using any number of row or column flips, can we obtain \(\mathbf{B}\) from \(\mathbf{A}\)?

inputFormat

The first line contains two integers \(n\) and \(m\) representing the number of rows and columns, respectively. This is followed by the description of two matrices:

  • The next \(n\) lines each contain \(m\) space-separated integers (each either 0 or 1) representing the matrix \(\mathbf{A}\).
  • The following \(n\) lines each contain \(m\) space-separated integers (each either 0 or 1) representing the matrix \(\mathbf{B}\).

outputFormat

Output Yes if it is possible to transform \(\mathbf{A}\) into \(\mathbf{B}\) using the operations described above; otherwise, output No.

sample

2 2
0 1
1 0
1 0
0 1
Yes