Problem:
 Score : 400 points    Problem Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i -th row and the j -th column will be denoted as Cell (i, j) .  In Cell (i, j) , a_{ij} coins are placed.  You can perform the following operation any number of times:  Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.  Maximize the number of cells containing an even number of coins.      Constraints  All values in input are integers.  1 \leq H, W \leq 500  0 \leq a_{ij} \leq 9         Input Input is given from Standard Input in the following format:  H  W  a_{11}  a_{12}  ...  a_{1W}  a_{21}  a_{22}  ...  a_{2W}  :  a_{H1}  a_{H2}  ...  a_{HW}       Output Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:  N  y_1  x_1  y_1'  x_1'  y_2  x_2  y_2'  x_2'  :  y_N  x_N  y_N'  x_N'   That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations.  In the (i+1) -th line ( 1 \leq i \leq N ), print four integers y_i, x_i, y_i' and x_i' ( 1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W ), representing the i -th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i') .  Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer .        Sample Input 1 2 3
1 2 3
0 1 1      Sample Output 1 3
2 2 2 3
1 1 1 2
1 3 1 2  Every cell contains an even number of coins after the following sequence of operations:   Move the coin in Cell (2, 2) to Cell (2, 3) .  Move the coin in Cell (1, 1) to Cell (1, 2) .  Move one of the coins in Cell (1, 3) to Cell (1, 2) .        Sample Input 2 3 2
1 0
2 1
1 0      Sample Output 2 3
1 1 1 2
1 2 2 2
3 1 3 2       Sample Input 3 1 5
9 9 9 9 9      Sample Output 3 2
1 1 1 2
1 3 1 4

Solution (Python):
h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

if h == 1 and w == 1:
    print(0)
    exit()

cnt = 0
ans = []
for i in range(h):
    for j in range(w):
        a = A[i][j]
        if a%2 == 1:
            for dy, dx in (-1, 0), (0, -1), (0, 1), (1, 0):
                ni = i+dy
                nj = j+dx
                if 0 <= ni < h and 0 <= nj < w:
                    ni_ = ni
                    nj_ = nj
                    if A[ni][nj]%2 == 1:
                        A[ni][nj] += 1
                        A[i][j] -= 1
                        cnt += 1
                        ans.append([i+1, j+1, ni+1, nj+1])
                        break
            else:
                A[ni_][nj_] += 1
                A[i][j] -= 1
                cnt += 1
                ans.append([i+1, j+1, ni_+1, nj_+1])

print(cnt)
for i in range(cnt):
    print(*ans[i])

Solution (Python):

import sys
input = sys.stdin.readline
from collections import Counter

h, w = map(int, input().split())
field = []
ans = []
for hgt in range(h):
    line = [int(item) for item in input().split()]
    ret = []
    for i in range(1, w):
        if line[i-1] % 2 == 1:
            line[i-1] -= 1
            line[i] += 1
            ans.append((hgt+1, i, hgt+1, i+1))
    field.append(line)

for i in range(1, h):
    if field[i-1][w-1] % 2 == 1:
        field[i-1][w-1] -= 1
        field[i][w-1] += 1
        ans.append((i, w, i+1, w))

print(len(ans))
for line in ans:
    print(*line)

Solution (Python):
H,W = map(int, input().split())
a = [[int(i) for i in input().split()] for _ in range(H)]

move = []
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if a[i][j] % 2 == 1:
                if j == W - 1 and i < H - 1:
                    move.append((i+1,j+1,i+2,j+1))
                    a[i][j] -= 1; a[i+1][j] += 1
                elif j < W - 1:
                    move.append((i+1,j+1,i+1,j+2))
                    a[i][j] -= 1; a[i][j+1] += 1
    else:
        for j in range(W-1, -1, -1):
            if a[i][j] % 2 == 1:
                if j == 0 and i < H - 1:
                    move.append((i+1,j+1,i+2,j+1))
                    a[i][j] -= 1; a[i+1][j] += 1
                elif j > 0:
                    move.append((i+1,j+1,i+1,j))
                    a[i][j] -= 1; a[i][j-1] += 1

print(len(move))
for ans in move:
    print(*ans, sep=" ")

Solution (Python):
h,w=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(h)]
ans=[]
for i in range(1,h,2):a[i]=a[i][::-1]
for i in range(h):
  for j in range(w):
    if a[i][j]%2==0:continue
    if j==w-1:
      if i==h-1:continue
      a[i+1][0]+=1
      a[i][w-1]-=1
      ans.append([i,w-1,i+1,0])
    else:
      a[i][j+1]+=1
      a[i][j]-=1
      ans.append([i,j,i,j+1])
for i in range(len(ans)):
  if ans[i][0]%2==1:ans[i][1]=(w-1)-ans[i][1]
  if ans[i][2]%2==1:ans[i][3]=(w-1)-ans[i][3]
print(len(ans))
for i in ans:
  a,b,c,d=i
  print(a+1,b+1,c+1,d+1)

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, W = (int(i) for i in input().split())
    c = [[int(i) for i in input().split()] for j in range(H)]
    ans = []
    for h in range(H):
        for w in range(W):
            if c[h][w] % 2 == 1:
                if h != H - 1 and w != W - 1:
                    c[h][w] -= 1
                    c[h][w+1] += 1
                    ans.append((h+1, w+1, h+1, w+2))
                elif w != W - 1:
                    c[h][w] -= 1
                    c[h][w+1] += 1
                    ans.append((h+1, w+1, h+1, w+2))
                elif h != H - 1:
                    c[h][w] -= 1
                    c[h+1][w] += 1
                    ans.append((h+1, w+1, h+2, w+1))
    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

cnt = 0
ans = []
for h in range(H - 1):
    for w in range(W):
        if A[h][w] % 2 == 1:
            cnt += 1
            ans.append((h, w, h + 1, w))
            A[h + 1][w] += 1
            A[h][w] -= 1

for w in range(W - 1):
    if A[H - 1][w] % 2 == 1:
        cnt += 1
        ans.append((H - 1, w, H - 1, w + 1))
        A[H - 1][w + 1] += 1
        A[H - 1][w] -= 1

print(cnt)
for a, b, c, d in ans:
    print(a + 1, b + 1, c + 1, d + 1)

Solution (Python):
H,W=map(int,input().split())
A=[]
for i in range(H):
  A.append(list(map(int,input().split())))
path=[]
for i in range(H):
  for j in range(W):
    if i%2==0:
      path.append([i,j])
    else:
      path.append([i,W-j-1])
count=0
opr=[]
for i in range(len(path)-1):
  if A[path[i][0]][path[i][1]]%2==0:
    pass
  else:
    A[path[i][0]][path[i][1]]-=1
    A[path[i+1][0]][path[i+1][1]]+=1
    count+=1
    opr.append([path[i][0]+1,path[i][1]+1,path[i+1][0]+1,path[i+1][1]+1])

print(count)
for i in opr:
  print(*i)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
A = [LIST() for i in range(H)]

xy = []
xxyy = []
route = []
sum_A = 0

for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            route.append([i, j])
    else:
        for j in range(W-1, -1, -1):
            route.append([i, j])
    sum_A += A[i][j]

ans = []
for i in range(len(route)-1):
    y, x = route[i]
    y_next, x_next = route[i+1]
    if A[y][x] % 2 == 1:
        A[y][x] -= 1
        A[y_next][x_next] += 1
        ans.append([y+1, x+1, y_next+1, x_next+1])
print(len(ans))
for a in ans:
    print(*a)

Solution (Python):
H, W = [int(x) for x in input().split()]
a = [[None for _ in range(W)]] + \
    [[None] + [int(x) for x in input().split()] for _ in range(H)]


N = 0
y_from = [0]
y_to = [0]
x_from = [0]
x_to = [0]
for i in range(1, H):
    for j in range(1, W + 1):
        if a[i][j] % 2 == 0: continue
        N += 1
        a[i][j] -= 1
        y_from.append(i)
        x_from.append(j)

        a[i + 1][j] += 1
        y_to.append(i + 1)
        x_to.append(j)

for j in range(1, W):
    if a[H][j] % 2 == 0: continue
    N += 1
    a[H][j] -= 1
    y_from.append(H)
    x_from.append(j)

    a[H][j + 1] += 1
    y_to.append(H)
    x_to.append(j + 1)

print(N)
for i in range(1, N + 1):
    print(y_from[i], x_from[i], y_to[i], x_to[i])

Solution (Python):
h,w=map(int,input().split())
M=[]
for i in range(h):
    M.append(list(map(int,input().split())))

ANS=[]
cnt=0
for i in range(h):
    for j in range(w):
        if M[i][j]%2==1:
            for x,y in [(0,1),(1,0)]:
                if (0<=i+x and i+x<h) and (0<=j+y and j+y<w):
                    M[i+x][j+y]+=1
                    cnt+=1
                    ANS.append([i+1,j+1,x+i+1,y+j+1])
                    break
print(cnt)
for i in range(cnt):
    print(*ANS[i])

Solution (Python):

from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = list( map(int, input().split()))


queue = deque()

ansN = 0
ans = []

for i in range(h):
    for j in range(w):
        if maze[i][j] % 2 != 0:
            if j+1 < w:
                maze[i][j] -= 1
                maze[i][j+1] += 1
                ansN+=1
                ans.append([i+1, j+1, i+1, j+2])

            elif i+1 < h:
                maze[i][j] -= 1
                maze[i+1][j] += 1
                ansN+=1
                ans.append([i+1, j+1, i+2, j+1])

print(ansN)

for i in range(ansN):
    print(*ans[i], sep =' ')

Solution (Python):
H,W = map(int, input().split())
A = [[int(i) for i in input().split()] for _ in range(H)]

cnt = 0
ans = []
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if i == H - 1 and j == W - 1:
                continue
            if j == W - 1:
                if A[i][j] % 2 == 1:
                    A[i][j] -= 1
                    A[i+1][j] += 1
                    ans.append((i+1, j+1, i+2, j+1))
            else:
                if A[i][j] % 2 == 1:
                    A[i][j] -= 1
                    A[i][j+1] += 1
                    ans.append((i+1, j+1, i+1, j+2))
    else:
        for j in range(W - 1, -1, -1):
            if i == H - 1 and j == 0:
                continue
            if j == 0:
                if A[i][j] % 2 == 1:
                    A[i][j] -= 1
                    A[i+1][j] += 1
                    ans.append((i+1, j+1, i+2, j+1))
            else:
                if A[i][j] % 2 == 1:
                    A[i][j] -= 1
                    A[i][j-1] += 1
                    ans.append((i+1, j+1, i+1, j))

print(len(ans))
for a in ans:
    print(*a, sep = " ")

Solution (Python):

H,W = map(int,input().split())
field = []

for i in range(H):
    coins = list(map(int,input().split()))
    field.append(coins)

field_route = []
is_left_to_right = False
for i in range(H):
    is_left_to_right = not is_left_to_right
    for j in range(W):
        if is_left_to_right:
            field_route.append((j,i))
        else:
            field_route.append((W-j-1,i))


ans_ls = []
for i,next_xy in enumerate(field_route[:-1]):
    tx,ty = next_xy
    x,y = field_route[i+1]
    if field[ty][tx] == 0:
        tx,ty = x,y
        continue
    if field[ty][tx] %2 == 1:
        field[y][x] += 1
        ans_ls.append([ty+1,tx+1,y+1,x+1])
    tx,ty = x,y
print(len(ans_ls))
for l in ans_ls:
    print(l[0],l[1],l[2],l[3])

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if i % 2 == 0:
            if a[i][j] % 2 == 1:
                if j != w - 1:
                    a[i][j + 1] += 1
                    d = [i + 1, j + 1, i + 1, j + 2]
                    ans.append(d)
                elif i != h - 1:
                    a[i + 1][j] += 1
                    d = [i + 1, w, i + 2, w]
                    ans.append(d)
        else:
            if a[i][w - j - 1] % 2 == 1:
                if j != w - 1:
                    a[i][w - j - 2] += 1
                    d = [i + 1, w - j, i + 1, w - j - 1]
                    ans.append(d)
                elif i != h - 1:
                    a[i + 1][0] += 1
                    d = [i + 1, 1, i + 2, 1]
                    ans.append(d)
print(len(ans))
for d in ans:
    print(" ".join(map(str, d)))

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

result = []
for x in range(h):
    for y in range(w):
        if a[x][y]%2==1:
            if y+1 < w:
                a[x][y+1] += 1
                result.append([x+1, y+1, x+1, y+1+1])
            elif x+1 < h:
                a[x+1][y] += 1
                result.append([x+1, y+1, x+1+1, y+1])
print(len(result))
for i in result:
    print(*i)

Solution (Python):









import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    h, w = list(map(int,ipti().split()))
    a = [[0] * w for _ in range(h)]

    for i in range(h):
        a[i] = list(map(int,ipti().split()))

    x_cur = 0
    y_cur = 0
    x_next = 0
    y_next = 0
    direction = 1 
    mani_count = 0
    res = []

    while True:
        x_next += direction
        if x_next >= w:
            x_next -= 1
            direction *= -1
            y_next += 1
            if y_next >= h:
                break
        elif x_next < 0:
            x_next += 1
            direction *= -1
            y_next += 1
            if y_next >=h:
                break

        if a[y_cur][x_cur] % 2 == 1:
            mani_count += 1
            a[y_cur][x_cur] -= 1
            a[y_next][x_next] += 1
            res.append([y_cur + 1, x_cur + 1, y_next + 1, x_next + 1])

        x_cur, y_cur = x_next, y_next

    print(mani_count)
    for elem in res:
        print(*elem)

if __name__ == '__main__':
    main()

Solution (Python):
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]
ans = []
for i in range(H-1):
    if i%2 == 0:
        for j in range(W-1):
            if a[i][j]%2 == 1:
                ans.append([i+1,j+1,i+1,j+2])
                a[i][j] -= 1
                a[i][j+1] += 1
        if a[i][W-1]%2 == 1:
            ans.append([i+1,W,i+2,W])
            a[i][W-1] -= 1
            a[i+1][W-1] += 1
    else:
        for j in range(W-1,0,-1):
            if a[i][j]%2 == 1:
                ans.append([i+1,j+1,i+1,j])
                a[i][j] -= 1
                a[i][j-1] += 1
        if a[i][0]%2 == 1:
            ans.append([i+1,1,i+2,1])
            a[i][0] -= 1
            a[i+1][0] += 1
if (H-1)%2 == 0:
    for j in range(W-1):
        if a[H-1][j]%2 == 1:
            ans.append([H,j+1,H,j+2])
            a[H-1][j] -= 1
            a[H-1][j+1] += 1
else:
    for j in range(W-1,0,-1):
        if a[H-1][j]%2 == 1:
            ans.append([H,j+1,H,j])
            a[H-1][j] -= 1
            a[H-1][j-1] += 1

print(len(ans))
for an in ans:
    print(*an)

Solution (Python):
H, W = map(int, input().split())

path = []
for i in range(H):
    y = i+1
    row = list(map(int, input().split()))
    if i%2==0:
        for j, coin in enumerate(row):
               x = j+1
               path.append([y, x, coin])
    else:
        for j, coin in enumerate(row[::-1]):
               x = W-j
               path.append([y, x, coin])

ans = []
cnt = 0
for k in range(len(path)-1):
    c = path[k][2]
    if c%2==0:
        continue
    else:
        cnt += 1
        y, x = path[k][:2]
        ny, nx = path[k+1][:2]
        ans.append((y, x, ny, nx))
        path[k+1][2] += 1

print(cnt)
for a in ans:
    print(a[0], a[1], a[2], a[3])

Solution (Python):
h, w = map(int, input().split())
A = []
for _ in range(h):
    a = list(map(int, input().split()))
    A.append(a)
Operation = []
count = 0
for i in range(h):
    for j in range(w-1):
        if A[i][j] % 2 == 0:
            continue
        else:
            A[i][j] = A[i][j] - 1
            A[i][j+1] = A[i][j+1] + 1
            count += 1
            operation = [i+1, j+1, i+1, j+2]
            operation = [str(x) for x in operation]
            Operation.append(operation)
    if i == h-1:
        continue
    for j in range(w):
        if A[i][j] % 2 == 0:
            continue
        else:
            A[i][j] = A[i][j] - 1
            A[i+1][j] = A[i+1][j] + 1
            count += 1
            operation = [i+1, j+1, i+2, j+1]
            operation = [str(x) for x in operation]
            Operation.append(operation)
print(count)
for operation in Operation:
    print(' '.join(operation))

Solution (Python):
import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().split()]
a = []
for _ in range(H):
    a.append([int(x) for x in input().split()])

place = [0, 0]
ans = []
flag = 1

for i in range(H * W - 1):
    x, y = place
    if flag:
        new_x, new_y = x, y + 1
        if new_y >= W:
            new_x, new_y = x + 1, y
            flag = 0
    else:
        new_x, new_y = x, y - 1
        if new_y < 0:
            new_x, new_y = x + 1, y
            flag = 1
    if a[x][y] % 2 == 1:
        ans.append([x + 1, y + 1, new_x + 1, new_y + 1])
        a[new_x][new_y] += 1
    place = [new_x, new_y]

print(len(ans))
for j in ans:
    print(*j)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]
    
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j]%2 != 0:
                a[i][j+1] += 1
                ans.append((i+1,j+1,i+1,j+2))
                
    for i in range(H-1):
        if a[i][-1]%2 != 0:
            a[i+1][-1] += 1
            ans.append((i+1,W,i+2,W))
            
    print(len(ans))
    for x in ans:
        print(*x)

if __name__ == "__main__":
    main()

Solution (Python):
H, W = map(int, input().split())

a = [0] * H
for i in range(H):
    a[i] = list(map(int, input().split()))


ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] % 2 != 0:
            a[i][j+1] += 1
            ans.append([i+1, j+1, i+1, j+2])

for i in range(H-1):
    if a[i][W-1] % 2 != 0:
        a[i+1][W-1] += 1
        ans.append([i+1, W, i+2, W])


print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Solution (Python):
H, W = (int(i) for i in input().split())  
A = [[int(i) for i in input().split()] for i in range(H)]
lst = []

for i in range(H-1):
  for j in range(W):
    if A[i][j] % 2 == 0:
      continue
    else:
      A[i][j] -= 1
      A[i+1][j] += 1
      lst.append([i+1, j+1, i+2, j+1])

for j in range(W-1):
  if A[H-1][j] % 2 == 1:
    A[H-1][j] -= 1
    A[H-1][j+1] += 1
    lst.append([H, j+1, H, j+2])
print(len(lst))
for l in lst:
  print(*l)

Solution (Python):
H, W = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(H)]
l = []

for h in range(H):
    for w in range(W-1):
        if d[h][w]%2:
            d[h][w+1] += 1
            d[h][w] -= 1
            l.append((h+1, w+1, h+1, w+2))

for h in range(H-1):
    if d[h][W-1]%2:
        d[h][W-1] -= 1
        d[h+1][W-1] += 1
        l.append((h+1, W, h+2, W))

print(len(l))
for i in l:
    print(*i)

Solution (Python):
H, W = map(int, input().split())
A = []
for h in range(H):
    tmp = list(map(int, input().split()))
    if h % 2 == 0:
        r = range(W)
    else:
        r = range(W)[::-1]

    for w in r:
        A.append((h, w, tmp[w]))

ans = []
for i in range(len(A) - 1):
    if A[i][2] % 2 != 0:
        ans.append((A[i][0] + 1, A[i][1] + 1, A[i + 1][0] + 1, A[i + 1][1] + 1))
        A[i + 1] = (A[i + 1][0], A[i + 1][1], A[i + 1][2] + 1)
print(len(ans))
for x in ans:
    print(*x)

Solution (Python):
H, W = map(int, input().split())
A = []
for h in range(H):
    tmp = list(map(int, input().split()))
    if h % 2 == 0:
        r = range(W)
    else:
        r = range(W)[::-1]

    for w in r:
        A.append((h, w, tmp[w]))

ans = []
for i in range(len(A) - 1):
    if A[i][2] % 2 != 0:
        ans.append((A[i][0] + 1, A[i][1] + 1, A[i + 1][0] + 1, A[i + 1][1] + 1))
        A[i + 1] = (A[i + 1][0], A[i + 1][1], A[i + 1][2] + 1)
        A[i] = (A[i][0], A[i][1], A[i][2] - 1)
print(len(ans))
for x in ans:
    print(*x)

Solution (Python):
def main():
    height, width = map(int, input().split())
    grid = [list(map(int, input().split())) for _ in range(height)]
    answer = []
    for i in range(height - 1):
        for j in range(width):
            if grid[i][j] % 2:
                grid[i + 1][j] += 1
                grid[i][j] -= 1
                answer.append([i + 1, j + 1, i + 2, j + 1])
    for j in range(width - 1):
        if grid[-1][j] % 2:
            grid[-1][j + 1] += 1
            grid[-1][j] -= 1
            answer.append([height, j + 1, height, j + 2])
    print(len(answer))
    for ans in answer:
        print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()

a = [LIST() for _ in range(H)]

op = []
for i in range(H):
	for j in range(W-1):
		if a[i][j]%2 != 0:
			a[i][j+1] += 1
			a[i][j] -= 1
			op.append([i+1, j+1, i+1, j+2])

for i in range(H-1):
	if a[i][-1]%2 != 0:
		a[i+1][-1] += 1
		a[i][-1] -= 1
		op.append([i+1, W, i+2, W])

print(len(op))
print(*[" ".join(map(str, x)) for x in op], sep="\n")

Solution (Python):
h,w=map(int,input().split())
a = [ list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w):
        if i==h-1 and j==w-1: continue
        if a[i][j] % 2==0: continue
        if j == w-1:      
            a[i+1][j] += 1
            ans.append((i+1,j+1,i+2,j+1))
        else:
            a[i][j+1] += 1
            ans.append((i+1,j+1,i+1,j+2))

print(len(ans))
for o in ans:
    print (*o)

Solution (Python):


if __name__ == '__main__':
    H,W=list(map(int,input().split()))
    A=[list(map(int,input().split())) for j in range(H)]
    N=0
    ans=[]
    XY=[]
    reverse=False
    for i in range(H):
        if not reverse:
            for j in range(W):
                XY.append((i,j))
            reverse=True
        else:
            for j in range(W-1,-1,-1):
                XY.append((i,j))
                reverse=False
    for i,(x,y) in enumerate(XY):
        if i!=len(XY)-1:
            if A[x][y]%2==1:
                A[x][y]-=1
                x2,y2=XY[i+1]
                A[x2][y2]+=1
                N+=1
                ans.append(((x,y),(x2,y2)))

    print(N)
    for a in ans:
        b,c=a[0]
        d,e=a[1]
        print("{} {} {} {}".format(b+1,c+1,d+1,e+1))

Solution (Python):
from sys import stdin
h,w = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(h)]
point = 0
lin = []

for i in range(h):
    for j in range(w-1):
        if li[i][j] %2 == 1:
            li[i][j] -= 1
            li[i][j+1] += 1
            lin.append([i+1,j+1,i+1,j+2])
            point += 1

for i in range(h-1):
    if li[i][w-1] %2 == 1:
        li[i][w-1] -= 1
        li[i+1][w-1] += 1
        lin.append([i+1,w,i+2,w])
        point += 1
print(point)
for i in lin:
    print(*i)

Solution (Python):
H, W = map(int, input().split())
A = [0] * H
for i in range(H):
    A[i] = list(map(int, input().split()))



ops_list = []

for h in range(H):
    for w in range(W):
        
        if A[h][w] % 2 == 0:
            continue
        if w+1 < W and A[h][w+1] % 2 == 1:
            A[h][w] -= 1
            A[h][w + 1] += 1
            ops_list.append([h+1, w+1, h+1, w+2])

        elif h+1 < H and A[h+1][w] % 2 == 1:
            A[h][w] -= 1
            A[h+1][w] += 1
            ops_list.append([h+1, w+1, h+2, w+1])

        elif w+1 < W:
            A[h][w] -= 1
            A[h][w + 1] += 1
            ops_list.append([h+1, w+1, h+1, w+2])

        elif h+1 < H:
            A[h][w] -= 1
            A[h+1][w] += 1
            ops_list.append([h+1, w+1, h+2, w+1])
print(len(ops_list))
for ops in ops_list:
    print(*ops)

Solution (Python):
H, W = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
ope = []
for y in range(H):
    for x in range(W):
        if grid[y][x] % 2 != 0 and (y, x) != (H - 1, W - 1):
            
            grid[y + (W == x + 1)][x + (W != x + 1)] += 1
            ope.append((y + 1, x + 1, y + 1 + (W == x + 1), x + 1 + (W != x + 1)))

print(len(ope))
for o in ope:
    print(*o)

Solution (Python):
h, w = map(int, input().split())
a = [[i & 1 for i in map(int, input().split())] for _ in range(h)]

n = 0
operations = []
for i in range(h):
    for j in range(w - 1):
        if a[i][j]:
            a[i][j + 1] ^= a[i][j]
            n += 1
            operations.append((i + 1, j + 1, i + 1, j + 2))

for i in range(h - 1):
    if a[i][-1]:
        a[i + 1][-1] ^= a[i][-1]
        n += 1
        operations.append((i + 1, w, i + 2, w))

print(n)
for y1, x1, y2, x2 in operations:
    print(y1, x1, y2, x2)

Solution (Python):
from collections import deque
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
operations = []
have_coin = False
for h in range(H):
    if h%2 == 0:
        for w in range(W):
            if have_coin == False and A[h][w]%2!=0:
                have_coin = True
                prev_w = w
                prev_h = h

            elif have_coin and A[h][w]%2 == 0:
                operations.append([prev_h+1,prev_w+1,h+1,w+1])
                prev_h = h
                prev_w = w

            elif have_coin and A[h][w]%2 != 0:
                have_coin = False
                operations.append([prev_h+1, prev_w+1, h+1, w+1])

            else:
                pass





    else:
        for w in range(W-1,-1,-1):
            if have_coin == False and A[h][w] % 2 != 0:
                have_coin = True
                prev_w = w
                prev_h = h

            elif have_coin and A[h][w] % 2 == 0:
                operations.append([prev_h+1, prev_w+1, h+1, w+1])
                prev_h = h
                prev_w = w

            elif have_coin and A[h][w] % 2 != 0:
                have_coin = False
                operations.append([prev_h+1, prev_w+1, h+1, w+1])

            else:
                pass

print(len(operations))
for operation in operations:
    print(*operation)

Solution (Python):
H, W = [int(x) for x in input().split()]
an = [[int(x) for x in input().split()] for _ in range(H)]

pathes = []
for h in range(H):
  for w in range(W):
    if h % 2 == 0:
      ww = w
    else:
      ww = W - 1 - w
    pathes.append((ww, h))


N = H * W 
outs = []
for n in range(N - 1):
  w1, h1 = pathes[n]
  w2, h2 = pathes[n + 1]
  if an[h1][w1] % 2 == 1:
    outs.append((h1 + 1, w1 + 1, h2 + 1, w2 + 1))
    an[h2][w2] += 1
    
print(len(outs))
for out in outs:
  print(" ".join([str(i) for i in out]))

Solution (Python):
from functools import reduce
from collections import deque
import math
    
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    H, W = (int(_) for _ in input().split())
    a=[]
    for h in range(H):
       a.append(list(int(_) for _ in input().split()))

    ans = []

    for h in range(H):
        for w in range(W-1):
            if a[h][w] % 2 ==1:
                ans.append((h+1,w+1,h+1,w+2))
                a[h][w] += -1
                a[h][w+1] += 1
                
    for h in range(H-1):
        if a[h][W-1] % 2 ==1:
            ans.append((h+1,W,h+2,W))
            a[h][W-1] += -1
            a[h+1][W-1] += 1
                
    print(len(ans))
    for i in ans:
        print(i[0],i[1],i[2],i[3])
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    h,w=map(int,input().split())
    grid=[list(map(int,input().split())) for i in range(h)]
    
    ans=[]
    a_append=ans.append
    for i in range(h):
        for j in range(w-1):
            if grid[i][j]%2!=0:
                grid[i][j+1]+=1
                a_append([i+1,j+1,i+1,j+2])
    for i in range(h-1):
        if grid[i][w-1]%2!=0:
            grid[i+1][w-1]+=1
            a_append([i+1,w,i+2,w])
    n=len(ans)
    print(n)
    for i in range(n):
        print(*ans[i])
if __name__=='__main__':
    main()

Solution (Python):
def main():
    h,w=map(int,input().split())
    grid=[list(map(int,input().split())) for i in range(h)]
    
    ans=[]
    for i in range(h):
        for j in range(w-1):
            if grid[i][j]%2!=0:
                grid[i][j+1]+=1
                ans.append([i+1,j+1,i+1,j+2])
    for i in range(h-1):
        if grid[i][w-1]%2!=0:
            grid[i+1][w-1]+=1
            ans.append([i+1,w,i+2,w])
    n=len(ans)
    print(n)
    for i in range(n):
        print(*ans[i])
if __name__=='__main__':
    main()

Solution (Python):

H,W=map(int,input().split())
A=[]
Ans=[]
for i in range(H):
    a=list(map(int,input().split()))
    if i%2==0:
        A+=a
    else:
        A+=a[::-1]
for i in range(H*W-1):
    if A[i]%2==1:
        A[i]-=1
        A[i+1]+=1
        y1=i//W+1
        x1=i%W+1 if y1%2==1 else W-i%W
        y2=(i+1)//W+1
        x2=(i+1)%W+1 if y2%2==1 else W-(i+1)%W
        Ans.append([y1,x1,y2,x2])
print(len(Ans))
for ans in Ans:
    print(*ans)

Solution (Python):
h, w = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if table[i][j] % 2 == 0:  
            pass
        elif i == h-1 and j == w-1:  
            pass
        else:
            table[i][j] -= 1
            if j != w - 1:  
                table[i][j+1] += 1  
                ans.append([i+1, j+1, i+1, j+2])
            elif i != h - 1:  
                table[i+1][j] += 1  
                ans.append([i+1, j+1, i+2, j+1])
print(len(ans))

for i in ans:
    print(*i)