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 = []
for i in range(h):
  b = list(map(int, input().split()))
  a.append(b)

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

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

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

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

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

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

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

ans=[]

c=0
for i in range(h):
    if i%2==0:
        for j in range(w):
            if c==0 and a[i][j]%2==1:
                c=1
            if c==2:
                c=0
            if c==1 and j<w-1:
                ans.append([str(i+1),str(j+1),str(i+1),str(j+2)])
                if a[i][j+1]%2==1:
                    c=2
            elif c==1 and j==w-1 and i+1<=h-1:
                ans.append([str(i+1),str(j+1),str(i+2),str(j+1)])
                if a[i+1][j]%2==1:
                    c=2
    if i%2==1:
        for j in range(w):
            if c==0 and a[i][w-1-j]%2==1:
                c=1
            if c==2:
                c=0
            if c==1 and j<w-1:
                ans.append([str(i+1),str(w-j),str(i+1),str(w-j-1)])
                if a[i][w-j-2]%2==1:
                    c=2
            elif c==1 and j==w-1 and i+1<=h-1:
                ans.append([str(i+1),str(w-j),str(i+2),str(w-j)])
                if a[i+1][w-1-j]%2==1:
                    c=2
print(len(ans))
for i in ans:
    print(' '.join(i))

Solution (Python):
H,W=map(int,input().split())
A=[list(map(int,input().split())) for h in range(H)]
x=1
w=0
ans=[]
for h in range(H):
  while 0<=w+x<W:
    if A[h][w]%2==1:
      ans.append([h+1,w+1,h+1,w+x+1])
      A[h][w+x]+=1
    w+=x
  if A[h][w]%2==1 and h+1<H:
    ans.append([h+1,w+1,h+1+1,w+1])
    A[h+1][w]+=1
  x*=-1
print(len(ans))
for _ in ans:
  print(*_)

Solution (Python):
import sys

H, W = map(int, input().split())
A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)]

res = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 != 0 and j < W - 1:
            A[i][j] -= 1
            A[i][j + 1] += 1
            res.append([i + 1, j + 1, i + 1, j + 2])
        elif A[i][j] % 2 != 0 and i != H - 1 and j == W - 1:
            A[i][j] -= 1
            A[i + 1][j] += 1
            res.append([i + 1, j + 1, i + 2, j + 1])
print(len(res))
for i in range(len(res)):
    print(*res[i])

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    H, W = ZZ()
    A = [ZZ() for _ in range(H)]
    done = [[False] * W for _ in range(H)]
    path = []
    operation = []

    for i in range(H):
        if i%2:
            for j in range(W)[::-1]: path.append([i, j])
        else:
            for j in range(W): path.append([i, j])
    for i in range(H*W-1):
        x, y = path[i]
        nx, ny = path[i+1]
        if A[x][y]%2:
            operation.append([x, y, nx, ny])
            A[x][y] -= 1
            A[nx][ny] += 1

    print(len(operation))
    for i, j, k, l in operation: print(i+1, j+1, k+1, l+1)

    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]
used = [[-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()))

ans = []

for y in range(h):
    if y%2==0:
        for x in range(w):
            if maze[y][x]%2==0:
                continue
            else:
                if x<w-1:
                    ans.append([y+1,x+1,y+1,x+1+1])
                    maze[y][x+1]+=1
                elif y<h-1:
                    ans.append([y+1,x+1,y+1+1,x+1])
                    maze[y+1][x]+=1

    else:
        for x in reversed(range(w)):
            if maze[y][x]%2==0:
                continue
            else:
                if x>0:
                    ans.append([y+1,x+1,y+1,x+1-1])
                    maze[y][x-1]+=1
                elif y<h-1:
                    ans.append([y+1,x+1,y+1+1,x+1])
                    maze[y+1][x]+=1

print(len(ans))

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

Solution (Python):
h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
l=[]
for i in range(h):
 for j in range(w):
  if a[i][j]%2:
   if i+1<h:a[i][j]-=1;a[i+1][j]+=1;l.append((i+1,j+1,i+2,j+1))
   elif j+1<w:a[i][j]-=1;a[i][j+1]+=1;l.append((i+1,j+1,i+1,j+2))
print(len(l))
for i in l:print(*i)

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

Ans = []
i = 0
while(True):
    for j in range(W-1):

        if K[i][j]%2 == 1:
            K[i][j] -= 1
            K[i][j+1] += 1
            Ans.append((i+1, j+1, i+1, j+2))
    i += 1
    if i >= H:
        break
    if K[i-1][W-1] % 2 == 1:
        K[i-1][W-1] -= 1
        K[i][W-1] +=1
        Ans.append((i, W, i+1, W))
    for j in range(W-1, 0, -1):
        if K[i][j]%2 == 1:
            K[i][j] -= 1
            K[i][j-1] += 1
            Ans.append((i+1, j+1, i+1, j))
    i += 1
    if i >= H:
        break
    if K[i-1][0] % 2 == 1:
        K[i-1][0] -= 1
        K[i][0] += 1
        Ans.append((i, 1, i+1, 1))

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

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):
        if a[i][j]%2:
            if i+1<H:
                a[i][j]-=1
                a[i+1][j]+=1
                ans.append((i+1,j+1,i+2,j+1))
            elif j+1<W:
                a[i][j]-=1
                a[i][j+1]+=1
                ans.append((i+1,j+1,i+1,j+2))
print(len(ans))
for x in ans:
    print(*x)

Solution (Python):
h, w = map(int, input().split())
maze = []
def where(step):
    hh = step // w
    tmp = step - (w*hh)
    if hh % 2 == 0:
        ww = tmp
    else:
        ww = w-1-tmp
    return [hh, ww]

for _ in range(h):
    l = map(int, input().split())
    l = list(l)
    maze.append(l)

res = []
for i in range(h*w - 1):
    hh1, ww1 = where(i)
    hh2, ww2 = where(i+1)
    
    if maze[hh1][ww1] % 2 == 1:
        maze[hh2][ww2] += 1
        res.append((hh1,ww1,hh2,ww2))


print(len(res))
for i in range(len(res)):
    a,b,c,d = res[i]
    print(a+1,b+1,c+1,d+1)

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
def nxtij(i, j):
    if i & 1 == 0:
        if j < w - 1:
            return i, j + 1
        elif i < h - 1:
            return i + 1, j
        else:
            return None
    else:
        if j > 0:
            return i, j - 1
        elif i < h - 1:
            return i + 1, j
        else:
            return None

def ijgen():
    p = 0, 0
    while p:
        yield p
        p = nxtij(*p)
    return
ans = []
for i, j in ijgen():
    if a[i][j] & 1:
        p = nxtij(i, j)
        if p:
            a[p[0]][p[1]] += 1
            ans.append((i+1, j+1, p[0]+1, p[1]+1))
print(len(ans))
for a in ans:
    print(*a)

Solution (Python):
H, W = map(int, input().split())
G = [list(map(int, input().split())) for _ in range(H)]
ans = []
for h in range(H-1):
    for w in range(W):
        if G[h][w] % 2:
            ans.append([h+1, w+1, h+2, w+1])
            G[h][w] -= 1
            G[h+1][w] += 1
for w in range(W-1):
    if G[H-1][w] % 2:
        ans.append([H, w+1, H, w+2])
        G[H-1][w] -= 1
        G[H-1][w+1] += 1
print(len(ans))
for row in ans:
    print(*row)

Solution (Python):
H,W=map(int,input().split())
flg=0
flg2=0
bef=[];aft=[]
ans=[]
N=0
for i in range(H):
  flg+=1;flg%=2
  A=list(map(int,input().split()))
  if flg==1:
    for j in range(W):
      a=A[j]
      aft=[i+1,j+1]
      if a%2==0:
        if flg2==0:
          pass
        else:
          ans.append(bef+aft)
          N+=1
      else:
        if flg2==0:
          flg2=1
        else:
          ans.append(bef+aft)
          N+=1
          flg2=0
      bef=[i+1,j+1]
          
  else:
    for j in range(W-1,-1,-1):
      a=A[j]
      aft=[i+1,j+1]
      if a%2==0:
        if flg2==0:
          pass
        else:
          ans.append(bef+aft)
          N+=1
      else:
        if flg2==0:
          flg2=1
        else:
          ans.append(bef+aft)
          N+=1
          flg2=0
      bef=[i+1,j+1]
print(N)
for i in ans:
  print(*i)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    h,w = map(int,ipt().split())
    a = [[int(i) for i in ipt().split()] for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if a[i][j]&1:
                if j < w-1:
                    ans.append((i+1,j+1,i+1,j+2))
                    a[i][j+1] += 1
                elif i == h-1:
                    continue
                else:
                    ans.append((i+1,j+1,i+2,j+1))
                    a[i+1][j] += 1
    print(len(ans))
    for a1,a2,a3,a4 in ans:
        print(a1,a2,a3,a4)

    return

if __name__ == '__main__':
    main()

Solution (Python):

h,w = list(map(int,input().split()))
d = [list(map(int,input().split())) for i in range(h)]

ret=[]
ra = ret.append
for hi in range(h):
    for wi in range(w):
        if d[hi][wi]%2==1:
            if wi!=w-1:
                d[hi][wi]-=1
                d[hi][wi+1]+=1
                ra([hi,wi,hi,wi+1])
            else:
                if hi!=h-1:
                    d[hi][wi]-=1
                    d[hi+1][wi]+=1
                    ra([hi,wi,hi+1,wi])
                else:
                    pass

print(len(ret))
for i in ret:
    i = list(map(lambda x:x+1,i))
    print(" ".join(list(map(str,i))))

Solution (Python):
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def S(): return sys.stdin.readline().rstrip()

H,W = map(int,S().split())
a = [LI() for _ in range(H)]

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

print(len(ANS))

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

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


res = []
cnt = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if h == H - 1 and w == W - 1:
                continue
            elif a[h][w] % 2 == 1 and w != W - 1:
                cnt += 1
                res.append([h + 1, w + 1, h + 1,  w + 2])
                a[h][w + 1] += 1
            elif a[h][w] % 2 == 1 and w == W - 1:
                cnt += 1
                res.append([h + 1, w + 1, h + 2, w + 1])
                a[h + 1][w] += 1
            else:
                continue
    elif h % 2 == 1:
        for w in range(W-1, -1, -1):
            if h == H - 1 and w == 0:
                continue
            elif a[h][w] % 2 == 1 and w != 0:
                cnt += 1
                res.append([h + 1, w + 1, h + 1,  w])
                a[h][w - 1] += 1
            elif a[h][w] % 2 == 1 and w == 0:
                cnt += 1
                res.append([h + 1, w + 1, h + 2, w + 1])
                a[h + 1][w] += 1
            else:
                continue

print(cnt)
for v in res:
    print(*v)

Solution (Python):

def main():
    H, W = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(H)]
    A = [[i, j, k] for i, a in enumerate(A) for j, k in enumerate(a)]
    for i in range(W, len(A), 2 * W):
        A[i: i + W] = A[i + W - 1:i - 1:-1]
    i = 0
    ans = []
    count = 0
    while i < len(A):

        if A[i][2] % 2 != 0:
            j = 1
            while i + j < len(A):
                if A[i + j][2] % 2 != 0:
                    for k in range(i, i + j):
                        ans.append([A[k][0], A[k][1], A[k + 1][0], A[k + 1][1]])
                        count += 1
                    i += j
                    break
                j += 1
            else:
                break
        else:
            pass
        i += 1
    print(count)
    for a in ans:
        print(' '.join(list(map(lambda x: str(x + 1), a))))

if __name__ == '__main__':
    main()

Solution (Python):

H, W = [int(i) for i in input().split()]
A = [[]]
for i in range(H):
    a = [0] + [int(i) for i in input().split()]
    A.append(a)

print_list = []
for y in range(1, H+1):
    if y % 2 == 1:
        for x in range(1, W+1):
            coin_num = A[y][x]
            if coin_num % 2 == 1:
                if x < W:
                    A[y][x+1] += 1
                    A[y][x] -= 1
                    print_list.append([y, x, y, x+1])
                elif y < H:
                    A[y+1][x] += 1
                    A[y][x] -= 1
                    print_list.append([y, x, y+1, x])
    else:
        for x in range(W, 0, -1):
            coin_num = A[y][x]
            if coin_num % 2 == 1:
                if x > 1:
                    A[y][x-1] += 1
                    A[y][x] -= 1
                    print_list.append([y, x, y, x-1])
                elif y < H:
                    A[y+1][x] += 1
                    A[y][x] -= 1
                    print_list.append([y, x, y+1, x])
print(len(print_list))
for p in print_list:
    print(*p)

Solution (Python):
def resolve():
    H, W = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(H)]
    ops = []
    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
                else:
                    A[i][j] -= 1
                    A[i+1][j] += 1
                    ops.append([i+1, j+1, i+2, j+1])
            else:
                A[i][j] -= 1
                A[i][j+1] += 1
                ops.append([i+1, j+1, i+1, j+2])
    print(len(ops))
    [print(" ".join(map(str, op))) for op in ops]


if '__main__' == __name__:
    resolve()

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

res = []
for i in range(H-1):
    for j in range(W):
        if a[i][j]%2 !=0:
            a[i+1][j]+=1
            res.append((i+1,j+1,i+2,j+1))
for i in range(W-1):
    if a[-1][i]%2 !=0:
        a[-1][i+1] += 1
        res.append((H,i+1,H,i+2))
print(len(res))
for a,b,c,d in res:
    print(a,b,c,d)

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    ai = list(map(int,input().split()))
    a.append(ai)
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][-1] % 2 == 1:
        ans.append([i+1,w,i+2,w])
        a[i+1][-1] += 1
print(len(ans))
for i,j,k,l in ans:
    print(i,j,k,l)

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

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

for i in range(h-1):
    if a[i][w-1] % 2 == 0:
        pass
    else:
        n += 1
        ansl.append([i+1, w, i+2, w])
        a[i][w-1] -= 1
        a[i+1][w-1] += 1

print(n)
[print(*x) for x in ansl]

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

for i in range(W-1):
    if a[-1][i] % 2 == 1:
        a[-1][i+1] += 1
        output.append((H, i+1, H, i+2))
print(len(output))
for y, x, ay, ax in output:
    print(y, x, ay, ax)

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

N = 0
ans = []
for hi in range(H):
  for wi in range(W-1):
    if a[hi][wi]%2 == 1:
      N += 1
      a[hi][wi+1] += 1
      ans.append((hi+1, wi+1, hi+1, wi+2))
      
for hi in range(H-1):
  if a[hi][-1]%2 == 1:
    N += 1
    a[hi+1][-1] += 1
    ans.append((hi+1, W, hi+2, W))
    
print(N)
for y, x, yp, xp in ans:
  print(y, x, yp, xp)

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

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

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

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ans = []


def root(s, g):
    sx, sy = s
    gx, gy = g

    sx += 1
    sy += 1
    gx += 1
    gy += 1

    while sx != gx or sy != gy:
        if sy % 2 == 0 and sx == 1:
            ans.append((sy, sx, sy + 1, sx))
            sy += 1
        elif sy % 2 == 1 and sx == W:
            ans.append((sy, sx, sy + 1, sx))
            sy += 1
        else:
            if sy % 2 == 1:
                ans.append((sy, sx, sy, sx + 1))
                sx += 1
            else:
                ans.append((sy, sx, sy, sx - 1))
                sx -= 1


s = None
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if A[h][w] % 2 == 1:
                if s:
                    root(s, (w, h))
                    A[h][w] -= 1
                    A[s[1]][s[0]] += 1
                    s = None
                    pass
                else:
                    s = (w, h)
    else:
        for w in range(W - 1, -1, -1):
            if A[h][w] % 2 == 1:
                if s:
                    root(s, (w, h))
                    A[h][w] -= 1
                    A[s[1]][s[0]] += 1
                    s = None
                    pass
                else:
                    s = (w, h)


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

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

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

ans = []

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


print(len(ans))

for y1, x1, y2, x2 in ans:
    print("%d %d %d %d" % (y1, x1, y2, x2))

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 accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

cnt = 0
move = []
for i in range(H):
	for j in range(W):
		if i == H-1 and j == W-1:
			print(cnt)
			for x in move:
				print(*x)
			exit()
		if i%2 == 0:
			if a[i][j]%2 == 1 and j == W-1:
				a[i][j] -= 1
				a[i+1][j] += 1
				cnt += 1
				move.append((i+1, j+1, i+2, j+1))
			elif a[i][j]%2 == 1:
				a[i][j] -= 1
				a[i][j+1] += 1
				cnt += 1
				move.append((i+1, j+1, i+1, j+2))
		else:
			if a[i][W-j-1]%2 == 1 and j == W-1:
				a[i][W-j-1] -= 1
				a[i+1][W-j-1] += 1
				cnt += 1
				move.append((i+1, W-j, i+2, W-j))
			elif a[i][W-j-1]%2 == 1:
				a[i][W-j-1] -= 1
				a[i][W-j-2] += 1
				cnt += 1
				move.append((i+1, W-j, i+1, W-j-1))

Solution (Python):






from collections import defaultdict











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
A = [readInts() for _ in range(h)]
ans = []
cnt = 0
for y in range(h):
    for x in range(w):
        if A[y][x]%2:
            if x + 1 < w:
                cnt += 1
                A[y][x] -= 1
                A[y][x+1] += 1
                ans.append([y+1,x+1,y+1,x+2])

for y in range(h):
    if A[y][-1]%2:
        if y + 1 < h:
            cnt += 1
            A[y][-1] -= 1
            A[y+1][-1] += 1
            ans.append([y+1,w,y+2,w])
print(cnt)
for a in ans:
    print(*a)

Solution (Python):
H,W = map(int,input().split())
A = [[-1 for _ in range(W+2)]]
for _ in range(H):
    a = list(map(int,input().split()))
    a.insert(0,-1)
    a.append(-1)
    A.append(a)
for i in range(1,H+1):
    for j in range(1,W+1):
        A[i][j] = A[i][j]%2
row = 1
col = 1
cnt = 0
Op = []
while row<=H and col<=W:
    if row%2==1:
        if col<W and A[row][col]==0:
            col += 1
        elif col<W and A[row][col]==1:
            Op.append([row,col,row,col+1])
            cnt += 1
            A[row][col] = 0
            A[row][col+1] = (A[row][col+1]+1)%2
            col += 1
        elif col==W and A[row][col]==0:
            row += 1
        elif col==W and A[row][col]==1:
            if row<H:
                Op.append([row,col,row+1,col])
                cnt += 1
                A[row][col]=0
                A[row+1][col]=(A[row+1][col]+1)%2
            row += 1
    else:
        if col>1 and A[row][col]==0:
            col -= 1
        elif col>1 and A[row][col]==1:
            Op.append([row,col,row,col-1])
            cnt += 1
            A[row][col]=0
            A[row][col-1]=(A[row][col-1]+1)%2
            col -= 1
        elif col==1 and A[row][col]==0:
            row += 1
        elif col==1 and A[row][col]==1:
            if row<H:
                Op.append([row,col,row+1,col])
                cnt += 1
                A[row][col]=0
                A[row+1][col]=(A[row+1][col]+1)%2
            row += 1
print(cnt)
for i in range(cnt):
    print(*Op[i])

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
 
h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(map(int,input().split())))
ans = []
flag = 1
for i in range(h):
    if flag:
        for j in range(w):
            if j == w - 1:
                flag ^= 1
                if i != h - 1 and a[i][j] % 2 == 1: 
                    ans.append([i + 1, j + 1, i + 2, j + 1])
                    a[i + 1][j] += 1
            elif a[i][j] % 2 == 1:
                ans.append([i + 1, j + 1, i + 1, j + 2])
                a[i][j + 1] += 1
    else:
        for j in range(w - 1, -1, -1):
            if j == 0:
                flag ^= 1
                if i != h - 1 and a[i][j] % 2 == 1:
                    ans.append([i + 1, j + 1, i + 2, j + 1])
                    a[i + 1][j] += 1
            elif a[i][j] % 2 == 1:
                ans.append([i + 1, j + 1, i + 1, j])
                a[i][j - 1] += 1
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):
H, W = map(int, input().split())
field = [list(map(int, input().split())) for _ in range(H)]
ans = []
for i in range(H):
    for j in range(W):
        if field[i][j] % 2 == 0:
            continue
        found = False
        for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < H and 0 <= nj < W and field[ni][nj] % 2:
                field[i][j] -= 1
                field[ni][nj] += 1
                found = True
                ans.append((i + 1, j + 1, ni + 1, nj + 1))
                break
        if not found:
            for di, dj in ((1, 0), (0, 1)):
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and field[ni][nj] % 2 == 0:
                    field[i][j] -= 1
                    field[ni][nj] += 1
                    ans.append((i + 1, j + 1, ni + 1, nj + 1))
                    break
print(len(ans))
[print(i, j, ni, nj) for i, j, ni, nj in ans]

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    h,w=map(int,readline().split())
    a=[list(map(int,readline().split())) for _ in range(h)]

    i=0
    j=0
    n=0
    ans=[]
    while True:
        if i%2==0:
            if j<w-1:
                if a[i][j]%2==1:
                    n+=1
                    ans.append([i+1,j+1,i+1,j+2])
                    a[i][j+1]+=1
                j+=1
            elif j==w-1:
                if i<h-1:
                    if a[i][j]%2==1:
                        n+=1
                        ans.append([i+1,j+1,i+2,j+1])
                        a[i+1][j]+=1
                    i+=1
                else:
                    break
        else:
            if j>0:
                if a[i][j]%2==1:
                    n+=1
                    ans.append([i+1,j+1,i+1,j])
                    a[i][j-1]+=1
                j-=1
            elif j==0:
                if i<h-1:
                    if a[i][j]%2==1:
                        n+=1
                        ans.append([i+1,j+1,i+2,j+1])
                        a[i+1][j]+=1
                    i+=1
                else:
                    break

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

if __name__=="__main__":
    main()

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

cnt = 0
X = []
for i in range(h):
    for j in range(w):
        if A[i][j]%2 ==1:
            if j != w-1:
                cnt += 1
                X.append((i+1, j+1, i+1, j+2))
                A[i][j+1] += 1
            else:
                if i != h-1:
                    cnt += 1
                    X.append((i+1, j+1, i+2, j+1))
                    A[i+1][j] += 1
print(cnt)
for x in X:
    print(*x)

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


ans = []
for i in range(H):

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

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [[int(a) for a in input().split()] for _ in range(H)]
    Ans = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 1:
                if w < W - 1:
                    A[h][w] -= 1
                    A[h][w+1] += 1
                    Ans.append((h+1, w+1, h+1, w+2))
                else:
                    if h < H - 1:
                        A[h][w] -= 1
                        A[h+1][w] += 1
                        Ans.append((h+1, w+1, h+2, w+1))
    count = len(Ans)
    print(count)
    for i in range(count):
        print(*Ans[i], sep=" ")
    

    return 0

if __name__ == "__main__":
    solve()

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

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

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

print(len(ans))
for h, w, x, y in ans:
    print(h + 1, w + 1, x + 1, y + 1)