C. Ramesses and Corner Inversion

problem_index: C

time_limit: 1 second

memory_limit: 256 megabytes

note:
The examples are explained below.
![image](images/cf_1119_C/2.png) Example 1.
![image](images/cf_1119_C/3.png) Example 2.
![image](images/cf_1119_C/4.png) Example 3.

solutions: ["(n, m) = map(int, input().split())\nA = []\nB = []\nAcount = []\nBcount = []\nfor i in range(n):\n\tA.append(list(map(int, input().split())))\nfor i in range(n):\n\tB.append(list(map(int, input().split())))\nfor i in range(n):\n\tcount = 0\n\tfor j in range(m):\n\t\tif A[i][j] == 1:\n\t\t\tcount += 1\n\tAcount.append(count)\nfor i in range(m):\n\tcount = 0\n\tfor j in range(n):\n\t\tif A[j][i] == 1:\n\t\t\tcount += 1\n\tAcount.append(count)\nfor i in range(n):\n\tcount = 0\n\tfor j in range(m):\n\t\tif B[i][j] == 1:\n\t\t\tcount += 1\n\tBcount.append(count)\nfor i in range(m):\n\tcount = 0\n\tfor j in range(n):\n\t\tif B[j][i] == 1:\n\t\t\tcount += 1\n\tBcount.append(count)\nflag = 1\nfor i in range(n + m):\n\tif (Acount[i] - Bcount[i]) % 2 == 1:\n\t\tflag = 0\nif flag == 1:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "def flip(bit):\n\tif bit == 0:\n\t\treturn 1\n\telse:\n\t\treturn 0\n(n, m) = map(int, input().split())\nA = []\nB = []\nfor i in range(n):\n\tA.append(list(map(int, input().split())))\nfor i in range(n):\n\tB.append(list(map(int, input().split())))\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tA[i][j] = flip(A[i][j])\n\t\t\tA[i + 1][j] = flip(A[i + 1][j])\n\t\t\tA[i][j + 1] = flip(A[i][j + 1])\n\t\t\tA[i + 1][j + 1] = flip(A[i + 1][j + 1])\nflag = 0\nfor i in range(n):\n\tfor j in range(m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tprint('No')\n\t\t\tflag = 1\n\t\t\tbreak\n\tif flag == 1:\n\t\tbreak\nelse:\n\tprint('Yes')\n", "(m, n) = map(int, input().split())\n\ndef x(l, y):\n\tt = int(l.replace(' ', ''), 2)\n\treturn y ^ t\n\ndef bn(ls):\n\ts = ''\n\tfor i in range(len(ls)):\n\t\ttemp = ls[i].count('1') % 2\n\t\ts += str(temp)\n\treturn s\na = []\nb = []\nfor i in range(m):\n\ta.append(input())\nfor i in range(m):\n\tb.append(input())\ng = h = 0\nfor i in range(m):\n\tg = x(a[i], g)\n\th = x(b[i], h)\nl = bn(a)\ns = bn(b)\nif l == s and g == h:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "(N, M) = map(int, input().split())\nA = [list(map(int, input().split())) for i in range(N)]\nB = [list(map(int, input().split())) for i in range(N)]\nif N == 1 or M == 1:\n\tprint('Yes' if A == B else 'No')\n\texit()\nD = []\nfor (arow, brow) in zip(A, B):\n\tD.append([abs(a - b) for (a, b) in zip(arow, brow)])\nfor i in range(N - 1):\n\tds = [j for j in range(M) if D[i][j]]\n\tif len(ds) % 2:\n\t\tprint('No')\n\t\texit()\n\tfor j in ds:\n\t\tD[i + 1][j] = 1 - D[i + 1][j]\nprint('No' if any(D[-1]) else 'Yes')\n", "def f(n, m, A, B):\n\ts_w_a = []\n\ts_w_b = []\n\tfor i in range(n):\n\t\ts_w_a.append(0)\n\t\ts_w_b.append(0)\n\t\tfor j in range(m):\n\t\t\ts_w_a[-1] += A[i][j]\n\t\t\ts_w_b[-1] += B[i][j]\n\ts_h_a = []\n\ts_h_b = []\n\tfor i in range(m):\n\t\ts_h_a.append(0)\n\t\ts_h_b.append(0)\n\t\tfor j in range(n):\n\t\t\ts_h_a[-1] += A[j][i]\n\t\t\ts_h_b[-1] += B[j][i]\n\tfor i in range(len(s_w_a)):\n\t\tif (s_w_a[i] - s_w_b[i]) % 2 != 0:\n\t\t\treturn 'No'\n\tfor i in range(len(s_h_a)):\n\t\tif (s_h_a[i] - s_h_b[i]) % 2 != 0:\n\t\t\treturn 'No'\n\treturn 'Yes'\n(n, m) = list(map(int, input().split()))\nA = []\nfor i in range(n):\n\tA.append(list(map(int, input().split())))\nB = []\nfor i in range(n):\n\tB.append(list(map(int, input().split())))\nprint(f(n, m, A, B))\n", "(n, m) = [int(i) for i in input().split()]\nA = []\nfor i in range(n):\n\tB = [int(j) for j in input().split()]\n\tA.append(B)\nB = []\nfor i in range(n):\n\tC = [int(j) for j in input().split()]\n\tB.append(C)\nchangesx = []\nchangesy = []\nfor i in range(n):\n\tfor j in range(m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tchangesx.append(i)\n\t\t\tchangesy.append(j)\nfrom collections import defaultdict\nddx = defaultdict(int)\nddy = defaultdict(int)\nfor i in changesx:\n\tddx[i] += 1\nfor i in changesy:\n\tddy[i] += 1\nok = 1\nfor i in ddx:\n\tif ddx[i] % 2 != 0:\n\t\tok = 0\nfor i in ddy:\n\tif ddy[i] % 2 != 0:\n\t\tok = 0\nif ok:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "def get_inp(nf):\n\ta = b = 0\n\tfor _ in range(nf):\n\t\tinp = input()\n\t\ta ^= int(inp.replace(' ', ''), 2)\n\t\tb = b * 2 + inp.count('1') % 2\n\treturn (a, b)\nn = int(input().split()[0])\nif get_inp(n) == get_inp(n):\n\tprint('Yes')\nelse:\n\tprint('No')\n", "from io import BytesIO, IOBase\nfrom math import sqrt\nimport sys, os\nfrom os import path\ninpl = lambda : list(map(int, input().split()))\ninpm = lambda : map(int, input().split())\ninpi = lambda : int(input())\ninp = lambda : input()\n(rev, ra, l) = (reversed, range, len)\nP = print\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\n\ndef input():\n\treturn sys.stdin.readline().rstrip('\\r\\n')\n\ndef B(n):\n\treturn bin(n).replace('0b', '')\n\ndef factors(n):\n\tarr = []\n\tfor i in ra(2, int(sqrt(n)) + 1):\n\t\tif n % i == 0:\n\t\t\tarr.append(i)\n\t\t\tif i * i != n:\n\t\t\t\tarr.append(int(n / i))\n\treturn arr\n\ndef dfs(arr, n):\n\tpairs = [[i + 1] for i in ra(n)]\n\tvis = [0] * (n + 1)\n\tfor i in ra(l(arr)):\n\t\tpairs[arr[i][0] - 1].append(arr[i][1])\n\tpairs[arr[i][1] - 1].append(arr[i][0])\n\tcomp = []\n\tfor i in ra(n):\n\t\tstack = [pairs[i]]\n\t\ttemp = []\n\t\tif vis[stack[-1][0]] == 0:\n\t\t\twhile len(stack) > 0:\n\t\t\t\tif vis[stack[-1][0]] == 0:\n\t\t\t\t\ttemp.append(stack[-1][0])\n\t\t\t\t\tvis[stack[-1][0]] = 1\n\t\t\t\t\ts = stack.pop()\n\t\t\t\t\tfor j in s[1:]:\n\t\t\t\t\t\tif vis[j] == 0:\n\t\t\t\t\t\t\tstack.append(pairs[j - 1])\n\t\t\t\telse:\n\t\t\t\t\tstack.pop()\n\t\t\tcomp.append(temp)\n\treturn comp\nfrom bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nimport sys, operator, math, operator\nfrom collections import Counter\nif path.exists('input.txt'):\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\nimport random, heapq\n(n, m) = inpm()\n(mat1, mat2) = ([], [])\nfor i in ra(n):\n\tmat1.append(inpl())\nfor i in ra(n):\n\tmat2.append(inpl())\n(row, col) = ([0] * 501, [0] * 501)\nfor i in ra(n):\n\tfor j in ra(m):\n\t\tif mat1[i][j] != mat2[i][j]:\n\t\t\trow[i + 1] += 1\n\t\t\tcol[j + 1] += 1\ntr = True\nfor i in ra(501):\n\tif row[i] & 1 or col[i] & 1:\n\t\ttr = False\n\t\tbreak\nif tr:\n\tP('YES')\nelse:\n\tP('NO')\n", "import os\nimport sys\nimport math\nfrom io import BytesIO, IOBase\nfrom fractions import Fraction\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n(n, m) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nok = True\nfor i in range(n):\n\tc = 0\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tc += 1\n\tif c & 1:\n\t\tok &= False\n\t\tbreak\nfor j in range(m):\n\tc = 0\n\tfor i in range(n):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tc += 1\n\tif c & 1:\n\t\tok &= False\n\t\tbreak\nif ok:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\na = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nb = []\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nc = []\nfor i in range(n):\n\tc.append([0] * m)\nfor i in range(n):\n\tfor j in range(m):\n\t\tc[i][j] = a[i][j] ^ b[i][j]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif c[i][j]:\n\t\t\tc[0][0] ^= 1\n\t\t\tc[i][0] ^= 1\n\t\t\tc[0][j] ^= 1\n\t\t\tc[i][j] ^= 1\nif any((any(i) for i in c)):\n\tprint('NO')\nelse:\n\tprint('YES')\n", "from math import gcd\nfrom bisect import bisect_left\nfrom collections import Counter\n(n, m) = map(int, input().split())\na = []\nb = []\nc1 = Counter()\nc2 = Counter()\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\n\tc1.update(a[i])\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\n\tc2.update(b[i])\nif c1[1] % 2 != c2[1] % 2 or c1[0] % 2 != c2[0] % 2:\n\tprint('No')\n\tquit()\ndel c1\ndel c2\nfor i in range(n):\n\tc1 = Counter(a[i])\n\tc2 = Counter(b[i])\n\tif c1[1] % 2 != c2[1] % 2 or c1[0] % 2 != c2[0] % 2:\n\t\tprint('No')\n\t\tquit()\nfor i in range(m):\n\tc1 = []\n\tc2 = []\n\tfor j in range(n):\n\t\tc1.append(a[j][i])\n\t\tc2.append(b[j][i])\n\tc1 = Counter(c1)\n\tc2 = Counter(c2)\n\tif c1[1] % 2 != c2[1] % 2 or c1[0] % 2 != c2[0] % 2:\n\t\tprint('No')\n\t\tquit()\nprint('Yes')\n", "(n, m) = tuple(map(int, input().split()))\na = []\nb = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nt = [[a[i][j] != b[i][j] for j in range(m)] for i in range(n)]\nrow = [sum(x) % 2 for x in t]\ncol = [sum(x) % 2 for x in zip(*t)]\nif row.count(1) + col.count(1) > 0:\n\tprint('NO')\nelse:\n\tprint('YES')\n", "def solve(n, m, a, b):\n\t(row_count_a, col_count_a) = ([0] * n, [0] * m)\n\t(row_count_b, col_count_b) = ([0] * n, [0] * m)\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif a[i][j] == '1':\n\t\t\t\trow_count_a[i] += 1\n\t\t\t\tcol_count_a[j] += 1\n\t\t\tif b[i][j] == '1':\n\t\t\t\trow_count_b[i] += 1\n\t\t\t\tcol_count_b[j] += 1\n\treturn 'Yes' if all((abs(row_count_a[i] - row_count_b[i]) % 2 == 0 for i in range(n))) and all((abs(col_count_a[i] - col_count_b[i]) % 2 == 0 for i in range(m))) else 'No'\n(n, m) = map(int, input().split())\na = [input().split() for _ in range(n)]\nb = [input().split() for _ in range(n)]\nprint(solve(n, m, a, b))\n", "(n, m) = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(n)]\ns = [list(map(int, input().split())) for _ in range(n)]\nd = [[], [], [], []]\nfor q in range(n):\n\td[0].append(a[q].count(1))\nfor q in range(m):\n\tans = 0\n\tfor q1 in range(n):\n\t\tans += a[q1][q]\n\td[1].append(ans)\nfor q in range(n):\n\td[2].append(s[q].count(1))\nfor q in range(m):\n\tans = 0\n\tfor q1 in range(n):\n\t\tans += s[q1][q]\n\td[3].append(ans)\nif all((d[0][q] % 2 == d[2][q] % 2 for q in range(n))) and all((d[1][q] % 2 == d[3][q] % 2 for q in range(m))):\n\tprint('Yes')\nelse:\n\tprint('No')\n", "mod = 10 ** 9 + 7\nfrom sys import stdin, stdout\nimport bisect\nfrom bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nimport itertools\nimport collections\nimport math\nimport heapq\nfrom random import randint as rn\n\ndef modinv(n, p):\n\treturn pow(n, p - 2, p)\n\ndef ncr(n, r, p):\n\tt = fact[n] * (ifact[r] * ifact[n - r] % p) % p\n\treturn t\n\ndef cin():\n\treturn map(int, sin().split())\n\ndef ain():\n\treturn list(map(int, sin().split()))\n\ndef sin():\n\treturn input()\n\ndef inin():\n\treturn int(input())\n\ndef GCD(x, y):\n\twhile y:\n\t\t(x, y) = (y, x % y)\n\treturn x\n\ndef main():\n\t(n, m) = cin()\n\ta = []\n\tb = []\n\tc = []\n\td = []\n\tfor i in range(n):\n\t\tl = ain()\n\t\ta.append(l)\n\t\tc.append([0] * m)\n\tfor i in range(n):\n\t\tl = ain()\n\t\tb.append(l)\n\tfor i in range(m):\n\t\td.append([0] * n)\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tc[i][j] = a[i][j] ^ b[i][j]\n\t\t\td[j][i] = c[i][j]\n\tans = 'Yes'\n\tfor i in c:\n\t\tif sum(i) % 2 != 0:\n\t\t\tans = 'No'\n\t\t\tbreak\n\tfor i in d:\n\t\tif sum(i) % 2 != 0:\n\t\t\tans = 'No'\n\t\t\tbreak\n\tprint(ans)\npy2 = round(0.5)\nif py2:\n\tfrom future_builtins import ascii, filter, hex, map, oct, zip\n\trange = xrange\nimport os, sys\nfrom io import IOBase, BytesIO\nBUFSIZE = 8192\n\nclass FastIO(BytesIO):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._file = file\n\t\tself._fd = file.fileno()\n\t\tself.writable = 'x' in file.mode or 'w' in file.mode\n\t\tself.write = super(FastIO, self).write if self.writable else None\n\n\tdef _fill(self):\n\t\ts = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\tself.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])\n\t\treturn s\n\n\tdef read(self):\n\t\twhile self._fill():\n\t\t\tpass\n\t\treturn super(FastIO, self).read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\ts = self._fill()\n\t\t\tself.newlines = s.count(b'\\n') + (not s)\n\t\tself.newlines -= 1\n\t\treturn super(FastIO, self).readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.getvalue())\n\t\t\t(self.truncate(0), self.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tif py2:\n\t\t\tself.write = self.buffer.write\n\t\t\tself.read = self.buffer.read\n\t\t\tself.readline = self.buffer.readline\n\t\telse:\n\t\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "(n, m) = [int(x) for x in input().split()]\na = []\nb = []\nfor i in range(n):\n\tk = [int(x) for x in input().split()]\n\ta.append(k)\nfor i in range(n):\n\tk = [int(x) for x in input().split()]\n\tb.append(k)\nfor i in range(n):\n\tcounter = 0\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tcounter += 1\n\tif counter % 2 == 1:\n\t\tprint('NO')\n\t\texit()\nfor i in range(m):\n\tcounter = 0\n\tfor j in range(n):\n\t\tif a[j][i] != b[j][i]:\n\t\t\tcounter += 1\n\tif counter % 2 == 1:\n\t\tprint('NO')\n\t\texit()\nprint('YES')\n", "(r, c) = [int(x) for x in input().split()]\n(a, b) = ([], [])\nfor i in range(r):\n\ta.append([int(x) for x in input().split()])\nfor i in range(r):\n\tb.append([int(x) for x in input().split()])\n\ndef change(m, i, j):\n\tfor (x, y) in [(0, 0), (1, 0), (0, 1), (1, 1)]:\n\t\tm[i + x][j + y] = 1 - m[i + x][j + y]\nfor i in range(r - 1):\n\tfor j in range(c - 1):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tchange(a, i, j)\n\tif a[i][-1] != b[i][-1]:\n\t\tprint('No')\n\t\tquit()\nfor j in range(c):\n\tif a[-1][j] != b[-1][j]:\n\t\tprint('No')\n\t\tquit()\nprint('Yes')\n", "from sys import stdin, stdout\nimport cProfile, math\nimport sys\n\ndef get_int():\n\treturn int(stdin.readline().strip())\n\ndef get_tuple():\n\treturn map(int, stdin.readline().split())\n\ndef get_list():\n\treturn list(map(int, stdin.readline().split()))\n\ndef main():\n\t(n, m) = get_tuple()\n\tmat1 = [get_list() for _ in range(n)]\n\tmat2 = [get_list() for _ in range(n)]\n\tfor i in range(n):\n\t\tdiff = 0\n\t\tfor j in range(m):\n\t\t\tif mat1[i][j] != mat2[i][j]:\n\t\t\t\tdiff += 1\n\t\tif diff % 2 != 0:\n\t\t\tprint('NO')\n\t\t\treturn\n\tfor j in range(m):\n\t\tdiff = 0\n\t\tfor i in range(n):\n\t\t\tif mat1[i][j] != mat2[i][j]:\n\t\t\t\tdiff += 1\n\t\tif diff % 2 != 0:\n\t\t\tprint('NO')\n\t\t\treturn\n\tprint('YES')\nmain()\n", "import sys\nfrom collections import defaultdict as dd\nfrom itertools import permutations as pp\nfrom itertools import combinations as cc\nfrom collections import Counter as ccd\nfrom random import randint as rd\nfrom bisect import bisect_left as bl\nfrom heapq import heappush as hpush\nfrom heapq import heappop as hpop\nmod = 10 ** 9 + 7\n\ndef ri(flag=0):\n\tif flag == 0:\n\t\treturn [int(i) for i in sys.stdin.readline().split()]\n\telse:\n\t\treturn int(sys.stdin.readline())\n(n, m) = ri()\none = []\ntwo = []\nfor i in range(n):\n\tone.append(ri())\nfor i in range(n):\n\ttwo.append(ri())\ne = []\nfor i in range(n):\n\tfor j in range(m):\n\t\tif one[i][j] != two[i][j]:\n\t\t\te.append((i, j))\nans = [[0 for i in range(m)] for j in range(n)]\nfor (i, j) in e:\n\tans[i][j] = 1\nr = [0 for i in range(n)]\nc = [0 for i in range(m)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tr[i] += ans[i][j]\n\t\tc[j] += ans[i][j]\nf = 1\nfor i in r:\n\tif i % 2 == 1:\n\t\tf = 0\nfor i in c:\n\tif i % 2 == 1:\n\t\tf = 0\nif f:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "(n, m) = list(map(int, input().split()))\nA = [list(map(int, input().split())) for _ in range(n)]\nB = [list(map(int, input().split())) for _ in range(n)]\n\ndef rev(i, j):\n\tA[i][j] ^= 1\n\tA[i + 1][j] ^= 1\n\tA[i][j + 1] ^= 1\n\tA[i + 1][j + 1] ^= 1\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif A[i][j] != B[i][j]:\n\t\t\trev(i, j)\nif A == B:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(n)]\nb = [list(map(int, input().split())) for _ in range(n)]\nd = [list(map(lambda x, y: x ^ y, u, v)) for (u, v) in zip(a, b)]\np = any(map(lambda x: sum(x) & 1, d))\nq = any(map(lambda x: sum(x) & 1, zip(*d)))\nif p or q:\n\tprint('No')\nelse:\n\tprint('Yes')\n", "def inp1():\n\treturn int(input())\n\ndef inp2():\n\treturn list(map(int, input().split()))\n\ndef inp3():\n\treturn map(int, input().split())\nif 1:\n\t(n, m) = inp3()\n\ta = []\n\tb = []\n\tc = 0\n\tfor i in range(n):\n\t\ta.append(inp2())\n\tfor i in range(n):\n\t\tb.append(inp2())\n\tf = 0\n\tans = [[0] * m for i in range(n)]\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif a[i][j] != b[i][j]:\n\t\t\t\tans[i][j] = 1\n\ta = [0] * m\n\tb = [0] * n\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\ta[j] += ans[i][j]\n\t\t\tb[i] += ans[i][j]\n\tfor i in range(m):\n\t\tif a[i] % 2:\n\t\t\tf = 1\n\tfor i in range(n):\n\t\tif b[i] % 2:\n\t\t\tf = 1\n\tif f:\n\t\tprint('No')\n\telse:\n\t\tprint('Yes')\n", "import sys\ninput = lambda : sys.stdin.readline().strip('\\r\\n')\n(n, m) = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(n)]\nb = [list(map(int, input().split())) for _ in range(n)]\nasum = 0\nbsum = 0\nfor i in range(n):\n\talpha = sum(a[i])\n\tbeta = sum(b[i])\n\tif alpha % 2 != beta % 2:\n\t\tprint('No')\n\t\texit()\n\tasum += alpha\n\tbsum += beta\nif asum % 2 != bsum % 2:\n\tprint('No')\n\texit()\nfor j in range(m):\n\talpha = 0\n\tbeta = 0\n\tfor i in range(n):\n\t\talpha += a[i][j]\n\t\tbeta += b[i][j]\n\tif alpha % 2 != beta % 2:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "(n, m) = map(int, input().split())\na = [tuple(map(int, input().split())) for i in range(n)]\nb = [tuple(map(int, input().split())) for i in range(n)]\ndiff = [[a[i][j] ^ b[i][j] for j in range(m)] for i in range(n)]\nfor line in diff:\n\tif line.count(1) & 1:\n\t\tprint('No')\n\t\texit()\nfor j in range(m):\n\tif [diff[i][j] for i in range(n)].count(1) & 1:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "t = 1\nfor _ in range(t):\n\t(n, m) = map(int, input().split())\n\tmata = []\n\tmatb = []\n\tfor i in range(n):\n\t\tarr = [int(j) for j in input().split()]\n\t\tmata += [arr]\n\tfor i in range(n):\n\t\tarr = [int(j) for j in input().split()]\n\t\tmatb += [arr]\n\tflag = 0\n\tfor i in range(n):\n\t\tcur = 0\n\t\tfor j in range(m):\n\t\t\tif mata[i][j] != matb[i][j]:\n\t\t\t\tcur += 1\n\t\tif cur % 2 == 1:\n\t\t\tflag = 1\n\tfor i in range(m):\n\t\tcur = 0\n\t\tfor j in range(n):\n\t\t\tif mata[j][i] != matb[j][i]:\n\t\t\t\tcur += 1\n\t\tif cur % 2 == 1:\n\t\t\tflag = 1\n\tif flag == 1:\n\t\tprint('No')\n\telse:\n\t\tprint('Yes')\n", "(n, m) = map(int, input().split())\nmat1 = []\nmat2 = []\nfor i in range(n):\n\tmat1.append(list(map(int, input().split())))\nfor i in range(n):\n\tmat2.append(list(map(int, input().split())))\nflag = 1\nfor i in range(n):\n\ts1 = sum(mat1[i])\n\ts2 = sum(mat2[i])\n\tif s1 % 2 != s2 % 2:\n\t\tflag = 0\n\t\tbreak\nfor i in range(m):\n\ts1 = 0\n\ts2 = 0\n\tfor j in range(n):\n\t\ts1 += mat1[j][i]\n\t\ts2 += mat2[j][i]\n\tif s1 % 2 != s2 % 2:\n\t\tflag = 0\n\t\tbreak\nif flag:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "from __future__ import division, print_function\nfrom fractions import Fraction\nimport sys\nimport os\nfrom io import BytesIO, IOBase\nimport bisect\nfrom heapq import *\nfrom math import *\nfrom collections import deque\nfrom collections import Counter as counter\nfrom itertools import combinations as comb\nfrom itertools import permutations as permutate\nfrom bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom bisect import bisect\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\ndef print(*args, **kwargs):\n\t(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))\n\tat_start = True\n\tfor x in args:\n\t\tif not at_start:\n\t\t\tfile.write(sep)\n\t\tfile.write(str(x))\n\t\tat_start = False\n\tfile.write(kwargs.pop('end', '\\n'))\n\tif kwargs.pop('flush', False):\n\t\tfile.flush()\nif sys.version_info[0] < 3:\n\t(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))\nelse:\n\t(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\nmod = 1000000007\n\ndef inp():\n\treturn sys.stdin.readline().rstrip('\\r\\n')\n\ndef out(var):\n\tsys.stdout.write(str(var))\n\ndef lis():\n\treturn list(map(int, inp().split()))\n\ndef stringlis():\n\treturn list(map(str, inp().split()))\n\ndef sep():\n\treturn map(int, inp().split())\n\ndef strsep():\n\treturn map(str, inp().split())\n\ndef graph(vertex):\n\treturn [[] for i in range(0, vertex + 1)]\n\ndef zerolist(n):\n\treturn [0] * n\n\ndef nextline():\n\tout('\\n')\n\ndef testcase(t):\n\tfor p in range(t):\n\t\tsolve()\n\ndef printlist(a):\n\tfor p in range(0, len(a)):\n\t\tout(str(a[p]) + ' ')\n\ndef lcm(a, b):\n\treturn a * b // gcd(a, b)\n\ndef power(a, b):\n\tans = 1\n\twhile b > 0:\n\t\tif b % 2 == 1:\n\t\t\tans *= a\n\t\ta *= a\n\t\tb //= 2\n\treturn ans\n\ndef ncr(n, r):\n\treturn factorial(n) // (factorial(r) * factorial(max(n - r, 1)))\n\ndef isPrime(n):\n\tif n <= 1:\n\t\treturn False\n\tif n <= 3:\n\t\treturn True\n\tif n % 2 == 0 or n % 3 == 0:\n\t\treturn False\n\ti = 5\n\twhile i * i <= n:\n\t\tif n % i == 0 or n % (i + 2) == 0:\n\t\t\treturn False\n\t\ti = i + 6\n\treturn True\n\ndef solve():\n\t(n, m) = sep()\n\ta = []\n\tb = []\n\tfor i in range(n):\n\t\ttemp = lis()\n\t\ta.append(temp)\n\tfor i in range(n):\n\t\ttemp = lis()\n\t\tb.append(temp)\n\tfor i in range(1, n):\n\t\tfor j in range(1, m):\n\t\t\tif a[i][j] != b[i][j]:\n\t\t\t\ta[i][j] = b[i][j]\n\t\t\t\ta[i][0] = 1 - a[i][0]\n\t\t\t\ta[0][j] = 1 - a[0][j]\n\t\t\t\ta[0][0] = 1 - a[0][0]\n\tfor j in range(m):\n\t\tif a[0][j] != b[0][j]:\n\t\t\tprint('No')\n\t\t\treturn\n\tfor i in range(n):\n\t\tif a[i][0] != b[i][0]:\n\t\t\tprint('No')\n\t\t\treturn\n\tprint('Yes')\ntestcase(1)\n", "(n, m) = map(int, input().split())\na = [[0] * m for i in range(n)]\nfor i in range(n):\n\ta[i] = list(map(int, input().split()))\nfor i in range(n):\n\tv = list(map(int, input().split()))\n\tfor j in range(m):\n\t\ta[i][j] ^= v[j]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] == 1:\n\t\t\tk = j + 1\n\t\t\twhile k < m and a[i][k] == 0:\n\t\t\t\tk += 1\n\t\t\tif k < m:\n\t\t\t\tz = i + 1\n\t\t\t\twhile z < n and a[z][j] == 0:\n\t\t\t\t\tz += 1\n\t\t\t\tif z < n:\n\t\t\t\t\t(a[i][j], a[i][k], a[z][j], a[z][k]) = (0, 0, 0, 1 - a[z][k])\nprint('Yes' if max(max(a)) == 0 else 'No')\n", "(n, m) = map(int, input().split())\nA = [input().split() for _ in range(n)]\nB = [input().split() for _ in range(n)]\nC = [[A[i][j] != B[i][j] for j in range(m)] for i in range(n)]\nf = True\nfor r in C:\n\tif sum(r) % 2:\n\t\tf = False\nfor c in range(m):\n\tif sum([C[r][c] for r in range(n)]) % 2:\n\t\tf = False\nif f:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(sizeI, sizeJ) = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(sizeI)]\nb = [list(map(int, input().split())) for _ in range(sizeI)]\n\ndef solve():\n\tfor i in range(sizeI):\n\t\tparityA = a[i].count(1)\n\t\tparityB = b[i].count(1)\n\t\tif parityA & 1 != parityB & 1:\n\t\t\treturn 'No'\n\tfor j in range(sizeJ):\n\t\tparityA = parityB = 0\n\t\tfor i in range(sizeI):\n\t\t\tparityA += a[i][j] == 1\n\t\t\tparityB += b[i][j] == 1\n\t\tif parityA & 1 != parityB & 1:\n\t\t\treturn 'No'\n\treturn 'Yes'\nprint(solve())\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\n\ndef main():\n\tchk = 0\n\t(n, m) = map(int, input().split(' '))\n\ta = [list(map(int, input().split(' '))) for x in range(n)]\n\tb = [list(map(int, input().split(' '))) for x in range(n)]\n\tfor x in range(n):\n\t\tif sum(a[x]) % 2 != sum(b[x]) % 2:\n\t\t\tprint('NO')\n\t\t\treturn\n\tfor y in range(m):\n\t\taa = []\n\t\tbb = []\n\t\tfor z in range(n):\n\t\t\taa.append(a[z][y])\n\t\t\tbb.append(b[z][y])\n\t\tif sum(aa) % 2 != sum(bb) % 2:\n\t\t\tprint('NO')\n\t\t\treturn\n\tprint('YES')\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "inputs = [int(x) for x in input().split()]\nn = inputs[0]\nm = inputs[1]\nif n == 1:\n\tboolean = False\n\tarr = [int(x) for x in input().split()]\n\tarr2 = [int(x) for x in input().split()]\n\tfor i in range(m):\n\t\tif arr[i] != arr2[i]:\n\t\t\tprint('no')\n\t\t\tboolean = True\n\t\t\tbreak\n\tif boolean == False:\n\t\tprint('yes')\nelif m == 1:\n\tboolean = False\n\tarr = []\n\tfor i in range(2 * n):\n\t\tarr.append(int(input()))\n\tfor i in range(n):\n\t\tif arr[i] != arr[n + i]:\n\t\t\tprint('no')\n\t\t\tboolean = True\n\t\t\tbreak\n\tif boolean == False:\n\t\tprint('yes')\nelse:\n\tfirstRows = [0 for i in range(n)]\n\tfirstColumns = [0 for i in range(m)]\n\tfor i in range(n):\n\t\tarr = [int(x) for x in input().split()]\n\t\tfor j in range(m):\n\t\t\tfirstRows[i] += arr[j]\n\t\t\tfirstColumns[j] += arr[j]\n\tfor i in range(n):\n\t\tarr = [int(x) for x in input().split()]\n\t\tfor j in range(m):\n\t\t\tfirstRows[i] -= arr[j]\n\t\t\tfirstColumns[j] -= arr[j]\n\tisWrong = False\n\tfor i in range(n):\n\t\tif firstRows[i] % 2 != 0:\n\t\t\tisWrong = True\n\t\t\tprint('no')\n\t\t\tbreak\n\tif isWrong == False:\n\t\tfor j in range(m):\n\t\t\tif firstColumns[j] % 2 != 0:\n\t\t\t\tisWrong = True\n\t\t\t\tprint('no')\n\t\t\t\tbreak\n\tif isWrong == False:\n\t\tprint('yes')\n", "first = [int(i) for i in input().split(' ')]\nn = first[0]\nm = first[1]\nA = []\nB = []\nfor i in range(n):\n\tA.append([int(i) for i in input().split(' ')])\nfor i in range(n):\n\tB.append([int(i) for i in input().split(' ')])\ndiff = []\nfor i in range(n):\n\ttmp = []\n\tfor j in range(m):\n\t\tif A[i][j] == B[i][j]:\n\t\t\ttmp.append(0)\n\t\telse:\n\t\t\ttmp.append(1)\n\tdiff.append(tmp)\n\ndef invert(matrix, x1, y1, x2, y2):\n\tmatrix[x1][y1] = 1 if matrix[x1][y1] == 0 else 0\n\tmatrix[x1][y2] = 1 if matrix[x1][y2] == 0 else 0\n\tmatrix[x2][y1] = 1 if matrix[x2][y1] == 0 else 0\n\tmatrix[x2][y2] = 1 if matrix[x2][y2] == 0 else 0\n\ndef find(matrix, n, m, i, j):\n\tfor x in range(i + 1, n):\n\t\tfor y in range(j + 1, m):\n\t\t\tif matrix[x][y] == 1:\n\t\t\t\treturn (x, y)\n\treturn (-1, -1)\n\ndef check(diff, n, m):\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif diff[i][j] == 1:\n\t\t\t\t(x, y) = find(diff, n, m, i, j)\n\t\t\t\tif x == -1 and y == -1:\n\t\t\t\t\treturn False\n\t\t\t\tinvert(diff, i, j, x, y)\n\treturn True\nres = check(diff, n, m)\nif res:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif a[i][j] != b[i][j]:\n\t\t\ta[i][j] ^= 1\n\t\t\ta[i + 1][j] ^= 1\n\t\t\ta[i][j + 1] ^= 1\n\t\t\ta[i + 1][j + 1] ^= 1\nans = True\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tans = False\nif ans == True:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, k) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nflag = 0\nfor i in range(n):\n\tr = 0\n\tfor j in range(k):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tr += 1\n\tif r % 2 == 1:\n\t\tflag = 1\n\t\tbreak\nfor i in range(k):\n\tc = 0\n\tfor j in range(n):\n\t\tif a[j][i] != b[j][i]:\n\t\t\tc += 1\n\tif c % 2 == 1:\n\t\tflag = 1\n\t\tbreak\nif flag == 1:\n\tprint('No')\nelse:\n\tprint('Yes')\n", "import heapq, math\nfrom collections import defaultdict, deque\nimport sys, os.path\nif os.path.exists('C:/Users/Dhanush/Desktop/cp/input.txt'):\n\tsys.stdout = open('C:/Users/Dhanush/Desktop/cp/output.txt', 'w')\n\tsys.stdin = open('C:/Users/Dhanush/Desktop/cp/input.txt', 'r')\ninput = sys.stdin.readline\n\ndef flip(x, y):\n\tgrid1[x][y] = 1 - grid1[x][y]\n(r, c) = map(int, input().split())\ngrid1 = []\nfor _ in range(r):\n\tl = list(map(int, input().split()))\n\tgrid1.append(l)\ngrid2 = []\nfor _ in range(r):\n\tl = list(map(int, input().split()))\n\tgrid2.append(l)\nf = 0\nfor i in range(r):\n\tcur = 0\n\tfor j in range(c):\n\t\tif grid1[i][j] != grid2[i][j]:\n\t\t\tcur += 1\n\tif cur % 2 != 0:\n\t\tf = 1\n\t\tbreak\nif f == 1:\n\tprint('NO')\nelse:\n\tfor i in range(c):\n\t\tcur = 0\n\t\tfor j in range(r):\n\t\t\tif grid1[j][i] != grid2[j][i]:\n\t\t\t\tcur += 1\n\t\tif cur % 2 != 0:\n\t\t\tf = 1\n\t\t\tbreak\n\tif f == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "(n, m) = map(int, input().split())\nA = []\nB = []\nfor i in range(n):\n\tA.append(list(map(int, input().split())))\nfor i in range(n):\n\tB.append(list(map(int, input().split())))\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tA[i][j] = 1 - A[i][j]\n\t\t\tA[i + 1][j] = 1 - A[i + 1][j]\n\t\t\tA[i][j + 1] = 1 - A[i][j + 1]\n\t\t\tA[i + 1][j + 1] = 1 - A[i + 1][j + 1]\nflag = 'YES'\nfor i in range(n):\n\tfor j in range(m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tflag = 'NO'\n\t\t\tbreak\nprint(flag)\n", "R = lambda : map(int, input().split())\n(n, m) = R()\n(A, B) = ([], [])\nfor i in range(n):\n\tA.append(list(R()))\nfor i in range(n):\n\tB.append(list(R()))\nif n == 1 or m == 1:\n\tif A == B:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n\tquit()\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tA[i][j] ^= 1\n\t\t\tA[i + 1][j] ^= 1\n\t\t\tA[i][j + 1] ^= 1\n\t\t\tA[i + 1][j + 1] ^= 1\nif A == B:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\nA1 = [list(map(int, input().split())) for i in range(n)]\nA2 = [list(map(int, input().split())) for wi in range(n)]\nfor i in range(n):\n\tif A1[i].count(0) % 2 != A2[i].count(0) % 2:\n\t\tprint('No')\n\t\treturn\nfor j in range(m):\n\tz1 = 0\n\tz2 = 0\n\tfor i in range(n):\n\t\tif A1[i][j] == 0:\n\t\t\tz1 += 1\n\t\tif A2[i][j] == 0:\n\t\t\tz2 += 1\n\tif z1 % 2 != z2 % 2:\n\t\tprint('No')\n\t\treturn\nprint('Yes')\n", "(n, m) = [int(x) for x in input().split()]\n(a, b) = ([], [])\nfor i in range(n):\n\ta.append([int(x) for x in input().split()])\nfor i in range(n):\n\tb.append([int(x) for x in input().split()])\nflag = 0\nfor i in range(n):\n\tcnt = 0\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tcnt += 1\n\tif cnt % 2 != 0:\n\t\tflag = 1\n\t\tbreak\nfor i in range(m):\n\tcnt = 0\n\tfor j in range(n):\n\t\tif a[j][i] != b[j][i]:\n\t\t\tcnt += 1\n\tif cnt % 2 != 0:\n\t\tflag = 1\n\t\tbreak\nif flag:\n\tprint('No')\nelse:\n\tprint('Yes')\n", "import sys\n(n, m) = [int(s) for s in input().split()]\narray_1 = []\nfor i in range(n):\n\tarray_1.append([int(s) for s in input().split()])\narray_2 = []\nfor i in range(n):\n\tarray_2.append([int(s) for s in input().split()])\nfor i in range(n):\n\tif sum(array_1[i]) % 2 != sum(array_2[i]) % 2:\n\t\tprint('No')\n\t\tsys.exit(0)\nfor j in range(m):\n\tsum_1 = 0\n\tsum_2 = 0\n\tfor i in range(n):\n\t\tsum_1 += array_1[i][j]\n\t\tsum_2 += array_2[i][j]\n\tif sum_1 % 2 != sum_2 % 2:\n\t\tprint('No')\n\t\tsys.exit(0)\nprint('Yes')\n", "import sys\na = []\n(n, m) = map(int, input().split())\nfor j in range(n):\n\ta.append(list(map(int, sys.stdin.readline().split())))\nb = []\nfor j in range(n):\n\tb.append(list(map(int, sys.stdin.readline().split())))\nr = [0] * n\nc = [0] * m\nfor j in range(n):\n\tfor k in range(m):\n\t\tif a[j][k] != b[j][k]:\n\t\t\tr[j] += 1\n\t\t\tc[k] += 1\nf = 0\nfor v in r:\n\tif v % 2 != 0:\n\t\tf = 1\n\t\tbreak\nif f == 0:\n\tfor v in c:\n\t\tif v % 2 != 0:\n\t\t\tf = 1\n\t\t\tbreak\nif f == 0:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "import math\nimport bisect\nimport heapq\n\ndef egcd(a, b):\n\tif a == 0:\n\t\treturn (b, 0, 1)\n\telse:\n\t\t(g, x, y) = egcd(b % a, a)\n\t\treturn (g, y - b // a * x, x)\n\ndef mulinv(b, n):\n\t(g, x, _) = egcd(b, n)\n\tif g == 1:\n\t\treturn x % n\nprimes = []\n\ndef isprime(n):\n\tfor d in range(2, int(math.sqrt(n)) + 1):\n\t\tif n % d == 0:\n\t\t\treturn False\n\treturn True\n\ndef argsort(ls):\n\treturn sorted(range(len(ls)), key=ls.__getitem__)\n\ndef f(p=0):\n\tif p == 1:\n\t\treturn map(int, input().split())\n\telif p == 2:\n\t\treturn list(map(int, input().split()))\n\telse:\n\t\treturn int(input())\n(n, m) = f(1)\nr1 = [0] * n\nr2 = [0] * n\nc1 = [0] * m\nc2 = [0] * m\nm1 = []\nm2 = []\nfor i in range(n):\n\tm1.append(f(2))\nfor i in range(n):\n\tm2.append(f(2))\nfor i in range(n):\n\tfor j in range(m):\n\t\tr1[i] += m1[i][j]\n\t\tr2[i] += m2[i][j]\n\t\tc1[j] += m1[i][j]\n\t\tc2[j] += m2[i][j]\nfor i in range(n):\n\tr1[i] = r1[i] % 2\n\tr2[i] = r2[i] % 2\nfor j in range(m):\n\tc1[j] = c1[j] % 2\n\tc2[j] = c2[j] % 2\nif c1 == c2 and r1 == r2:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\n\ndef solve(d):\n\tfor i in range(n):\n\t\tif sum(d[i]) % 2 != 0:\n\t\t\treturn False\n\tfor j in range(m):\n\t\tif sum([d[i][j] for i in range(n)]) % 2 != 0:\n\t\t\treturn False\n\treturn True\na = []\nb = []\nfor i in range(n):\n\ta.append([int(s) for s in input().split()])\nfor i in range(n):\n\tb.append([int(s) for s in input().split()])\nd = []\nfor i in range(n):\n\td.append([a[i][j] ^ b[i][j] for j in range(m)])\nans = solve(d)\nif ans:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "def Solve(A, B, n, m):\n\tfor i in range(n - 1):\n\t\tfor j in range(m - 1):\n\t\t\tif A[i][j] != B[i][j]:\n\t\t\t\tA[i][j] = int(not A[i][j])\n\t\t\t\tA[i][j + 1] = int(not A[i][j + 1])\n\t\t\t\tA[i + 1][j] = int(not A[i + 1][j])\n\t\t\t\tA[i + 1][j + 1] = int(not A[i + 1][j + 1])\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif A[i][j] != B[i][j]:\n\t\t\t\tprint('No')\n\t\t\t\treturn\n\tprint('Yes')\n\ndef main():\n\t(n, m) = list(map(int, input().split()))\n\tA = []\n\tB = []\n\tfor i in range(n):\n\t\tA.append(list(map(int, input().split())))\n\tfor i in range(n):\n\t\tB.append(list(map(int, input().split())))\n\tSolve(A, B, n, m)\nmain()\n", "def g(f):\n\ta = b = 0\n\tfor _ in range(f):\n\t\ti = input()\n\t\t(a, b) = (a ^ int(i.replace(' ', ''), 2), b * 2 + i.count('1') % 2)\n\treturn (a, b)\nn = int(input().split()[0])\nprint('Yes' if g(n) == g(n) else 'No')\n", "import sys\ninput = sys.stdin.readline\n(n, m) = map(int, input().split())\ngrid = []\nansGrid = []\nfor i in range(n):\n\tgrid.append(list(map(int, input().split())))\nfor i in range(n):\n\tansGrid.append(list(map(int, input().split())))\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif grid[i][j] != ansGrid[i][j]:\n\t\t\tgrid[i][j] ^= 1\n\t\t\tgrid[i + 1][j] ^= 1\n\t\t\tgrid[i][j + 1] ^= 1\n\t\t\tgrid[i + 1][j + 1] ^= 1\nvalid = True\nfor i in range(n):\n\tif grid[i][m - 1] != ansGrid[i][m - 1]:\n\t\tvalid = False\n\t\tbreak\nfor j in range(m):\n\tif grid[n - 1][j] != ansGrid[n - 1][j]:\n\t\tvalid = False\n\t\tbreak\nprint('Yes' if valid else 'No')\n", "line = [int(x) for x in input().split()]\nn = line[0]\nm = line[1]\nmat = [[] for _ in range(n)]\ntarget = [[] for _ in range(n)]\ncorrect = True\nfor i in range(2 * n):\n\tl = [int(x) for x in input().split(' ')]\n\tif i < n:\n\t\tmat[i] = l\n\telse:\n\t\ttarget[i - n] = l\nfor i in range(n):\n\tm_par = sum(mat[i]) % 2\n\tt_par = sum(target[i]) % 2\n\tif m_par != t_par:\n\t\tcorrect = False\n\t\tbreak\nmT = list(zip(*mat))\ntT = list(zip(*target))\nfor i in range(m):\n\tm_par = sum(mT[i]) % 2\n\tt_par = sum(tT[i]) % 2\n\tif m_par != t_par:\n\t\tcorrect = False\n\t\tbreak\nif correct:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools\nsys.setrecursionlimit(10 ** 7)\ninf = 10 ** 20\neps = 1.0 / 10 ** 10\nmod = 10 ** 9 + 7\ndd = [(-1, 0), (0, 1), (1, 0), (0, -1)]\nddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]\n\ndef LI():\n\treturn tuple(map(int, sys.stdin.readline().split()))\n\ndef LLI():\n\treturn [tuple(map(int, l.split())) for l in sys.stdin]\n\ndef LI_():\n\treturn [int(x) - 1 for x in sys.stdin.readline().split()]\n\ndef LF():\n\treturn [float(x) for x in sys.stdin.readline().split()]\n\ndef LS():\n\treturn sys.stdin.readline().split()\n\ndef I():\n\treturn int(sys.stdin.readline())\n\ndef F():\n\treturn float(sys.stdin.readline())\n\ndef S():\n\treturn input()\n\ndef pf(s):\n\treturn print(s, flush=True)\n\ndef main():\n\t(n, m) = LI()\n\ta = [LI() for _ in range(n)]\n\tb = [LI() for _ in range(n)]\n\tfor i in range(n):\n\t\tt = 0\n\t\tfor j in range(m):\n\t\t\tif a[i][j] != b[i][j]:\n\t\t\t\tt += 1\n\t\tif t % 2 == 1:\n\t\t\treturn 'No'\n\tfor j in range(m):\n\t\tt = 0\n\t\tfor i in range(n):\n\t\t\tif a[i][j] != b[i][j]:\n\t\t\t\tt += 1\n\t\tif t % 2 == 1:\n\t\t\treturn 'No'\n\treturn 'Yes'\nprint(main())\n", "import sys\nstdout = sys.stdout\nrr = lambda : input().strip()\nrri = lambda : int(rr())\nrrm = lambda : list(map(int, rr().split()))\n\ndef solve(R, C, A, B):\n\tfor r in range(R):\n\t\tfor c in range(C):\n\t\t\tA[r][c] ^= B[r][c]\n\treturn all((sum(row) % 2 == 0 for row in A)) and all((sum(col) % 2 == 0 for col in zip(*A)))\n(R, C) = rrm()\nA = [rrm() for _ in range(R)]\nB = [rrm() for _ in range(R)]\nprint('Yes' if solve(R, C, A, B) else 'No')\n", "from sys import stdin\n\ndef solve():\n\t(N, M) = map(int, stdin.readline().split())\n\tA = []\n\tfor _ in range(N):\n\t\tA.append([int(k) for k in stdin.readline().split()])\n\tc_diff = [0] * N\n\tr_diff = [0] * M\n\tfor i in range(N):\n\t\tcol = [int(k) for k in stdin.readline().split()]\n\t\tfor j in range(M):\n\t\t\tif A[i][j] != col[j]:\n\t\t\t\tc_diff[i] += 1\n\t\t\t\tr_diff[j] += 1\n\ts = set(c_diff)\n\tans = 'Yes'\n\tfor x in s:\n\t\tif x % 2:\n\t\t\tans = 'No'\n\t\t\tbreak\n\tif ans == 'Yes':\n\t\ts = set(r_diff)\n\t\tfor x in s:\n\t\t\tif x % 2:\n\t\t\t\tans = 'No'\n\t\t\t\tbreak\n\tprint(ans)\nsolve()\n", "R = lambda : map(int, input().split())\n(n, m) = R()\n(r, c) = ([0] * n, [0] * m)\na = [list(R()) for i in range(n)]\nb = [list(R()) for i in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tr[i] += 1\n\t\t\tc[j] += 1\nfor i in c:\n\tif i % 2 != 0:\n\t\tprint('No')\n\t\texit()\nfor i in r:\n\tif i % 2 != 0:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "def Sort(sub_li):\n\tsub_li.sort(key=lambda x: x[1])\n\treturn sub_li\n\ndef Sort2(sub_li):\n\tsub_li.sort(key=lambda x: x[0])\n\treturn sub_li\np = input().rstrip().split(' ')\nl = []\nq = []\nw = []\nfor i in range(0, int(p[0])):\n\tu = input().rstrip().split(' ')\n\tl.append(u)\nfor i in range(0, int(p[0])):\n\tu = input().rstrip().split(' ')\n\tfor j in range(0, len(u)):\n\t\tif u[j] != l[i][j]:\n\t\t\tw.append([i, j])\nT = list(Sort(w))\nP = list(Sort2(w))\nU = 0\nif len(T) == 1:\n\tprint('No')\nelse:\n\tfor i in range(0, len(T) - 1, 2):\n\t\tif T[i][1] != T[i + 1][1]:\n\t\t\tU = 1\n\t\t\tbreak\n\tif U == 1:\n\t\tprint('No')\n\telse:\n\t\tfor i in range(0, len(P) - 1, 2):\n\t\t\tif P[i][0] != P[i + 1][0]:\n\t\t\t\tprint('No')\n\t\t\t\tbreak\n\t\telse:\n\t\t\tprint('Yes')\n", "(n, m) = list(map(int, input().split()))\nf = []\ns = []\nfor i in range(n):\n\tf.append(list(map(int, input().split())))\nfor i in range(n):\n\ts.append(list(map(int, input().split())))\nfor y in range(1, n):\n\tfor x in range(1, m):\n\t\tif f[y][x] != s[y][x]:\n\t\t\tf[y][x] ^= 1\n\t\t\tf[0][x] ^= 1\n\t\t\tf[y][0] ^= 1\n\t\t\tf[0][0] ^= 1\nfl = True\nfor y in range(n):\n\tfor x in range(m):\n\t\tif fl:\n\t\t\tif f[y][x] != s[y][x]:\n\t\t\t\tfl = False\nif fl:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "(n, m) = map(int, input().split())\narr = []\nfor i in range(n):\n\tarr.append(list(map(int, input().split())))\na = [0 for _ in range(m)]\nb = [0 for j in range(n)]\nfor i in range(n):\n\tbrr = list(map(int, input().split()))\n\tfor j in range(len(brr)):\n\t\tif arr[i][j] != brr[j]:\n\t\t\ta[j] += 1\n\t\t\tb[i] += 1\nf = 1\nfor i in range(len(a)):\n\tif a[i] % 2:\n\t\tf = 0\nfor j in range(len(b)):\n\tif b[j] % 2:\n\t\tf = 0\nprint(['No', 'Yes'][f])\n", "(n, m) = [int(i) for i in input().split()]\na = []\nb = []\nfor i in range(n):\n\tcor = [int(i) for i in input().split()]\n\ta.append(cor)\nfor i in range(n):\n\tcor = [int(i) for i in input().split()]\n\tb.append(cor)\nrow = [0] * n\ncol = [0] * m\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\trow[i] += 1\n\t\t\tcol[j] += 1\nispos = 0\nfor i in row:\n\tif i % 2 != 0:\n\t\tispos = 1\n\t\tbreak\nfor i in col:\n\tif i % 2 != 0:\n\t\tispos = 1\n\t\tbreak\nif ispos == 0:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "arr = input()\n(R, C) = [int(x) for x in arr.split(' ')]\nmat1 = [[0] * C for _ in range(R)]\nmat2 = [[0] * C for _ in range(R)]\nfor i in range(R):\n\tarr = input()\n\tarr = [int(x) for x in arr.split(' ')]\n\tfor j in range(C):\n\t\tmat1[i][j] = arr[j]\nfor i in range(R):\n\tarr = input()\n\tarr = [int(x) for x in arr.split(' ')]\n\tfor j in range(C):\n\t\tmat2[i][j] = arr[j]\nbulb = [0] * C\nfor i in range(R):\n\tfor j in range(C):\n\t\tif mat1[i][j] != mat2[i][j]:\n\t\t\tbulb[j] = bulb[j] ^ 1\n\tif sum(bulb) % 2 == 1:\n\t\tprint('NO')\n\t\tquit()\nif sum(bulb) == 0:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "(N, M) = list(map(int, input().split()))\nA = [[int(a) for a in input().split()] for i in range(N)]\nB = [[int(a) for a in input().split()] for i in range(N)]\nC = [[A[i][j] ^ B[i][j] for j in range(M)] for i in range(N)]\nfor i in range(N):\n\tif sum(C[i]) % 2:\n\t\tprint('No')\n\t\tbreak\n\tif i < N - 1:\n\t\tfor j in range(M):\n\t\t\tC[i + 1][j] ^= C[i][j]\nelse:\n\tif sum(C[N - 1]) == 0:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "import math\n\ndef na():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\treturn (n, b)\n\ndef nab():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tc = [int(x) for x in input().split()]\n\treturn (n, b, c)\n\ndef dv():\n\t(n, m) = map(int, input().split())\n\treturn (n, m)\n\ndef dva():\n\t(n, m) = map(int, input().split())\n\ta = [int(x) for x in input().split()]\n\tb = [int(x) for x in input().split()]\n\treturn (n, m, b)\n\ndef nm():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tm = int(input())\n\tc = [int(x) for x in input().split()]\n\treturn (n, b, m, c)\n\ndef dvs():\n\tn = int(input())\n\tm = int(input())\n\treturn (n, m)\n(n, m) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\tvr = [int(x) for x in input().split()]\n\ta.append(vr)\nfor i in range(n):\n\tvr = [int(x) for x in input().split()]\n\tb.append(vr)\nc = [[a[i][j] ^ b[i][j] for j in range(m)] for i in range(n)]\nfor i in range(n):\n\tif sum(c[i]) % 2:\n\t\tprint('No')\n\t\tbreak\n\tif i < n - 1:\n\t\tfor j in range(m):\n\t\t\tc[i + 1][j] ^= c[i][j]\nelse:\n\tif sum(c[n - 1]) == 0:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "temparr = input()\ntemparr = temparr.split()\nrow = int(temparr[0])\ncol = int(temparr[1])\nprevarr = []\nfor i in range(row):\n\ttemparr = input()\n\ttemparr = temparr.split()\n\tarr = []\n\tfor i in temparr:\n\t\tarr.append(int(i))\n\tprevarr.append(arr[:])\ncurarr = []\nfor i in range(row):\n\ttemparr = input()\n\ttemparr = temparr.split()\n\tarr = []\n\tfor i in temparr:\n\t\tarr.append(int(i))\n\tcurarr.append(arr[:])\nrowdiff = []\ncoldiff = []\nfor i in range(row):\n\tcount = 0\n\tfor j in range(col):\n\t\tif prevarr[i][j] != curarr[i][j]:\n\t\t\tcount += 1\n\trowdiff.append(count)\nfor i in range(col):\n\tcount = 0\n\tfor j in range(row):\n\t\tif prevarr[j][i] != curarr[j][i]:\n\t\t\tcount += 1\n\tcoldiff.append(count)\nflag = 0\nfor i in rowdiff:\n\tif i & 1 == 1:\n\t\tflag = 1\nfor i in coldiff:\n\tif i & 1 == 1:\n\t\tflag = 1\nif flag == 1:\n\tprint('No')\nelse:\n\tprint('Yes')\n", "(n, m) = list(map(int, input().split()))\nA = [[0 for i in range(m)] for i in range(n)]\nB = [[0 for i in range(m)] for i in range(n)]\nfor i in range(n):\n\trow = list(map(int, input().split()))\n\tfor j in range(m):\n\t\tA[i][j] = row[j]\nfor i in range(n):\n\trow = list(map(int, input().split()))\n\tfor j in range(m):\n\t\tB[i][j] = row[j]\n\ndef is_similar(A, B, n, m):\n\tC = [[0 for i in range(m)] for i in range(n)]\n\tcnt_err = 0\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif A[i][j] != B[i][j]:\n\t\t\t\tC[i][j] = 1\n\t\t\t\tcnt_err += 1\n\tfor i in range(n):\n\t\tcnt = 0\n\t\tfor j in range(m):\n\t\t\tcnt += C[i][j]\n\t\tif cnt % 2 == 1:\n\t\t\treturn print('No')\n\tfor j in range(m):\n\t\tcnt = 0\n\t\tfor i in range(n):\n\t\t\tcnt += C[i][j]\n\t\tif cnt % 2 == 1:\n\t\t\treturn print('No')\n\treturn print('Yes')\nis_similar(A, B, n, m)\n", "(n, m) = map(int, input().split())\na = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nb = []\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\n(f, s) = (-1, -1)\nfor i in range(n):\n\tcur = 0\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tcur += 1\n\tif cur % 2 == 1:\n\t\tprint('NO')\n\t\texit()\nfor j in range(m):\n\tcur = 0\n\tfor i in range(n):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tcur += 1\n\tif cur % 2 == 1:\n\t\tprint('NO')\n\t\texit()\nprint('YES')\n", "def main():\n\t(n, m) = map(int, input().split())\n\t(a, b) = ([], [])\n\tfor i in range(n):\n\t\ta.append(list(map(int, input().split())))\n\tfor i in range(n):\n\t\tb.append(list(map(int, input().split())))\n\tfor i in range(n - 1):\n\t\tfor j in range(m - 1):\n\t\t\tif a[i][j] != b[i][j]:\n\t\t\t\ta[i][j] = 1 - a[i][j]\n\t\t\t\ta[i + 1][j] = 1 - a[i + 1][j]\n\t\t\t\ta[i][j + 1] = 1 - a[i][j + 1]\n\t\t\t\ta[i + 1][j + 1] = 1 - a[i + 1][j + 1]\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif a[i][j] != b[i][j]:\n\t\t\t\tprint('No')\n\t\t\t\treturn\n\tprint('Yes')\n\ndef __starting_point():\n\tmain()\n__starting_point()\n", "from collections import defaultdict as dd\nimport math\nimport heapq\n\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n(n, m) = mi()\nA = []\nfor i in range(n):\n\tA.append(lm())\nB = []\nfor i in range(n):\n\tB.append(lm())\n\ndef check(A, B):\n\tfor i in range(n):\n\t\tcount = 0\n\t\tfor j in range(m):\n\t\t\tcount += abs(A[i][j] - B[i][j])\n\t\tif not count % 2 == 0:\n\t\t\treturn 'No'\n\tfor j in range(m):\n\t\tcount = 0\n\t\tfor i in range(n):\n\t\t\tcount += abs(A[i][j] - B[i][j])\n\t\tif not count % 2 == 0:\n\t\t\treturn 'No'\n\treturn 'Yes'\nprint(check(A, B))\n", "def main():\n\t(n, m) = list(map(int, input().split()))\n\tA = [[0] * m for _ in range(n)]\n\tB = [[0] * m for _ in range(n)]\n\tfor i in range(n):\n\t\tA[i] = list(map(int, input().split()))\n\tfor i in range(n):\n\t\tB[i] = list(map(int, input().split()))\n\tfor i in range(n):\n\t\tans = 0\n\t\tfor j in range(m):\n\t\t\tans = ans + A[i][j] - B[i][j]\n\t\tif ans % 2 != 0:\n\t\t\tprint('No')\n\t\t\treturn\n\tfor j in range(m):\n\t\tans = 0\n\t\tfor i in range(n):\n\t\t\tans = ans + A[i][j] - B[i][j]\n\t\tif ans % 2 != 0:\n\t\t\tprint('No')\n\t\t\treturn\n\tprint('Yes')\nmain()\n", "(N, M) = map(int, input().split())\nA = []\nB = []\nfor i in range(N):\n\tA.append(list(map(int, input().split())))\nfor i in range(N):\n\tB.append(list(map(int, input().split())))\nC = []\nfor i in range(N):\n\ttmp = []\n\tfor j in range(M):\n\t\ta = A[i][j]\n\t\tb = B[i][j]\n\t\ttmp.append(a ^ b)\n\tC.append(tmp)\nfor i in range(N - 1):\n\tfor j in range(M - 1):\n\t\tif C[i][j] == 0:\n\t\t\tcontinue\n\t\telse:\n\t\t\tC[i][j] = 0\n\t\t\tC[i + 1][j] = 1 if C[i + 1][j] == 0 else 0\n\t\t\tC[i][j + 1] = 1 if C[i][j + 1] == 0 else 0\n\t\t\tC[i + 1][j + 1] = 1 if C[i + 1][j + 1] == 0 else 0\nfor i in range(N):\n\tfor j in range(M):\n\t\tc = C[i][j]\n\t\tif c == 1:\n\t\t\tprint('No')\n\t\t\texit()\nprint('Yes')\n", "(a, b) = map(int, input().split())\nA = []\nB = [] * b\nfor i in range(a):\n\tA.append(list(map(int, input().split())))\n\tif i == 0:\n\t\tfor j in range(b):\n\t\t\tB.append([A[i][j]])\n\telse:\n\t\tfor j in range(b):\n\t\t\tB[j].append(A[i][j])\nC = []\nD = [] * b\nfor i in range(a):\n\tC.append(list(map(int, input().split())))\n\tif i == 0:\n\t\tfor j in range(b):\n\t\t\tD.append([C[i][j]])\n\telse:\n\t\tfor j in range(b):\n\t\t\tD[j].append(C[i][j])\nk = True\nfor i in range(a):\n\tif sum(A[i]) % 2 != sum(C[i]) % 2:\n\t\tk = False\nfor i in range(b):\n\tif sum(B[i]) % 2 != sum(D[i]) % 2:\n\t\tk = False\nq = 0\nw = 0\nfor i in range(a):\n\tq += sum(A[i])\n\tw += sum(C[i])\nif q % 2 != w % 2:\n\tk = False\nif k == True:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "import sys\nfrom bisect import bisect_left, bisect_right\nfrom collections import deque\ninf = float('inf')\nmod = 1000000007\n\ndef binary(number):\n\tresult = 0\n\twhile number:\n\t\tresult = result + 1\n\t\tnumber = number & number - 1\n\treturn result\n\ndef get_array():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef get_ints():\n\treturn map(int, sys.stdin.readline().split())\ntmp = get_array()\n(n, m) = (tmp[0], tmp[1])\nA = []\nB = []\nfor i in range(n):\n\tA.append(get_array())\nfor i in range(n):\n\tB.append(get_array())\ndelta = [[0] * m for i in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tdelta[i][j] = 1\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif delta[i][j] == 1:\n\t\t\tfor e in [(i, j), (i + 1, j + 1), (i, j + 1), (i + 1, j)]:\n\t\t\t\t(i_, j_) = e\n\t\t\t\tdelta[i_][j_] = 0 if delta[i_][j_] == 1 else 1\nif sum([sum(x) for x in delta]):\n\tprint('NO')\nelse:\n\tprint('YES')\n", "import sys\nline = sys.stdin.readline().strip().split()\nn = int(line[0])\nm = int(line[1])\nA = [0] * n\nB = [0] * n\nfor i in range(0, n):\n\tA[i] = sys.stdin.readline().strip().split()\nfor i in range(0, n):\n\tB[i] = sys.stdin.readline().strip().split()\nv = True\nfor i in range(0, n):\n\tx = 0\n\tfor j in range(0, m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tx = x + 1\n\tif x % 2 == 1:\n\t\tv = False\nfor j in range(0, m):\n\tx = 0\n\tfor i in range(0, n):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tx = x + 1\n\tif x % 2 == 1:\n\t\tv = False\nif v == True:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "(r, c) = list(map(int, input().split()))\nm1 = [list(map(int, input().split())) for i in range(r)]\nm2 = [list(map(int, input().split())) for i in range(r)]\nwiersze1 = []\nwiersze2 = []\nkolumny1 = []\nkolumny2 = []\nfor i in range(r):\n\twiersze1.append(sum(m1[i]))\n\twiersze2.append(sum(m2[i]))\nm1tr = [[m1[a][b] for a in range(r)] for b in range(c)]\nm2tr = [[m2[a][b] for a in range(r)] for b in range(c)]\nfor i in range(c):\n\tkolumny1.append(sum(m1tr[i]))\n\tkolumny2.append(sum(m2tr[i]))\nimport sys\nfor i in range(c):\n\tif (kolumny1[i] - kolumny2[i]) % 2 != 0:\n\t\tprint('NO')\n\t\tsys.exit(0)\nfor i in range(r):\n\tif (wiersze1[i] - wiersze2[i]) % 2 != 0:\n\t\tprint('NO')\n\t\tsys.exit(0)\nprint('YES')\n", "(n, m) = map(int, input().split())\nA = []\nB = []\nfor i in range(n):\n\tA.append(list(map(int, input().split())))\nfor i in range(n):\n\tB.append(list(map(int, input().split())))\nv = True\nfor r in range(n - 1):\n\tfor c in range(m - 1):\n\t\tif A[r][c] != B[r][c]:\n\t\t\tA[r][c] ^= 1\n\t\t\tA[r + 1][c] ^= 1\n\t\t\tA[r][c + 1] ^= 1\n\t\t\tA[r + 1][c + 1] ^= 1\n\tif A[r][m - 1] != B[r][m - 1]:\n\t\tv = False\nif A[n - 1] != B[n - 1]:\n\tv = False\nif v == True:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\nmat1 = []\nfor i in range(n):\n\tmat1.append([int(i) for i in input().split()])\nmat2 = []\nfor i in range(n):\n\tmat2.append([int(i) for i in input().split()])\npar1 = [0] * n\npar2 = [0] * n\nfor i in range(n):\n\tp = 0\n\tp1 = 0\n\tfor j in range(m):\n\t\tp ^= mat1[i][j]\n\t\tp1 ^= mat2[i][j]\n\tpar2[i] = p1\n\tpar1[i] = p\nf = 1\nif par1 != par2:\n\tf = 0\npar1 = [0] * m\npar2 = [0] * m\nfor j in range(m):\n\tfor i in range(n):\n\t\tp ^= mat1[i][j]\n\t\tp1 ^= mat2[i][j]\n\tpar2[j] = p1\n\tpar1[j] = p\nif par1 != par2:\n\tf = 0\nprint('Yes' if f else 'No')\n", "(n, m) = map(int, input().split())\nA = [0] * n\nfor i in range(n):\n\tA[i] = list(map(int, input().split()))\nB = [0] * n\nfor i in range(n):\n\tB[i] = list(map(int, input().split()))\nArows = [sum(A[i]) % 2 for i in range(n)]\nAcols = [sum((A[j][i] for j in range(n))) % 2 for i in range(m)]\nBrows = [sum(B[i]) % 2 for i in range(n)]\nBcols = [sum((B[j][i] for j in range(n))) % 2 for i in range(m)]\nif Arows == Brows and Acols == Bcols:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = [int(item) for item in input().split()]\na = []\nb = []\nfor _ in range(n):\n\ta.append([int(item) for item in input().split()])\nfor _ in range(n):\n\tb.append([int(item) for item in input().split()])\nok = True\nfor i in range(n):\n\tc = 0\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tc += 1\n\tif c & 1:\n\t\tok &= False\n\t\tbreak\nfor j in range(m):\n\tc = 0\n\tfor i in range(n):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tc += 1\n\tif c & 1:\n\t\tok &= False\n\t\tbreak\nprint('Yes' if ok else 'No')\n", "(n, m) = map(int, input().split())\nmat1 = []\nmat2 = []\nsum1 = 0\nsum2 = 0\nfor i in range(n):\n\ta = list(map(int, input().split()))\n\tmat1.append(a)\nfor i in range(n):\n\ta = list(map(int, input().split()))\n\tmat2.append(a)\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif mat1[i][j] != mat2[i][j]:\n\t\t\tmat1[i][j] = 1 - mat1[i][j]\n\t\t\tif j + 1 < m:\n\t\t\t\tmat1[i][j + 1] = 1 - mat1[i][j + 1]\n\t\t\tif i + 1 < n:\n\t\t\t\tmat1[i + 1][j] = 1 - mat1[i + 1][j]\n\t\t\tif i + 1 < n and j + 1 < m:\n\t\t\t\tmat1[i + 1][j + 1] = 1 - mat1[i + 1][j + 1]\nif mat1 == mat2:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "from sys import stdin\ninput = stdin.readline\n\ndef solve(n, m, a, b):\n\tx = [[False] * m for _ in range(n)]\n\tcnt = 0\n\tfor r in range(n):\n\t\tfor c in range(m):\n\t\t\tif a[r][c] != b[r][c]:\n\t\t\t\tx[r][c] = True\n\t\t\t\tcnt += 1\n\tfor r in x:\n\t\tif r.count(True) % 2 > 0:\n\t\t\tprint('NO')\n\t\t\treturn\n\tfor c in range(m):\n\t\tcnt = 0\n\t\tfor r in range(n):\n\t\t\tcnt += x[r][c]\n\t\tif cnt % 2 > 0:\n\t\t\tprint('NO')\n\t\t\treturn\n\tprint('YES')\n(n, m) = [int(x) for x in input().split()]\na = [[int(x) for x in input().split()] for _ in range(n)]\nb = [[int(x) for x in input().split()] for _ in range(n)]\nsolve(n, m, a, b)\n", "SS = input()\nSS = SS.strip().split(' ')\n(N, M) = (int(SS[0]), int(SS[1]))\n(mat1, mat2) = ([], [])\nfor i in range(N):\n\tSSS = input()\n\tline = SSS.strip().split(' ')\n\tline = list(map(int, line))\n\tmat1.append(line)\nfor i in range(N):\n\tSSS = input()\n\tline = SSS.strip().split(' ')\n\tline = list(map(int, line))\n\tmat2.append(line)\nfor i in range(N):\n\tfor j in range(M):\n\t\tmat1[i][j] = mat1[i][j] ^ mat2[i][j]\nans = 'Yes'\nfor i in range(N):\n\tif sum(mat1[i]) % 2 == 1:\n\t\tans = 'No'\nfor j in range(M):\n\tsum1 = 0\n\tfor i in range(N):\n\t\tsum1 += mat1[i][j]\n\tif sum1 % 2 == 1:\n\t\tans = 'No'\nprint(ans)\n", "def main():\n\t(n, m) = map(int, input().split())\n\tarr = [list(map(int, input().split())) for _ in range(n)]\n\tkek = [list(map(int, input().split())) for _ in range(n)]\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tarr[i][j] ^= kek[i][j]\n\tf = 1\n\tfor i in range(n):\n\t\ts = 0\n\t\tfor j in range(m):\n\t\t\ts += arr[i][j]\n\t\tif s & 1:\n\t\t\tf = 0\n\t\t\tbreak\n\tfor i in range(m):\n\t\ts = 0\n\t\tfor j in range(n):\n\t\t\ts += arr[j][i]\n\t\tif s & 1:\n\t\t\tf = 0\n\t\t\tbreak\n\tif f:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n\treturn 0\nmain()\n", "(N, M) = map(int, input().split())\nA = []\nB = []\nfor i in range(N):\n\tA.append(list(map(int, input().split())))\nfor i in range(N):\n\tB.append(list(map(int, input().split())))\na_row = 0\nb_row = 0\nfor i in range(N):\n\ta_row = sum(A[i])\n\tb_row = sum(B[i])\n\tif a_row % 2 == b_row % 2:\n\t\ta_row = 0\n\t\tb_row = 0\n\t\tcontinue\n\telse:\n\t\tprint('No')\n\t\texit()\na_column = 0\nb_column = 0\nfor j in range(M):\n\tfor i in range(N):\n\t\ta_column += A[i][j]\n\t\tb_column += B[i][j]\n\tif a_column % 2 == b_column % 2:\n\t\ta_column = 0\n\t\tb_column = 0\n\t\tcontinue\n\telse:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "(n, m) = map(int, input().split())\nA = [[int(x) for x in input().split()] for _ in range(n)]\nB = [[int(x) for x in input().split()] for _ in range(n)]\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tA[i][j] = 1 - A[i][j]\n\t\t\tA[i + 1][j] = 1 - A[i + 1][j]\n\t\t\tA[i][j + 1] = 1 - A[i][j + 1]\n\t\t\tA[i + 1][j + 1] = 1 - A[i + 1][j + 1]\nif A == B:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "mn = input().split()\nn = int(mn[0])\nm = int(mn[1])\nf = 0\nA = []\nB = []\n\ndef del2(ls):\n\tif ls.count('1') % 2 == 0:\n\t\treturn 1\n\telse:\n\t\treturn 0\nfor i in range(n):\n\tA.append(input().split())\nfor i in range(n):\n\tB.append(input().split())\nfor i in range(0, n):\n\tif del2(A[i]) != del2(B[i]):\n\t\tf += 1\n\t\tbreak\nif f > 0:\n\tprint('No')\nelse:\n\tfor j in range(m):\n\t\tst = []\n\t\tkz = []\n\t\tfor i in range(n):\n\t\t\tst.append(A[i][j])\n\t\t\tkz.append(B[i][j])\n\t\tif del2(st) != del2(kz):\n\t\t\tf += 1\n\t\t\tbreak\n\tif f > 0:\n\t\tprint('No')\n\telse:\n\t\tprint('Yes')\n", "from sys import stdin\ninp = stdin.readline\n(n, m) = map(int, inp().split())\n(a, b) = ([[int(i) for i in inp().split()] for _ in range(n)], [[int(i) for i in inp().split()] for _ in range(n)])\na = [[a[i][j] ^ b[i][j] for j in range(m)] for i in range(n)]\nif all((sum(i) % 2 == 0 for i in a)) and all((sum((i[j] for i in a)) % 2 == 0 for j in range(m))):\n\tprint('YES')\n\texit()\nprint('NO')\n", "(n, m) = map(int, input().split())\nA = []\nB = []\nfor i in range(n):\n\tA.append([int(x) for x in input().split()])\nfor i in range(n):\n\tB.append([int(x) for x in input().split()])\nfor i in range(n):\n\tfor j in range(m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tstate = 0\n\t\t\tmi = mj = 0\n\t\t\tfor mi in range(i + 1, n):\n\t\t\t\tif A[mi][j] != B[mi][j]:\n\t\t\t\t\tA[mi][j] = B[mi][j]\n\t\t\t\t\tstate += 1\n\t\t\t\t\tbreak\n\t\t\tfor mj in range(j + 1, m):\n\t\t\t\tif A[i][mj] != B[i][mj]:\n\t\t\t\t\tA[i][mj] = B[i][mj]\n\t\t\t\t\tstate += 1\n\t\t\t\t\tbreak\n\t\t\tif A[mi][mj]:\n\t\t\t\tA[mi][mj] = 0\n\t\t\telse:\n\t\t\t\tA[mi][mj] = 1\n\t\t\tif state != 2:\n\t\t\t\tprint('No')\n\t\t\t\texit()\nprint('Yes')\n", "import sys\n\ndef get_array():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef get_ints():\n\treturn map(int, sys.stdin.readline().split())\n\ndef input():\n\treturn sys.stdin.readline()\n\ndef main():\n\tglobal n, m\n\t(n, m) = get_ints()\n\tglobal A, B\n\tA = [[0] * m for _ in range(n)]\n\tB = [[0] * m for _ in range(n)]\n\tfor i in range(n):\n\t\tA[i] = get_array()\n\tfor i in range(n):\n\t\tB[i] = get_array()\n\tC = [[0] * m for _ in range(n)]\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif A[i][j] == B[i][j]:\n\t\t\t\tC[i][j] == 0\n\t\t\telse:\n\t\t\t\tC[i][j] = 1\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif C[i][j] == 1:\n\t\t\t\tt1 = i + 1\n\t\t\t\tt2 = j + 1\n\t\t\t\twhile t1 < n and C[t1][j] == 0:\n\t\t\t\t\tt1 += 1\n\t\t\t\twhile t2 < m and C[i][t2] == 0:\n\t\t\t\t\tt2 += 1\n\t\t\t\tif t1 == n or t2 == m:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\treturn\n\t\t\t\tC[i][t2] = 0\n\t\t\t\tC[t1][j] = 0\n\t\t\t\tC[t1][t2] = 1 - C[t1][t2]\n\tprint('YES')\nmain()\n", "(R, C) = map(int, input().split())\n(r, c) = ([0] * R, [0] * C)\na = [input().split() for i in r]\nb = [input().split() for i in r]\nfor i in range(C):\n\tfor j in range(R):\n\t\tr[j] += a[j][i] != b[j][i]\n\t\tc[i] += a[j][i] != b[j][i]\nfor C in c:\n\tif C % 2:\n\t\tprint('No')\n\t\texit()\nfor R in r:\n\tif R % 2:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "from sys import stdin\ninput = stdin.readline\n\ndef check_parity(n):\n\t(a, b) = (0, 0)\n\tfor i in range(n):\n\t\tline = input()\n\t\ta ^= int(line.replace(' ', ''), 2)\n\t\tb = b * 2 + line.count('1') % 2\n\treturn (a, b)\n(n, m) = map(int, input().split())\nif check_parity(n) == check_parity(n):\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(n, m) = map(int, input().split())\na = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nb = []\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nflag = True\nfor i in range(n):\n\thor = 0\n\tfor l in range(m):\n\t\tif a[i][l] != b[i][l]:\n\t\t\thor += 1\n\tif hor % 2 == 1:\n\t\tflag = False\n\t\tbreak\nfor l in range(m):\n\thor = 0\n\tfor i in range(n):\n\t\tif a[i][l] != b[i][l]:\n\t\t\thor += 1\n\tif hor % 2 == 1:\n\t\tflag = False\n\t\tbreak\nif flag:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "import sys\ninput = sys.stdin.readline\n(n, m) = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(n)]\nb = [list(map(int, input().split())) for _ in range(n)]\ng = 0\n(total1, total2) = (0, 0)\nfor i in range(n):\n\ttotal1 += sum(a[i])\n\ttotal2 += sum(b[i])\n\tif sum(a[i]) & 1 != sum(b[i]) & 1:\n\t\tg = 1\n\t\tbreak\nfor i in range(m):\n\t(s1, s2) = (0, 0)\n\tfor j in range(n):\n\t\ts1 += a[j][i]\n\t\ts2 += b[j][i]\n\ttotal1 += s1\n\ttotal2 += s2\n\tif s2 & 1 != s1 & 1:\n\t\tg = 1\n\t\tbreak\nif total1 & 1 != total2 & 1:\n\tg = 1\nif g:\n\tprint('No')\nelse:\n\tprint('Yes')\n", "(n, m) = [int(i) for i in input().split()]\na = []\nb = []\nfor slakfj in range(n):\n\ta.append([int(i) for i in input().split()])\nfor slakfj in range(n):\n\tb.append([int(i) for i in input().split()])\nc = a.copy()\nfor i in range(n):\n\tfor j in range(m):\n\t\tc[i][j] = c[i][j] ^ b[i][j]\nflag = 1\nfor i in c:\n\ts = sum(i)\n\tif s % 2 != 0:\n\t\tprint('NO')\n\t\tflag = 0\n\t\tbreak\nif flag == 1:\n\tfor j in range(m):\n\t\ts = 0\n\t\tfor i in range(n):\n\t\t\ts += c[i][j]\n\t\tif s % 2 != 0:\n\t\t\tprint('NO')\n\t\t\tflag = 0\n\t\t\tbreak\nif flag:\n\tprint('YES')\n", "(n, m) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nc = [[0 for _ in range(m)] for _ in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] == b[i][j]:\n\t\t\tc[i][j] = 0\n\t\telse:\n\t\t\tc[i][j] = 1\nrow = [0 for j in range(m)]\ncol = [0 for i in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\trow[j] += c[i][j]\n\t\tcol[i] += c[i][j]\nfor i in row:\n\tif i % 2 == 1:\n\t\tprint('No')\n\t\texit()\nfor i in col:\n\tif i % 2 == 1:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nfrom collections import *\nfrom operator import itemgetter, attrgetter\nimport bisect\nimport math\nimport heapq as hq\n(n, m) = map(int, input().split())\nfirst = []\nsecond = []\nfor i in range(n):\n\tfirst.append(list(map(int, input().split())))\nfor i in range(n):\n\tsecond.append(list(map(int, input().split())))\ntemp = [[0 for i in range(m)] for j in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif first[i][j] != second[i][j]:\n\t\t\ttemp[i][j] = 1\nvert = [0 for i in range(n)]\nhor = [0 for i in range(m)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif temp[i][j] == 1:\n\t\t\tvert[i] += 1\n\t\t\thor[j] += 1\nf = 0\nfor i in range(n):\n\tif vert[i] % 2:\n\t\tprint('No')\n\t\tbreak\nelse:\n\tfor i in range(m):\n\t\tif hor[i] % 2:\n\t\t\tprint('No')\n\t\t\tbreak\n\telse:\n\t\tprint('Yes')\n", "(n, m) = (int(x) for x in input().split())\nA = []\nB = []\nfor i in range(n):\n\tline = [int(x) for x in input().split()]\n\tA.append(line)\nfor i in range(n):\n\tline = [int(x) for x in input().split()]\n\tB.append(line)\nfor i in range(1, n):\n\tfor j in range(1, m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tA[i][j] = 1 - A[i][j]\n\t\t\tA[0][j] = 1 - A[0][j]\n\t\t\tA[i][0] = 1 - A[i][0]\n\t\t\tA[0][0] = 1 - A[0][0]\nrowA = A[0]\nrowB = B[0]\ncolA = [A[i][0] for i in range(n)]\ncolB = [B[i][0] for i in range(n)]\nans = rowA == rowB and colA == colB\nif ans:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "(n, m) = map(int, input().split())\nar = [0 for i in range(n)]\nbr = [0 for i in range(n)]\nac = [0 for i in range(m)]\nbc = [0 for i in range(m)]\nfor i in range(n):\n\tline = list(map(int, input().split()))\n\tfor j in range(m):\n\t\tar[i] ^= line[j]\n\t\tac[j] ^= line[j]\nfor i in range(n):\n\tline = list(map(int, input().split()))\n\tfor j in range(m):\n\t\tbr[i] ^= line[j]\n\t\tbc[j] ^= line[j]\nif ar != br:\n\tprint('No')\nelif ac != bc:\n\tprint('No')\nelse:\n\tprint('Yes')\n", "from sys import stdin\n(n, m) = map(int, stdin.readline().strip().split())\ns = [list(map(int, stdin.readline().strip().split())) for i in range(n)]\ns1 = [list(map(int, stdin.readline().strip().split())) for i in range(n)]\ncol = [0 for i in range(m)]\nrow = [0 for i in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif s[i][j] != s1[i][j]:\n\t\t\tcol[j] += 1\n\t\t\trow[i] += 1\nflag = 'Yes'\nfor i in range(m):\n\tif col[i] % 2 != 0:\n\t\tflag = 'No'\nfor i in range(n):\n\tif row[i] % 2 != 0:\n\t\tflag = 'No'\nprint(flag)\n", "(n, m) = map(int, input().split())\na = [[int(x) for x in input().split()] for i in range(n)]\nb = [[int(x) for x in input().split()] for i in range(n)]\nc = [[a[i][j] ^ b[i][j] for j in range(m)] for i in range(n)]\nfor i in range(n - 1):\n\tj = 0\n\tfor j in range(m - 1):\n\t\tif c[i][j] == 1:\n\t\t\tfor k in range(j + 1, m):\n\t\t\t\tif c[i][k] == 1:\n\t\t\t\t\tc[i][j] ^= 1\n\t\t\t\t\tc[i][k] ^= 1\n\t\t\t\t\tc[i + 1][j] ^= 1\n\t\t\t\t\tc[i + 1][k] ^= 1\n\t\t\t\t\tbreak\nif sum(map(sum, c)) == 0:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "from collections import defaultdict\n(n, m) = list(map(int, input().split()))\nm1 = [list(input().split()) for _ in range(n)]\nm2 = [list(input().split()) for _ in range(n)]\nrow_change = defaultdict(int)\ncol_change = defaultdict(int)\ncount_change = 0\nfor x in range(n):\n\tfor y in range(m):\n\t\tif m1[x][y] != m2[x][y]:\n\t\t\tcount_change += 1\n\t\t\trow_change[x] += 1\n\t\t\tcol_change[y] += 1\nif count_change % 2:\n\tprint('No')\n\treturn\nif 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()))):\n\tprint('Yes')\n\treturn\nprint('No')\n", "def mp():\n\treturn map(int, input().split())\n(n, m) = mp()\na = [list(mp()) for i in range(n)]\nb = [list(mp()) for i in range(n)]\nc = [[0] * m for i in range(n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] == b[i][j]:\n\t\t\tc[i][j] = 1\nfor i in range(n):\n\tfor j in range(m):\n\t\tif c[i][j] == 1:\n\t\t\tcontinue\n\t\tk = h = -1\n\t\tfor q in range(i + 1, n):\n\t\t\tif c[q][j] == 0:\n\t\t\t\tk = q\n\t\tfor q in range(j + 1, m):\n\t\t\tif c[i][q] == 0:\n\t\t\t\th = q\n\t\tc[i][j] = 1 - c[i][j]\n\t\tc[k][j] = 1 - c[k][j]\n\t\tc[i][h] = 1 - c[i][h]\n\t\tc[k][h] = 1 - c[k][h]\nfail = 0\nfor i in range(n):\n\tfor j in range(m):\n\t\tif c[i][j] == 0:\n\t\t\tfail = 1\n\t\t\tbreak\n\tif fail:\n\t\tprint('No')\n\t\tbreak\nelse:\n\tprint('Yes')\n", "from collections import defaultdict as DD\nfrom bisect import bisect_left as BL\nfrom bisect import bisect_right as BR\nfrom itertools import combinations as IC\nfrom itertools import permutations as IP\nfrom random import randint as RI\nimport sys\nMOD = pow(10, 9) + 7\n\ndef IN(f=0):\n\tif f == 0:\n\t\treturn [int(i) for i in sys.stdin.readline().split()]\n\telse:\n\t\treturn int(sys.stdin.readline())\n(n, m) = IN()\na = []\nb = []\nc = []\nfor i in range(n):\n\trr = IN()\n\ta.append(rr)\n\tc.append(rr)\nfor i in range(n):\n\tb.append(IN())\nfr = [0 for i in range(n)]\nfc = [0 for i in range(m)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif c[i][j] == b[i][j]:\n\t\t\tc[i][j] = 0\n\t\telse:\n\t\t\tc[i][j] = 1\n\t\t\tfr[i] += 1\n\t\t\tfc[j] += 1\nf = 'Yes'\nfor i in fr:\n\tif i % 2 != 0:\n\t\tf = 'No'\n\t\tbreak\nfor i in fc:\n\tif i % 2 != 0:\n\t\tf = 'No'\n\t\tbreak\nprint(f)\n", "def invert(el):\n\tif el == 0:\n\t\treturn 1\n\telse:\n\t\treturn 0\n(n, m) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\tlis = list(map(int, input().split()))\n\ta.append(lis)\nfor i in range(n):\n\tlis = list(map(int, input().split()))\n\tb.append(lis)\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif a[i][j] != b[i][j]:\n\t\t\ta[i][j] = invert(a[i][j])\n\t\t\ta[i + 1][j] = invert(a[i + 1][j])\n\t\t\ta[i][j + 1] = invert(a[i][j + 1])\n\t\t\ta[i + 1][j + 1] = invert(a[i + 1][j + 1])\nok = True\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tok = False\n\t\t\tbreak\nif ok:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "class Solution:\n\n\tdef __solve__(self):\n\t\tn = self[0]\n\t\tm = self[1]\n\t\tleft = self[2]\n\t\tright = self[3]\n\t\trow = []\n\t\tcolumn = []\n\t\tfor i in range(n):\n\t\t\trow.append(0)\n\t\tfor i in range(m):\n\t\t\tcolumn.append(0)\n\t\tfor i in range(n * m):\n\t\t\th = int(i / m)\n\t\t\tl = i % m\n\t\t\trow[h] ^= left[0][i]\n\t\t\tcolumn[l] ^= left[0][i]\n\t\tfor i in range(n * m):\n\t\t\th = int(i / m)\n\t\t\tl = i % m\n\t\t\trow[h] ^= right[0][i]\n\t\t\tcolumn[l] ^= right[0][i]\n\t\tfor i in range(n):\n\t\t\tif row[i] != 0:\n\t\t\t\tprint('No')\n\t\t\t\treturn\n\t\tfor i in range(m):\n\t\t\tif column[i] != 0:\n\t\t\t\tprint('No')\n\t\t\t\treturn\n\t\tprint('Yes')\n\t\treturn\n\n\tdef __read__():\n\t\tdata = []\n\t\tfirst = input().split()\n\t\tn = int(first[0])\n\t\tm = int(first[1])\n\t\tdata.append(n)\n\t\tdata.append(m)\n\t\tleft = [[]] * n\n\t\tright = [[]] * n\n\t\tfor i in range(n):\n\t\t\tmatix = input().split()\n\t\t\tfor j in range(m):\n\t\t\t\tleft[i].append(int(matix[j]))\n\t\tfor i in range(n):\n\t\t\tmatix = input().split()\n\t\t\tfor j in range(m):\n\t\t\t\tright[i].append(int(matix[j]))\n\t\tdata.append(left)\n\t\tdata.append(right)\n\t\treturn data\nSolution.__solve__(Solution.__read__())\n", "(n, m) = map(int, input().split())\nA = []\nB = []\nfor _ in range(n):\n\trow = list(map(int, input().split()))\n\tA.append(row)\nfor _ in range(n):\n\trow = list(map(int, input().split()))\n\tB.append(row)\nflag = 0\nfor i in range(n):\n\tre = 0\n\tfor j in range(m):\n\t\tif A[i][j] != B[i][j]:\n\t\t\tre += 1\n\tif re % 2 == 1:\n\t\tflag = 1\n\t\tbreak\nif flag == 1:\n\tprint('No')\nelse:\n\tfor i in range(m):\n\t\tce = 0\n\t\tfor j in range(n):\n\t\t\tif A[j][i] != B[j][i]:\n\t\t\t\tce += 1\n\t\tif ce % 2 == 1:\n\t\t\tflag = 1\n\t\t\tbreak\n\tif flag == 1:\n\t\tprint('No')\n\telse:\n\t\tprint('Yes')\n", "(n, h) = [int(x) for x in input().strip().split(' ')]\nmax1 = []\nmax2 = []\nfor _ in range(n):\n\tmax1.append([int(x) for x in input().strip().split(' ')])\nfor _ in range(n):\n\tmax2.append([int(x) for x in input().strip().split(' ')])\nfor i in range(n):\n\tcolumn_mis = 0\n\tfor j in range(h):\n\t\tif max1[i][j] != max2[i][j]:\n\t\t\tcolumn_mis += 1\n\tif column_mis % 2:\n\t\tprint('No')\n\t\texit()\nfor i in range(h):\n\trow_mis = 0\n\tfor j in range(n):\n\t\tif max1[j][i] != max2[j][i]:\n\t\t\trow_mis += 1\n\tif row_mis % 2:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "import sys, math, queue\nsys.setrecursionlimit(1000000)\n(n, m) = map(int, input().split())\na = []\nb = []\nfor i in range(n):\n\ta.append(list(map(int, input().split())))\nfor i in range(n):\n\tb.append(list(map(int, input().split())))\nfor i in range(n):\n\tx = 0\n\ty = 0\n\tfor j in range(m):\n\t\tx += a[i][j]\n\tfor j in range(m):\n\t\ty += b[i][j]\n\tif x % 2 != y % 2:\n\t\tprint('No')\n\t\texit()\nfor j in range(m):\n\tx = 0\n\ty = 0\n\tfor i in range(n):\n\t\tx += a[i][j]\n\tfor i in range(n):\n\t\ty += b[i][j]\n\tif x % 2 != y % 2:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "__author__ = 'r0levrai'\nfrom math import *\nfrom operator import itemgetter\n(n, m) = map(int, input().split(' '))\nA = [list(map(int, input().split(' '))) for i_line in range(n)]\nB = [list(map(int, input().split(' '))) for i_line in range(n)]\nnumbers_to_revert_in_line = [0 for i in range(n)]\nnumbers_to_revert_in_column = [0 for j in range(m)]\nfor i in range(n):\n\tnumbers_to_revert_in_line[i] = sum([A[i][j] != B[i][j] for j in range(m)])\nfor j in range(m):\n\tnumbers_to_revert_in_column[j] = sum([A[i][j] != B[i][j] for i in range(n)])\ncan_transform = True\nfor nr in numbers_to_revert_in_line + numbers_to_revert_in_column:\n\tif nr % 2 != 0:\n\t\tcan_transform = False\nprint('yes' if can_transform else 'no')\n", "def rowsum(grid, i):\n\treturn sum(grid[i])\n\ndef colsum(grid, i):\n\treturn sum([grid[j][i] for j in range(len(grid))])\n\ndef compat(grid1, grid2, r, c):\n\tfor i in range(r):\n\t\tif (rowsum(grid1, i) - rowsum(grid2, i)) % 2 != 0:\n\t\t\treturn 'No'\n\tfor i in range(c):\n\t\tif (colsum(grid1, i) - colsum(grid2, i)) % 2 != 0:\n\t\t\treturn 'No'\n\treturn 'Yes'\n(r, c) = [int(x) for x in input().split()]\ngrid1 = []\nfor _ in range(r):\n\tgrid1.append([int(x) for x in input().split()])\ngrid2 = []\nfor _ in range(r):\n\tgrid2.append([int(x) for x in input().split()])\nprint(compat(grid1, grid2, r, c))\n", "(n, m) = map(int, input().split())\nf = []\ns = []\nfor i in range(n):\n\tf.append(list(map(int, input().split())))\nfor i in range(n):\n\ts.append(list(map(int, input().split())))\nstroka = [0] * n\nstolb = [0] * m\nfor i in range(n):\n\tfor j in range(m):\n\t\tif f[i][j] != s[i][j]:\n\t\t\tstroka[i] += 1\n\t\t\tstolb[j] += 1\nfor i in range(n):\n\tif stroka[i] % 2:\n\t\tprint('NO')\n\t\texit(0)\nfor i in range(m):\n\tif stolb[i] % 2:\n\t\tprint('NO')\n\t\texit(0)\nprint('YES')\n", "import atexit\nimport io\nimport sys\n_I_B = sys.stdin.read().splitlines()\ninput = iter(_I_B).__next__\n_O_B = io.StringIO()\nsys.stdout = _O_B\n\n@atexit.register\ndef write():\n\tsys.__stdout__.write(_O_B.getvalue())\n(r, c) = map(int, input().split())\nm1 = []\nm2 = []\nfor i in range(r):\n\tm1.append(list(map(int, input().split())))\nfor i in range(r):\n\tm2.append(list(map(int, input().split())))\nsdr = []\nsdc = []\nfor j in range(c):\n\tsdc.append([0] * r)\nfor i in range(r):\n\tsdr.append([])\n\tfor j in range(c):\n\t\tx = m1[i][j] ^ m2[i][j]\n\t\tsdr[-1].append(x)\n\t\tsdc[j][i] = x\nfor i in range(r):\n\tif sdr[i].count(1) & 1:\n\t\tprint('NO')\n\t\texit(0)\nfor i in range(c):\n\tif sdc[i].count(1) & 1:\n\t\tprint('NO')\n\t\texit(0)\nprint('YES')\n", "(n, m) = map(int, input().strip().split())\narr = []\nfor i in range(n):\n\ta = list(map(int, input().strip().split()))\n\tarr.append(a)\nbrr = []\nfor i in range(n):\n\ta = list(map(int, input().strip().split()))\n\tbrr.append(a)\nfor i in range(n):\n\tfor j in range(m):\n\t\tif arr[i][j] != brr[i][j]:\n\t\t\tfl = 1\n\t\t\tif i == n - 1 or j == m - 1:\n\t\t\t\tcontinue\n\t\t\tarr[i][j] = 1 - arr[i][j]\n\t\t\tarr[i + 1][j] = 1 - arr[i + 1][j]\n\t\t\tarr[i][j + 1] = 1 - arr[i][j + 1]\n\t\t\tarr[i + 1][j + 1] = 1 - arr[i + 1][j + 1]\nfl = 1\nfor i in range(n):\n\tfor j in range(m):\n\t\tif arr[i][j] != brr[i][j]:\n\t\t\tfl = 0\nif fl:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "import sys\ninput = sys.stdin.readline\n(n, m) = map(int, input().split())\n(a, b) = ([list(map(int, input().split())) for _ in range(n)], [list(map(int, input().split())) for _ in range(n)])\nfor i in range(n):\n\tif sum((a[i][j] for j in range(m))) % 2 != sum((b[i][j] for j in range(m))) % 2:\n\t\tprint('No')\n\t\tsys.exit(0)\nfor j in range(m):\n\tif sum((a[i][j] for i in range(n))) % 2 != sum((b[i][j] for i in range(n))) % 2:\n\t\tprint('No')\n\t\tsys.exit(0)\nprint('Yes')\n", "(m, n) = map(int, input().split())\n(a, b) = ([input().split() for i in range(m)], [input().split() for i in range(m)])\nk = 0\nfor i in range(m):\n\tcount1 = 0\n\tfor j in range(n):\n\t\tif a[i][j] != b[i][j]:\n\t\t\tcount1 += 1\n\tif count1 % 2:\n\t\tk = 1\nfor i in range(n):\n\tcount2 = 0\n\tfor j in range(m):\n\t\tif a[j][i] != b[j][i]:\n\t\t\tcount2 += 1\n\tif count2 % 2:\n\t\tk = 1\nif k:\n\tprint('NO')\nelse:\n\tprint('YES')\n", "(n, m) = map(int, input().split())\nfirst = [[bool(int(i)) for i in input().split()] for j in range(n)]\nsecond = [[bool(int(i)) for i in input().split()] for j in range(n)]\nfor i in range(n):\n\tk1 = 0\n\tk2 = 0\n\tfor j in range(m):\n\t\tif first[i][j]:\n\t\t\tk1 += 1\n\t\tif second[i][j]:\n\t\t\tk2 += 1\n\tif k1 % 2 != k2 % 2:\n\t\tprint('No')\n\t\texit(0)\nfor j in range(m):\n\tk1 = 0\n\tk2 = 0\n\tfor i in range(n):\n\t\tif first[i][j]:\n\t\t\tk1 += 1\n\t\tif second[i][j]:\n\t\t\tk2 += 1\n\tif k1 % 2 != k2 % 2:\n\t\tprint('No')\n\t\texit(0)\nprint('Yes')\n", "(n, m) = map(int, input().split())\nmata = [None] * n\nfor i in range(n):\n\tmata[i] = list(map(int, input().split()))\nmatb = [None] * n\nfor i in range(n):\n\tmatb[i] = list(map(int, input().split()))\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\tif mata[i][j] == 0:\n\t\t\tmata[i][j] = 1\n\t\t\tmata[i + 1][j] ^= 1\n\t\t\tmata[i][j + 1] ^= 1\n\t\t\tmata[i + 1][j + 1] ^= 1\n\t\tif matb[i][j] == 0:\n\t\t\tmatb[i][j] = 1\n\t\t\tmatb[i + 1][j] ^= 1\n\t\t\tmatb[i][j + 1] ^= 1\n\t\t\tmatb[i + 1][j + 1] ^= 1\nif mata == matb:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "(a, b) = map(int, input().split())\na1 = [list(map(int, input().split())) for _ in range(a)]\na2 = [list(map(int, input().split())) for _ in range(a)]\ns1 = sum((sum(t) for t in a1))\ns2 = sum((sum(t) for t in a2))\nif (s2 - s1) % 2 != 0:\n\tprint('No')\n\texit()\nr1 = [sum(t) for t in a1]\nr2 = [sum(t) for t in a2]\nfor i in range(a):\n\tif (r1[i] - r2[i]) % 2 != 0:\n\t\tprint('No')\n\t\texit()\nc1 = [sum((a1[j][i] for j in range(a))) for i in range(b)]\nc2 = [sum((a2[j][i] for j in range(a))) for i in range(b)]\nfor i in range(b):\n\tif (c1[i] - c2[i]) % 2 != 0:\n\t\tprint('No')\n\t\texit()\nprint('Yes')\n", "def solve():\n\t(n, m) = [int(x) for x in input().split(' ')]\n\tA = [[int(x) for x in input().split(' ')] for row in range(n)]\n\tB = [[int(x) for x in input().split(' ')] for row in range(n)]\n\n\tdef row_par(M, k):\n\t\treturn sum(M[k]) % 2\n\n\tdef col_par(M, k):\n\t\treturn sum([r[k] for r in M]) % 2\n\tfor r in range(n):\n\t\tif row_par(A, r) != row_par(B, r):\n\t\t\treturn 'No'\n\tfor c in range(m):\n\t\tif col_par(A, c) != col_par(B, c):\n\t\t\treturn 'No'\n\treturn 'Yes'\nprint(solve())\n"]

difficulty: MEDIUM

source: codeforces

raw_problem:
C. Ramesses and Corner Inversion

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

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$$$.
  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.
  Example 1.   Example 2.   Example 3.

question:
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](1.png) 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](2.png) Example 1.  ![image](3.png) Example 2.  ![image](4.png) Example 3.

tags: ['Mathematics', 'Greedy algorithms', 'Implementation', 'Constructive algorithms']

skill_types: ['Greedy algorithms']

raw_tags: ['greedy', 'math', 'implementation', 'constructive algorithms']

image_tags: Patterns Patterns Patterns Patterns

data_split: test