Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.

You are given two matrices $A$ and $B$ of size $n \times m$, each of which consists of $0$ and $1$ only. You can apply the following operation to the matrix $A$ arbitrary number of times: take any submatrix of the matrix $A$ that has at least two rows and two columns, and invert the values in its corners (i.e. all corners of the submatrix that contain $0$, will be replaced by $1$, and all corners of the submatrix that contain $1$, will be replaced by $0$). You have to answer whether you can obtain the matrix $B$ from the matrix $A$. [Image] An example of the operation. The chosen submatrix is shown in blue and yellow, its corners are shown in yellow. 

Ramesses don't want to perform these operations by himself, so he asks you to answer this question.

A submatrix of matrix $M$ is a matrix which consist of all elements which come from one of the rows with indices $x_1, x_1+1, \ldots, x_2$ of matrix $M$ and one of the columns with indices $y_1, y_1+1, \ldots, y_2$ of matrix $M$, where $x_1, x_2, y_1, y_2$ are the edge rows and columns of the submatrix. In other words, a submatrix is a set of elements of source matrix which form a solid rectangle (i.e. without holes) with sides parallel to the sides of the original matrix. The corners of the submatrix are cells $(x_1, y_1)$, $(x_1, y_2)$, $(x_2, y_1)$, $(x_2, y_2)$, where the cell $(i,j)$ denotes the cell on the intersection of the $i$-th row and the $j$-th column.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$) — the number of rows and the number of columns in matrices $A$ and $B$.

Each of the next $n$ lines contain $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $A$ ($0 \leq A_{ij} \leq 1$). 

Each of the next $n$ lines contain $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $B$ ($0 \leq B_{ij} \leq 1$). 


-----Output-----

Print "Yes" (without quotes) if it is possible to transform the matrix $A$ to the matrix $B$ using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower).


-----Examples-----
Input
3 3
0 1 0
0 1 0
1 0 0
1 0 0
1 0 0
1 0 0

Output
Yes

Input
6 7
0 0 1 1 0 0 1
0 1 0 0 1 0 1
0 0 0 1 0 0 1
1 0 1 0 1 0 0
0 1 0 0 1 0 1
0 1 0 1 0 0 1
1 1 0 1 0 1 1
0 1 1 0 1 0 0
1 1 0 1 0 0 1
1 0 1 0 0 1 0
0 1 1 0 1 0 0
0 1 1 1 1 0 1

Output
Yes

Input
3 4
0 1 0 1
1 0 1 0
0 1 0 1
1 1 1 1
1 1 1 1
1 1 1 1

Output
No



-----Note-----

The examples are explained below. [Image] Example 1.  [Image] Example 2.  [Image] Example 3.

Difficulty: interview

Starter code:

Solutions:
from collections import defaultdict as dd
import math
import heapq
def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))

n, m=mi()
A=[]
for i in range(n):
	A.append(lm())

B=[]
for i in range(n):
	B.append(lm())

def check(A,B):
	for i in range(n):
		count=0
		for j in range(m):
			count+=abs(A[i][j]-B[i][j])

		if not count%2==0:
			return 'No'

	for j in range(m):
		count=0
		for i in range(n):
			count+=abs(A[i][j]-B[i][j])
		if not count%2==0:
			return 'No'

	return 'Yes'

print(check(A,B))















import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return tuple(map(int, sys.stdin.readline().split()))
def LLI(): return [tuple(map(int, l.split())) for l in sys.stdin]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    b = [LI() for _ in range(n)]
    for i in range(n):
        t = 0
        for j in range(m):
            if a[i][j] != b[i][j]:
                t += 1
        if t % 2 == 1:
            return 'No'

    for j in range(m):
        t = 0
        for i in range(n):
            if a[i][j] != b[i][j]:
                t += 1
        if t % 2 == 1:
            return 'No'

    return 'Yes'

print(main())




def main():
    n, m = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(n)]
    kek = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        for j in range(m):
            arr[i][j] ^= kek[i][j]
    f = 1
    for i in range(n):
        s = 0
        for j in range(m):
            s += arr[i][j]
        if s & 1:
            f = 0
            break
    for i in range(m):
        s = 0
        for j in range(n):
            s += arr[j][i]
        if s & 1:
            f = 0
            break
    if f:
        print("Yes")
    else:
        print("No")
    return 0
main()

n,m = list(map(int,input().split()))
A = [[int(x) for x in input().split()] for _ in range(n)]
B = [[int(x) for x in input().split()] for _ in range(n)]

for i in range(n-1):
    for j in range(m-1):
        if A[i][j] != B[i][j]:
            A[i][j] = 1 - A[i][j]
            A[i+1][j] = 1 - A[i+1][j]
            A[i][j+1] = 1 - A[i][j+1]
            A[i+1][j+1] = 1 - A[i+1][j+1]

if A == B:
    print('Yes')
else:
    print('No')


n,m = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(n)]
B = [list(map(int,input().split())) for _ in range(n)]

def rev(i, j):
    A[i][j] ^= 1
    A[i + 1][j] ^= 1
    A[i][j + 1] ^= 1
    A[i + 1][j + 1] ^= 1

for i in range(n - 1):
    for j in range(m - 1):
        # A[i][j] -> B[i][j]
        if A[i][j] != B[i][j]:
            rev(i, j)

if A == B:
    print('Yes')
else:
    print('No')


def get_inp(nf):
    a = b = 0
    for _ in range(nf):
        inp = input()
        a ^= int(inp.replace(' ', ''), 2)
        b = b * 2 + inp.count('1') % 2
    return a, b


n = int(input().split()[0])
if get_inp(n) == get_inp(n):
    print("Yes")
else:
    print("No")


n, m = [int(i) for i in input().split()]
A = []
for i in range(n):
    B = [int(j) for j in input().split()]
    A.append(B)

B = []
for i in range(n):
    C = [int(j) for j in input().split()]
    B.append(C)

changesx = []
changesy = []

for i in range(n):
    for j in range(m):
        if A[i][j] != B[i][j]:
            changesx.append(i)
            changesy.append(j)

from collections import defaultdict

ddx = defaultdict(int)
ddy = defaultdict(int)

for i in changesx:
    ddx[i] += 1
for i in changesy:
    ddy[i] += 1

ok = 1

for i in ddx:
    if ddx[i]%2 != 0:
        ok = 0
for i in ddy:
    if ddy[i]%2 != 0:
        ok = 0

if ok:
    print('Yes')
else:
    print('No')


n, m = list(map(int, input().split()))

A = []
B = []

for i in range(n):
    A.append(list(map(int, input().split())))

for i in range(n):
    B.append(list(map(int, input().split())))
    
v = True

for r in range(n-1):
    for c in range(m - 1):
        if A[r][c] != B[r][c]:
            A[r][c] ^= 1
            A[r+1][c] ^= 1
            A[r][c+1] ^= 1
            A[r+1][c+1] ^= 1
    if A[r][m-1] != B[r][m-1] : v = False
if A[n-1] != B[n-1]: v = False

if v == True:
    print("Yes")
else:
    print("No")


n, m = map(int, input().split())
A1 = [list(map(int, input().split())) for i in range(n)]
A2 = [list(map(int, input().split())) for wi in range(n)]
for i in range(n):
    if A1[i].count(0) % 2 != A2[i].count(0) % 2:
        print('No')
        return
for j in range(m):
    z1 = 0
    z2 = 0
    for i in range(n):
        if A1[i][j] == 0:
            z1 += 1
        if A2[i][j] == 0:
            z2 += 1
    if z1 % 2 != z2 % 2:
        print('No')
        return
print('Yes')

N, M = list(map(int, input().split()))
A = [[int(a) for a in input().split()] for i in range(N)]
B = [[int(a) for a in input().split()] for i in range(N)]
C = [[A[i][j]^B[i][j] for j in range(M)] for i in range(N)]

for i in range(N):
    if sum(C[i]) % 2:
        print("No")
        break
    if i < N-1:
        for j in range(M):
            C[i+1][j] ^= C[i][j]

else:
    if sum(C[N-1]) == 0:
        print("Yes")
    else:
        print("No")


n,m=map(int,input().split())
mata=[None]*n
for i in range(n):
         mata[i]=list(map(int,input().split()))
matb=[None]*n
for i in range(n):
         matb[i]=list(map(int,input().split()))
for i in range(n-1):
         for j in range(m-1):
                  if(mata[i][j]==0):
                           mata[i][j]=1
                           mata[i+1][j]^=1
                           mata[i][j+1]^=1
                           mata[i+1][j+1]^=1
                  if(matb[i][j]==0):
                           matb[i][j]=1
                           matb[i+1][j]^=1
                           matb[i][j+1]^=1
                           matb[i+1][j+1]^=1
if(mata==matb):
         print("Yes")
else:
         print("No")

n, m = map(int, input().split())
a = [tuple(map(int, input().split())) for i in range(n)]
b = [tuple(map(int, input().split())) for i in range(n)]
diff = [[a[i][j] ^ b[i][j] for j in range(m)] for i in range(n)]
for line in diff:
	if line.count(1) & 1:
		print('No')
		return
for j in range(m):
	if [diff[i][j] for i in range(n)].count(1) & 1:
		print('No')
		return
print('Yes')

N,M = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]

if N==1 or M==1:
    print('Yes' if A==B else 'No')
    return

D = []
for arow,brow in zip(A,B):
    D.append([abs(a-b) for a,b in zip(arow,brow)])

for i in range(N-1):
    ds = [j for j in range(M) if D[i][j]]
    if len(ds)%2:
        print('No')
        return
    for j in ds:
        D[i+1][j] = 1 - D[i+1][j]
print('No' if any(D[-1]) else 'Yes')    


from collections import defaultdict
n,m = list(map(int,input().split())) 
# rows # columns
m1 = [list(input().split()) for _ in range(n)]
m2 = [list(input().split()) for _ in range(n)]

row_change = defaultdict(int)
col_change = defaultdict(int)
count_change = 0

for x in range(n):
    for y in range(m):
        if m1[x][y] != m2[x][y]:
            count_change += 1
            row_change[x] += 1
            col_change[y] += 1
if count_change%2:
    print ("No")
    return
if all(v%2 == 0 for k,v in list(row_change.items())) and all(v%2 == 0 for k,v in list(col_change.items())):
    print ("Yes")
    return
print ("No")


n, m = list(map(int, input().split()))
A = []
B = []
Acount = []
Bcount = []
for i in range(n):
    A.append(list(map(int, input().split())))

for i in range(n):
    B.append(list(map(int, input().split())))

for i in range(n):
    count = 0
    for j in range(m):
        if A[i][j] == 1:
            count += 1
    Acount.append(count)
for i in range(m):
    count = 0
    for j in range(n):
        if A[j][i] == 1:
            count += 1
    Acount.append(count)

for i in range(n):
    count = 0
    for j in range(m):
        if B[i][j] == 1:
            count += 1
    Bcount.append(count)
for i in range(m):
    count = 0
    for j in range(n):
        if B[j][i] == 1:
            count += 1
    Bcount.append(count)

flag = 1
for i in range(n+m):
    if (Acount[i] - Bcount[i]) % 2 == 1:
        flag = 0
if flag == 1:
    print("Yes")
else:
    print("No")


def Solve(A,B,n,m):
    for i in range(n-1):
        for j in range(m-1):
            if A[i][j] != B[i][j]:
                A[i][j] = int(not A[i][j])
                A[i][j+1] = int(not A[i][j+1])
                A[i+1][j] = int(not A[i+1][j])
                A[i+1][j+1] = int(not A[i+1][j+1])

    for i in range(n):
        for j in range(m):
            if A[i][j] != B[i][j]:
                print('No')
                return
    print('Yes')

def main():
    n,m = list(map(int,input().split()))
    A = []
    B = []
    for i in range(n):
        A.append(list(map(int,input().split())))
    for i in range(n):
        B.append(list(map(int,input().split())))

    Solve(A,B,n,m)


main()


from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD=pow(10,9)+7

def IN(f=0):
    if f==0:
        return ( [int(i) for i in sys.stdin.readline().split()] )
    else:
        return ( int(sys.stdin.readline()) )

n,m=IN()
a=[]
b=[]
c=[]
for i in range(n):
    rr=IN()
    a.append(rr)
    c.append(rr)
for i in range(n):
    b.append(IN())

fr=[0 for i in range(n)]
fc=[0 for i in range(m)]

for i in range(n):
    for j in range(m):
        if c[i][j]==b[i][j]:
            c[i][j]=0
        else:
            c[i][j]=1
            fr[i]+=1
            fc[j]+=1
f="Yes"
for i in fr:
    if i%2!=0:
        f="No"
        break
for i in fc:
    if i%2!=0:
        f="No"
        break
print(f)

            


# -*- coding: utf-8 -*-
# @Time    : 2019/4/6 20:26
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : C. Ramesses and Corner Inversion.py

def main():
    n, m = map(int, input().split())

    a, b = [], []
    for i in range(n):
        a.append(list(map(int, input().split())))
    for i in range(n):
        b.append(list(map(int, input().split())))

    for i in range(n - 1):
        for j in range(m - 1):
            if a[i][j] != b[i][j]:
                a[i][j] = 1 - a[i][j]
                a[i + 1][j] = 1 - a[i + 1][j]
                a[i][j + 1] = 1 - a[i][j + 1]
                a[i + 1][j + 1] = 1 - a[i + 1][j + 1]

    for i in range(n):
        for j in range(m):
            if a[i][j] != b[i][j]:
                print('No')
                return
    print('Yes')


def __starting_point():
    main()
__starting_point()