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())
hw=[[]]
ans=[]
for i in range(h):
    ht=[0]+list(map(int,input().split()))
    hw.append(ht)
for i in range(1,h+1):
    for j in range(1,w):
        if hw[i][j]%2==1:
            ans.append([i,j,i,j+1])
            hw[i][j+1]+=1

for k in range(1,h):
    
    if hw[k][-1]%2==1:
        ans.append([k,w,k+1,w])
        hw[k+1][-1]+=1
print(len(ans))
for i in ans:
    for j in range(len(i)):
        i[j]=str(i[j])
    print(" ".join(i))

Solution (Python):
H, W = map(int, input().split())
A = []
for i in range(H):
    r = list(map(int, input().split()))
    if i&1:
        r.reverse()
    A.append(r)

ans = []

for i in range(H*W-1):
    if A[i//W][i%W]&1:
        j = i+1
        A[j//W][j%W] += 1
        ans.append([i, j])

def f(n):
    x = n//W
    y = n%W
    if x&1:
        y = W-y-1
    return f"{x+1} {y+1}"

print(len(ans))
for a, b in ans:
    print(f(a), f(b))

Solution (Python):
H, W = map(int, input().split())
a = []
for i in range(H):
  a.append(list(map(int, input().split())))
  
tmp = []
for i in range(H):
  if (sum(a[i])%2==1) and (i<H-1):
    for j in range(W):
      if a[i][j] % 2 == 1:
        n = j
        a[i][j] -= 1
        a[i+1][0] += 1
        break
    for j in range(n):
      tmp.append([i+1, n-j+1, i+1, n-j])
    tmp.append([i+1, 1, i+2, 1])
  for j in range(W):
    if (a[i][j]%2==1) and (j<W-1):
      a[i][j] -= 1
      a[i][j+1] += 1
      tmp.append([i+1, j+1, i+1, j+2])
print(len(tmp))
for i in range(len(tmp)):
  print(*tmp[i])

Solution (Python):
h, w = map(int, input().split())
a_s = [list(map(int, input().split())) for _ in range(h)]
pm = 1
x = 0
ans = []
car = 0
for y in range(h):
    for _ in range(w - 1):
        if (a_s[y][x] + car) % 2 == 0:
            car = 0
        else:
            car = 1
            ans.append([y + 1, x + 1, y + 1, x + 1 + pm])
        x += pm
    if y != h - 1:
        if (a_s[y][x] + car) % 2 == 0:
            car = 0
        else:
            car = 1
            ans.append([y + 1, x + 1, y + 2, x + 1])
    pm *= -1
print(len(ans))
for row in ans:
    print(*row)

Solution (Python):








def solve(H, W, A):
    move = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 1:
                if h < H - 1 and A[h + 1][w] % 2 == 1:
                    A[h][w] -= 1
                    A[h + 1][w] += 1
                    move.append([h, w, h + 1, w])
                elif w < W - 1 and A[h][w + 1] % 2 == 1:
                    A[h][w] -= 1
                    A[h][w + 1] += 1
                    move.append([h, w, h, w + 1])
                elif h < H - 1:
                    A[h][w] -= 1
                    A[h + 1][w] += 1
                    move.append([h, w, h + 1, w])
                elif w < W - 1:
                    A[h][w] -= 1
                    A[h][w + 1] += 1
                    move.append([h, w, h, w + 1])
    print(len(move))
    for m in move:
        print(' '.join([str(i + 1) for i in m]))


if __name__ == '__main__':
    H, W = map(int, input().split())
    A = [[int(i) for i in input().split()] for _ in range(H)]
    solve(H, W, A)

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

Solution (Python):

import sys


sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush


sys.setrecursionlimit(10 ** 7)





from collections import deque




INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def run():
    H, W = mapline()
    A = []
    for i in range(H):
        A.append(list(mapline()))

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

    print(len(output))
    for i1, j1, i2, j2 in output:
        print(f'{i1 + 1} {j1 + 1} {i2 + 1} {j2 + 1}')


if __name__ == "__main__":
    run()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter




from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

H, W = na()
a = [na() for _ in range(H)]
N = 0
ans = []
for y in range(H):
    for x in range(W):
        
        if a[y][x] % 2 == 0:
            continue
        else:
            nx = x + 1
            ny = y + 1
            if 0 <= nx < W and a[y][nx] % 2 == 1:
                N += 1
                a[y][nx] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, y+1, nx+1))
            elif 0 <= ny < H and a[ny][x] % 2 == 1:
                N += 1
                a[ny][x] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, ny+1, x+1))
            elif 0 <= ny < H:
                N += 1
                a[ny][x] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, ny+1, x+1))
            elif 0 <= nx < W:
                N += 1
                a[y][nx] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, y+1, nx+1))
print(N)
for x in ans:
    print(*x)

Solution (Python):

def resolve():
    H, W = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(H)]

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

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

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


if __name__ == "__main__":
    resolve()

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

ans=[]
for i in range(h-1):
  for j in range(w):
    if m[i][j]%2:
      ans.append(" ".join(map(str,(i+1,j+1,i+2,j+1))))
      m[i+1][j]+=1
for j in range(w-1):
  if m[h-1][j]%2:
    ans.append(" ".join(map(str,(h,j+1,h,j+2))))
    m[h-1][j+1]+=1

print(len(ans))
print("\n".join(ans))

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

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

    def next_index(x, y):
        if y % 2 == 0:
            if x == w - 1:
                return x, y + 1
            else:
                return x + 1, y
        else:
            if x == 0:
                return x, y + 1
            else:
                return x - 1, y

    ans = []
    x = 0; y = 0
    while True:
        next_x, next_y = next_index(x, y)

        if next_y == h:
            break

        if a[y][x] % 2 == 1:
            ans.append((y+1, x+1, next_y+1, next_x+1))
            a[next_y][next_x] += 1
        x = next_x; y = next_y

    print(len(ans))
    for i in ans:
        print(' '.join(map(str, i)))

main()

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

h,w = I()
A = []
for i in range(h):
    A.append([int(i) for i in input().split()])
Ans = []
for i in range(h):
    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] += 1

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

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

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

s = [[0] * W for i in range(H)]
s[0][0] = a[0][0] % 2
for i in range(1,W):
    s[0][i] = (s[0][i-1] + a[0][i]) % 2
for i in range(1,H):
    for j in range(W):
        if j == 0:
            s[i][j] = (s[i-1][-1] + a[i][j]) % 2
        else:
            s[i][j] = (s[i][j-1] + a[i][j]) % 2

s[H-1][W-1] = 0

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

print(len(ans))
for i in range(len(ans)):
    print("{} {} {} {}".format(ans[i][0], ans[i][1], ans[i][2], ans[i][3]))

Solution (Python):
h,w = map(int, input().split())
a = []
for i in range(h):
    a.append(list(map(int,input().split())))
now="R"
x,y=0,0
carry=False
ans=[]
while True:
    if carry:
        if a[y][x]%2==1: 
            carry=False
    else:
        if a[y][x]%2==1: 
            carry=True

    if now=="R":
        nxtx=x+1
        nxty=y
        if nxtx==w:
            nxtx=x
            nxty+=1
            now="L"
            if nxty==h:
                break
    else:
        nxtx=x-1
        nxty=y
        if nxtx==-1:
            nxtx=0
            nxty+=1
            now="R"
            if nxty==h:
                break
    if carry:
        ans.append([y+1,x+1,nxty+1,nxtx+1])
    x=nxtx
    y=nxty


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

Solution (Python):
import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    h, w = input_int_list()
    ans = []
    grid = []
    for _ in range(h):
        grid.append(input_int_list())
    
    
    

    for i in range(h):
        for j in range(w):
            if grid[i][j] % 2 == 1:
                if i == h - 1 and j == w - 1:
                    break
                grid[i][j] -= 1
                if j < w - 1:
                    grid[i][j + 1] += 1
                    ans.append((i + 1, j + 1, i + 1, j + 2))  
                elif i < h - 1:
                    grid[i + 1][j] += 1
                    ans.append((i + 1, j + 1, i + 2, j + 1))  

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

    return


if __name__ == "__main__":
    main()

Solution (Python):
def abc109_d():
    h, w = (int(x) for x in input().split())
    grid = [[int(x) for x in input().split()] for _ in range(h)]

    move = []
    rest = []
    for i in range(h):
        pick = False
        for j in range(w):
            v = grid[i][j]
            if pick:
                if v%2:
                    pick = False
                else:
                    if j < w-1: move.append((i+1, j+1, i+1, j+2))
            else:
                if v%2:
                    pick = True
                    if j < w-1: move.append((i+1, j+1, i+1, j+2))
        rest.append(pick)

    pick = False
    for i, v in enumerate(rest):
        if pick:
            if v:
                pick = False
            else:
                if i < h-1: move.append((i+1, w, i+2, w))
        else:
            if v%2:
                pick = True
                if i < h-1: move.append((i+1, w, i+2, w))

    print(len(move))
    for mv in move:
        print(*mv, sep=' ')

if __name__ == '__main__':
    abc109_d()

Solution (Python):
H,W = map(int,input().split())
B = []
C = []

for h in range(H):
  A = list(map(int,input().split()))
  w = 0
  for w in range(1,W):
    if A[w-1]%2:
      C.append((h+1,w,h+1,w+1))
      A[w]+=1
  B.append(A[w])
  
  if h and B[-2]%2:
    C.append((h,W,h+1,W))
    B[h]+=1
    
print(len(C))
for c in C:
  print(*c)

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

ans = []
temp = []
p = 0
for i in range(h):
    if i%2 == 0:
        rw = list(range(w))
    else:
        rw = list(range(w))[::-1]
    for j in rw:
        if p == 1:
            temp.append('{} {} {} {}'.format(
                prev[0], prev[1], i+1, j+1
            ))
            prev = (i+1, j+1)
        if area[i][j]%2 == 1:
            if p == 0:
                prev = (i+1, j+1)
                p+=1
            elif p == 1:
                p = 0
                ans += temp
                temp = []

print(len(ans))
for a in ans:
    print(a)

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

coin=[[0]*(W+2)]
for h in range(H):
    c=[0]
    c.extend(list(map(int,input().split())))
    c.append(0)
    coin.append(c)
coin.append([0]*(W+2))
    
position=[]
for h in range(1,H+1):
    W_list=list(range(1,W+1))
    if h % 2 == 0:
        W_list.reverse()
    for w in W_list:
        position.append([h,w])
        
ans=[]
for p1,p2 in zip(position[:-1],position[1:]):
    if coin[p1[0]][p1[1]] % 2 != 0:
        coin[p1[0]][p1[1]] -= 1
        coin[p2[0]][p2[1]] += 1
        ans.append([p1[0],p1[1],p2[0],p2[1]])
        
print(len(ans))
for a in ans:
    print(' '.join(map(str,a)))

Solution (Python):
h,w=map(int,input().split())
grid=[]
for i in range(h):
    *x,=map(int,input().split())
    grid.append(x)
oper=[]
d=[(1,0),(0,1)]
flg=False
cand=[]
for i in range(h):
    if i%2==0:
        s=0
        e=w
        b=1
    else:
        s=w-1
        e=-1
        b=-1
    for j in range(s,e,b):
        if flg:
            grid[i][j]+=1
            flg=False
            cand+=[i+1,j+1]
            oper.append(cand)
            cand=[]
        if grid[i][j]%2==1:
            grid[i][j]-=1
            flg=True
            cand+=[i+1,j+1]

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

Solution (Python):
h, w = map(int, input().split())
A = [list(map(int, input().split())) for _  in range(h)]
tates = []
moves = []
for j, line in enumerate(A):
    odd = 0
    for i, a in enumerate(line[:w-1]):
        if a%2==1:
            odd ^= 1
        if odd:
            moves.append((j+1, i+1, j+1, i+2))
    tates.append(odd^(line[-1]%2))

odd = 0
for i, a in enumerate(tates[:h-1]):
    if a:
        odd ^= 1
    if odd:
        moves.append((i+1, w, i+2, w))

print(len(moves))
for m in moves:
    print(*m)

Solution (Python):

H, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(H)]

ans = []
idx_list = [(i, j) if i % 2 == 0 else (i, W - j - 1)
            for i in range(H) for j in range(W)]
for i, (u, v) in enumerate(idx_list[:-1]):
    if X[u][v] % 2 == 1:
        x, y = idx_list[i + 1]
        X[x][y] += 1
        ans.append((u + 1, v + 1, x + 1, y + 1))

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

Solution (Python):
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
n = 0
ans = []
b = []
for i in range(h):
  for j in range(w):
    b.append((i,j if i%2==0 else w-j-1))
for i in range(h*w-1):
  y,x = b[i]
  if a[y][x]%2==0:
    continue
  a[y][x]-=1
  n+=1
  ny,nx = b[i+1]
  a[ny][nx]+=1
  ans.append("{} {} {} {}".format(str(y+1),str(x+1),str(ny+1),str(nx+1)))
print(n)
print("\n".join(ans))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(H)]
ans = []

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

        if X[i][-1] % 2 == 1 and i < H - 1:
            X[i][-1] -= 1
            X[i + 1][-1] += 1
            ans.append((i + 1, W, i + 2, W))
    else:
        for j in reversed(range(1, W)):
            if X[i][j] % 2 == 1:
                X[i][j] -= 1
                X[i][j - 1] += 1
                ans.append((i + 1, j + 1, i + 1, j))

        if X[i][0] % 2 == 1 and i < H - 1:
            X[i][0] -= 1
            X[i + 1][0] += 1
            ans.append((i + 1, 1, i + 2, 1))

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

Solution (Python):
H,W=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
   for j in range(W):
      l[i][j]%=2
sw=0
ans=[]
for i in range(H):
   if i%2==0:
      for j in range(W):
         if sw==1:
            ans.append((i+1,j+1))
         if l[i][j]==1:
            sw=1 if sw==0 else 0
            if sw==1:
               ans.append((i+1,j+1))
            if sw==0:
               ans.append(0)
   else:
      for j in reversed(range(W)):
         if sw==1:
            ans.append((i+1,j+1))
         if l[i][j]==1:
            sw=1 if sw==0 else 0
            if sw==1:
               ans.append((i+1,j+1))
            if sw==0:
               ans.append(0)
f_ans=[]
for i in range(len(ans)-1):
   if ans[i]!=0 and ans[i+1]!=0:
      f_ans.append((*ans[i],*ans[i+1]))
print(len(f_ans))
for i in f_ans:print(*i)

Solution (Python):
H, W = map(int,input().split())
a = []
for _ in range(H):
    l = list(map(int,input().split()))
    a.append(l)
cnt = 0
ope = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 != 0:
            cnt += 1
            ni,nj = i+1,j
            if ni < H and nj < W and a[ni][nj] % 2 != 0:
                a[i][j] -= 1
                a[ni][nj] += 1
                ope.append((i,j,ni,nj))
                continue
            ni,nj = i,j+1
            if ni < H and nj < W and a[ni][nj] % 2 != 0:
                a[i][j] -= 1
                a[ni][nj] += 1
                ope.append((i,j,ni,nj))
                continue
            ni,nj = i+1,j
            if ni < H and nj < W:
                a[i][j] -= 1
                a[ni][nj] += 1
                ope.append((i,j,ni,nj))
                continue
            ni,nj = i,j+1
            if ni < H and nj < W:
                a[i][j] -= 1
                a[ni][nj] += 1
                ope.append((i,j,ni,nj))
                continue
            cnt -= 1
print(cnt)
for x in ope:
    print(*map(lambda y:y+1, x))

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

cnt, ans, rvs = 0, [], -1
for i, ai in enumerate(a):
    rvs *= -1
    for j in range(w)[::rvs]:
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            ai[j] += 1
        cnt = int(ai[j] == 1)
        bi, bj = i, j

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

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

cnt, ans, rvs = 0, [], -1
for i, ai in enumerate(a):
    rvs *= -1
    for j in range(w)[::rvs]:
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            ai[j] += 1
        cnt = int(ai[j] == 1)
        bi, bj = i, j

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

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

stack = []

cnt = 0
printlist = [[False]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if l[i][j] % 2 == 1:
            if j < w-1:
                l[i][j+1] += 1
                printlist[i][j] = (i,j+1)
                cnt += 1

for i in range(h):
    if l[i][w-1] % 2 == 1:
        if i < h-1:
            l[i+1][w-1] +=1
            printlist[i][w-1] = (i+1,w-1)
            cnt += 1

print(cnt)
for i in range(h):
    for j in range(w-1):
        if printlist[i][j]:
            x = printlist[i][j]
            print(i+1,j+1,x[0]+1,x[1]+1)
for i in range(h):
    if printlist[i][w-1]:
        x = printlist[i][w-1]
        print(i+1,w,x[0]+1,w)

Solution (Python):

from collections import deque

H, W = (int(x) for x in input().split())
A = []

curMove = []
moves = []
hasOdd = False
pi = -1
pj = -1
for i in range(H):
    row = [int(x) for x in input().split()]
    if i % 2 == 0:
        start, end, diff = 0, W, 1
    else:
        start, end, diff = W-1, 0-1, -1

    for j in range(start, end, diff):
        if row[j] % 2 == 1:
            if hasOdd:
                curMove.append((pi,pj, i, j))
                moves += curMove
                curMove = []
                hasOdd = False
            else:
                hasOdd = True
        else:
            if hasOdd:
                curMove.append((pi,pj, i, j))
        pi = i
        pj = j

print(len(moves))
for m in moves:
    print(" ".join((str(i+1) for i in m)))

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

cnt, ans = 0, []
for i, ai in enumerate(a):
    for j in range(w)[::(i % 2) * (-2) + 1]:
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            ai[j] += 1
        cnt = int(ai[j] == 1)
        bi, bj = i, j

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

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

cnt, ans = 0, []
for i, ai in enumerate(a):
    for j in range(w)[::(i%2)*(-2)+1]:
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            ai[j] += 1
        cnt = int(ai[j] == 1)
        bi, bj = i, j

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

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

cnt, ans = 0, []
for i, ai in enumerate(a):
    for j in range(w):
        if i % 2 == 1:
            j = w - 1 - j
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            ai[j] = ai[j] + 1
        cnt = int(ai[j] == 1)
        bi, bj = i, j

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

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

cnt, ans = 0, []
for i, ai in enumerate(a):
    for j in range(w):
        if i % 2 == 1:
            j = w - 1 - j
        if cnt == 1:
            ans.append([bi + 1, bj + 1, i + 1, j + 1])
            cnt = 0
            ai[j] = (ai[j] + 1) % 2
        if ai[j] == 1:
            cnt = 1
        bi, bj = i, j

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

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

res = []
temp = 0

for i in range(h):
    for j in range(w-1):
        if ab[i][j] % 2 ==0:
            pass
        else:
            ab[i][j] -=1
            ab[i][j+1] += 1
            temp +=1
            res.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))

for k in range(h-1):
    if ab[k][w-1] % 2 ==0:
        pass
    else:
        ab[k][w-1] -=1
        ab[k+1][w-1] +=1
        temp +=1
        res.append(str(k+1)+" "+str(w)+" "+str(k+2)+" "+str(w))
                
print(temp)
for i in range(temp):
    print(res[i])

Solution (Python):
import sys
class Pair:
    def __init__(self,x,y):
        self.x=x
        self.y=y
class PPair:
    def __init__(self,xx,yy):
        self.xx=xx
        self.yy=yy

h,w=map(int,input().split())
A = [ list(map(int,input().split())) for i in range(h)]
odd =0
for i in range(h): 
    for j in range(w): 
        if A[i][j]%2==1: odd+=1
num=0;x=0;y=0
res=[]
for i in range(0,w*h):
    if A[x][y]%2==1: num+=1
    nx=x;ny=y;
    if x%2==0:
        if ny == w-1: nx+=1
        else: ny+=1
    else: 
        if ny==0: nx+=1
        else: ny-=1
    if num%2==1:
        if num<odd:
            res.append(PPair(Pair(x,y),Pair(nx,ny)))
    x=nx;y=ny
print (len(res))
for r in res:
    print("%d %d %d %d" %(r.xx.x+1, r.xx.y+1, r.yy.x+1, r.yy.y+1))

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

a = [[-1]*(W+2) for _ in range(H+2)]
odd_count = 0

for i in range(1, H+1):
    tmp = list(map(int, input().split()))
    for j in range(1, W+1):
        a[i][j] = tmp[j-1]
        odd_count += int(a[i][j] % 2 == 1)

moves = []

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

is_carrying = 0
for i, (h, w) in enumerate(routes):
    if i == H*W-1:
        break
    if odd_count == 1:
        break
    if a[h][w] % 2 == 1 and not is_carrying:
        tmp = (h, w)
        is_carrying = 1
        moves.append((h, w, routes[i+1][0], routes[i+1][1]))
    elif a[h][w] % 2 == 1 and is_carrying:
        is_carrying = 0
        odd_count -= 2
        
    elif a[h][w] % 2 == 0 and is_carrying:
        moves.append((h, w, routes[i+1][0], routes[i+1][1]))

print(len(moves))
for move in moves:
    print(*move)

Solution (Python):


H, W = map(int, input().split())
a = [[-1]*(W+2) for _ in range(H+2)]
odd_count = 0

for i in range(1, H+1):
    tmp = list(map(int, input().split()))
    for j in range(1, W+1):
        a[i][j] = tmp[j-1]
        odd_count += int(a[i][j] % 2 == 1)

moves = []
routes = []
for h in range(1, H+1):
    tmp = []
    for w in range(1, W+1):
        tmp.append((h, w))
    if h % 2 == 1:
        routes += tmp
    else:
        routes += tmp[::-1]

is_carrying = 0
for i, (h, w) in enumerate(routes):
    if i == H*W-1:
        break
    if a[h][w] % 2 == 1 and not is_carrying and odd_count != 1:
        tmp = (h, w)
        is_carrying = 1
        moves.append((h, w, routes[i+1][0], routes[i+1][1]))
    elif a[h][w] % 2 == 1 and is_carrying and odd_count != 1:
        is_carrying = 0
        odd_count -= 2
        
    elif a[h][w] % 2 == 0 and is_carrying and odd_count != 1:
        moves.append((h, w, routes[i+1][0], routes[i+1][1]))

print(len(moves))
for move in moves:
    print(*move)

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

done = [[0]*W for _ in range(H)]

def nex(y,x):
    for new_y,new_x in [[y,x+1],[y+1,x],[y-1,x],[y,x-1]]:
        if 0<=new_y<H and 0<=new_x<W and not done[new_y][new_x]:
            return [new_y,new_x]
    return False

ans_ls = []
y,x = 0,0
if grid[y][x] % 2 == 1:
    previous_y, previous_x = y,x
    have_odd = True
else:
    have_odd = False

while True:
    if not nex(y,x):
        break
    y,x  = nex(y,x)
    done[y][x] = 1
    
    
    if have_odd:
        if grid[y][x] % 2 == 1:
            ans_ls.append([y+1,x+1,previous_y+1,previous_x+1])
            have_odd = False
        else:
            ans_ls.append([y+1,x+1,previous_y+1,previous_x+1])
            previous_y,previous_x = y,x
    
    else:
        if grid[y][x] % 2 == 1:
            previous_y,previous_x = y,x 
            have_odd = True
        else:
            pass

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

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


xylis=[]

for i in range(h-1):
  for j in range(w-1):
    if a[i][j]%2==1:
      a[i][j]-=1
      a[i][j+1]+=1
      xylis.append([i,j,i,j+1])
  if a[i][w-1]%2==1:
    a[i][w-1]-=1
    a[i+1][w-1]+=1
    xylis.append([i,w-1,i+1,w-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
    xylis.append([h-1,j,h-1,j+1])

print(len(xylis))
for xylisi in xylis:
  print(*list(map(lambda x:x+1,xylisi)))

Solution (Python):
def mover(H,W):
    k=1
    x,y=0,0
    v=1
    while k<H*W:
        old_x,old_y=x,y

        if not((v==1 and x==W-1) or (v==-1 and x==0)):
            x+=v
        else:
            v*=-1
            y+=1
        yield ((old_x,old_y),(x,y))
        k+=1

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

Mode=0
D=[]
for ((ox,oy),(x,y)) in mover(H,W):
    if (Mode==0 and A[oy][ox]%2==1) or Mode==1:
        A[oy][ox]-=1
        A[y][x]+=1
        D.append(((ox,oy),(x,y)))
        Mode=A[y][x]%2

print(len(D))
for ((ox,oy),(x,y)) in D:
    print(oy+1,ox+1,y+1,x+1)

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):
  for j in range(w-1):
    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])
for i in range(h-1):
  if a[i][w-1] % 2 == 1:
    a[i][w-1] -= 1
    a[i+1][w-1] += 1
    ans.append([i+1, w, i+2, w])
print(len(ans))
for p in ans:
  print(*p)