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())
aij = [[int(i) for i in input().split()] for j in range(h)]

move = []

"""
for i in range(w-1,-1,-1):
    print(i)
""" 
 
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if aij[i][j] % 2 == 1:
                if j == w-1:
                    if i == h-1:
                        break
                    move.append([[i+1,j+1],[i+1+1,j+1]])
                    aij[i+1][j] += 1
                else:
                    move.append([[i+1,j+1],[i+1,j+1+1]])
                    aij[i][j+1] += 1
    else:
        for j in range(w-1,-1,-1):
            if aij[i][j] % 2 == 1:
                if j == 0:
                    if i == h-1:
                        break
                    move.append([[i+1,j+1],[i+1+1,j+1]])
                    aij[i+1][j] += 1
                else:
                    move.append([[i+1,j+1],[i+1,j+1-1]])
                    aij[i][j-1] += 1


print(len(move))

for i in range(len(move)):
    for j in range(len(move[i])):
        print(*move[i][j],end='')
        if j == 1:
            continue
        print(end=' ')
    print()

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

N=0
ans=[]
for i in range(H):
    for j in range(W):
        if a[i][j]%2==1:
            if j<W-1:
                a[i][j]-=1
                a[i][j+1]+=1
                N+=1
                ans.append([i+1,j+1,i+1,j+2])
            elif i<H-1:
                a[i][j]-=1
                a[i+1][j]+=1
                N+=1
                ans.append([i+1,j+1,i+2,j+1])
print(N)
for a in ans:
    for k in range(4):
        if k<3:
            print(a[k],end=" ")
        else:
            print(a[k])

Solution (Python):
def line_mainte(A,h):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append(str(h)+" "+str(i+1)+" "+str(h)+" "+str(i+2))
    return (len(output),output)

def row_mainte(A,w):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))
    return (len(output),output)

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

count,procedure = 0,[]
for i in range(H):
    tmp = line_mainte(a[i],i+1)
    count += tmp[0]
    procedure += tmp[1]
row_W = [a[i][W-1] for i in range(H)]
tmp = row_mainte(row_W,W)
count += tmp[0]
procedure += tmp[1]

print(count)
for i in range(len(procedure)):
    print(procedure[i])

Solution (Python):
def line_mainte(A,h):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append((h,i+1,h,i+2))
    return (len(output),output)

def row_mainte(A,w):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append((i+1,w,i+2,w))
    return (len(output),output)

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

count,procedure = 0,[]
for i in range(H):
    tmp = line_mainte(a[i],i+1)
    count += tmp[0]
    procedure += tmp[1]
row_W = [a[i][W-1] for i in range(H)]
tmp = row_mainte(row_W,W)
count += tmp[0]
procedure += tmp[1]

print(count)
for i in range(len(procedure)):
    for j in range(4):
        if j != 3:
            print(procedure[i][j],end=" ")
        else:
            print(procedure[i][j])

Solution (Python):
h, w = map(int, input().split())
lis = [] * h
for i in range(h):
    lis.append(tuple(map(int, input().split())))
flg = False
res = []
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if not flg and lis[i][j] % 2 == 1:
                res.append(i+1)
                res.append(j+1)
                flg = not flg
            elif flg and lis[i][j] % 2 == 0:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                res.append(i+1)
                res.append(j+1)
            elif flg and lis[i][j] % 2 == 1:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                flg = not flg
    else:
        for j in range(w -1, -1, -1):
            if not flg and lis[i][j] % 2 == 1:
                res.append(i + 1)
                res.append(j + 1)
                flg = not flg
            elif flg and lis[i][j] % 2 == 0:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                res.append(i + 1)
                res.append(j + 1)
            elif flg and lis[i][j] % 2 == 1:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                flg = not flg
print(len(ans))
for a in ans:
    print(*a)

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

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

i = 0
j = 0
direction = 'r'
ans = []
route = []
is_selected = False
cnt = 0
while True:
    if cnt >= h * w:
        break
    next_i = i
    next_j = j
    if j == 0 and direction == 'l':
        next_i = i + 1
        direction = 'r'
    elif j == w-1 and direction == 'r':
        next_i = i + 1
        direction = 'l'
    else:
        if direction == 'r':
            next_j += 1
        else:
            next_j -= 1

    if a[i][j] % 2 == 1:
        if is_selected:
            ans.extend(route)
            route = []
            is_selected = False
        else:
            route.append([i+1, j+1, next_i+1, next_j+1])
            is_selected = True
    else:
        if is_selected:
            route.append([i+1, j+1, next_i+1, next_j+1])
    i = next_i
    j = next_j
    cnt += 1


print(len(ans))
for i in range(len(ans)):
    print(" ".join(list(map(str, ans[i]))))

Solution (Python):
from sys import stdin
H,W = [int(x) for x in stdin.readline().rstrip().split()]
A = []
for i in range(H):
    a = [int(x) for x in stdin.readline().rstrip().split()]
    A.append(a)
    
ans = []

f = False
route = [0,0,0,0]
tmp = []
l = True

for h in range(H):
    for w in range(W):
        if h % 2 == 1:
            w = W-w-1
        if A[h][w] % 2 != 0:
            if not f:
                route[0],route[1] = h+1,w+1
                f = True
            else:
                route[2],route[3] = h+1,w+1
                tmp.append(route)
                route = [0,0,0,0]
                ans += tmp
                tmp = []
                f = False
        else:
            if f:
                route[2],route[3] = h+1,w+1
                tmp.append(route)
                route = [h+1,w+1,0,0]
print(len(ans))
for a,b,c,d in ans:
    print(a,b,c,d)

Solution (Python):


import math





H,W = list(map(int,input().split(" ")))
x1 = 0
y1 = 0
x2 = 0
y2 = 0
cond = 0
mass = []
for _ in range(H):
    mass.append(list(map(int, input().split(" "))))

s = [0]
def move(sx,sy,gx,gy):
    temp = []
    go = -1
    if sy % 2 == 1:
        go = 1 
    x = sx
    y = sy
    while True:

        

        if (x == W and go == 1) or (x == 1 and go == -1): 
            ny = y + 1
            temp.append([y, x, ny, x])
            s[0] += 1
            y = ny 
            go *= -1
            if x == gx and y == gy:
                return temp



        nx = x + go
        temp.append([y, x, y, nx])
        s[0] += 1
        x = nx

        
        if  x == gx and  y ==gy:
            return temp






ans = []
for y,As in enumerate(mass):
    if y %2 == 0:
        start = 0
        end = W
        hoge = 1
    else:
        start = W-1
        end = -1
        hoge = -1
    for i in range(start,end,hoge):
        a = As[i]
        if a % 2 == 1:
            if cond %2 == 0:
                x1 = i + 1
                y1 = y + 1
                cond += 1
            else:
                x2 = i + 1
                y2 = y + 1
                ans.append(move(x1,y1,x2,y2))
                
                
                
                
                
                
                
                
                
                
                
                
                cond += 1

print(s[0])
for temp in ans:
    for temp2 in temp:
        print(*temp2 )

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


cnt = 0
ope=[]
for y in range(H):
    if y != H -1:
        for x in range(W):
            if a[y][x] % 2 == 1:
                a[y][x] -= 1
                a[y + 1][x] += 1
                cnt += 1
                ope.append([y+1,x+1,y+1+1,x+1])
    else:
        for x in range(W-1):
            if a[y][x] % 2 == 1:
                a[y][x] -= 1
                a[y][x+1] += 1
                cnt += 1
                ope.append([y+1,x+1,y+1,x+1+1])
print(cnt)
for el in ope:
    print(' '.join(list(map(str, el))))

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

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


for i in range(len(B)-1):
  a,x,y=B[i][0], B[i][1], B[i][2]
  if a%2==1:
    B[i+1][0]+=1
    ans.append((x,y,B[i+1][1], B[i+1][2]))
print(len(ans))  
for a,b,c,d in ans:
  print(a+1,b+1,c+1,d+1)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    h,w = map(int, input().split())
    d = []
    for _ in range(h):
        d.append(list(map(int, input().split())))
    
    res = []
    for i in range(h):
        for j in range(w):
            if j == w-1 and i < h-1:
                if d[i][j]%2 == 1:
                    res.append([i+1, j+1, i+2, j+1])
                    d[i+1][j] += 1
                continue
            if d[i][j]%2 == 1 and j < w-1:
                res.append([i+1, j+1, i+1, j+2])
                d[i][j+1] += 1
    print(len(res))
    for i in res:
        print(*i)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    h,w = map(int, input().split())
    d = []
    for _ in range(h):
        d.append(list(map(int, input().split())))
    
    res = []
    for i in range(h):
        for j in range(w):
            if j == w-1 and i < h-1:
                if d[i][j]%2 == 1:
                    res.append([i+1, j+1, i+2, j+1])
                    d[i+1][j] += 1
                continue
            if d[i][j]%2 == 1 and j < w-1:
                res.append([i+1, j+1, i+1, j+2])
                d[i][j+1] += 1
    print(len(res))
    for i in res:
        print(*i)

if __name__ == '__main__':
    main()

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

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            elif 0<=i+1<h:
                C.append([i,j,i+1,j])
                A[i+1][j] +=1

print(len(C))
for i in C:
    print(*list(map(lambda x:x+1,i)))

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

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i+1,j+1,i+1,j+flag+1])
                A[i][j+flag] +=1
            elif 0<=i+1<h:
                C.append([i+1,j+1,i+2,j+1])
                A[i+1][j] +=1

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

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


hold=0
ans=[]
for i in range(h):
    if i&1:
        for j in range(w-1,-1,-1):
            
            if hold:
                if a[i][j]:
                    a[i][j]=0
                    hold=0
                else:
                    if j==0 and i!=h-1:

                        ans.append((i+1,j+1,i+2,j+1))
                    elif j>0:

                        ans.append((i+1,j+1,i+1,j))
            else: 
                if a[i][j]:
                    hold=1
                    a[i][j]=0
                    if j==0 and i!=h-1:
 
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j>0:
  
                        ans.append((i+1,j+1,i+1,j))
    else:
        for j in range(w):
            if hold:
                if a[i][j]:
                    a[i][j]=0
                    hold=0
                else:
                    if j==w-1 and i!=h-1:
   
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j!=w-1:
    
                        ans.append((i+1,j+1,i+1,j+2))
            else:
                if a[i][j]:
                    hold=1
                    a[i][j]=0
                    if j==w-1 and i!=h-1:
     
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j!=w-1:
      
                        ans.append((i+1,j+1,i+1,j+2))
print(len(ans))
for i in ans:
    print(' '.join(map(str,i)))

Solution (Python):
def inpl(): return list(map(int, input().split()))
H,W = inpl()
MAP = [inpl() for i in range(H)]
flag = False 
ans = []
for y in range(H):
    if y%2 == 0:
        xx = range(W)
    else:
        xx = reversed(range(W))
    for x in xx:
        if flag:
            ans.append([by,bx,y,x])
        if MAP[y][x]%2 == 1:
            flag = not flag
        bx,by = x,y
print(len(ans))
for a,zu,nya,n in ans:
    print(a+1,zu+1,nya+1,n+1)

Solution (Python):
h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
answer = []
count = 0
for i in range (0,h-1):
    for j in range (0,w):
        if (a[i][j] % 2 != 0):
            a[i+1][j] += 1
            count += 1
            answer.append([i+1,j+1,i+2,j+1]) 
for k in range (0,w-1):
    if (a[h-1][k] % 2 != 0):
        a[h-1][k+1] += 1
        count += 1
        answer.append([h,k+1,h,k+2]) 
print(count)
for l in range (0,len(answer)):
    print(*answer[l])

Solution (Python):
h, w = map(int, input().split())

GRID = [["
for _ in range(h):
    GRID.append(["
GRID.append(["

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

n = 0
OPERATIONS = []
for k in range(h * w - 1):
    a, b = PATH[k]; c, d = PATH[k + 1]
    if GRID[a][b] % 2 == 1:
        GRID[a][b] -= 1; GRID[c][d] += 1
        n += 1
        OPERATIONS.append((a, b, c, d))

print(n)
for operation in OPERATIONS:
    print(*operation)

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):
  if i%2==0:
    for j in range(w):
      l.append((i,j))
  else:
    for j in range(w)[::-1]:
      l.append((i,j))
ans=[]

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

Solution (Python):


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

    hold = False
    opers = []
    for i in range(h):
        jlist = range(w) if i % 2 == 0 else reversed(range(w))
        for j in jlist:
            if not (i == j == 0):
                if hold:
                    opers.append((ipre + 1, jpre + 1, i + 1, j + 1))
            hold = (hold != (a[i][j] % 2 == 1))
            ipre = i
            jpre = j
    print(len(opers))
    for o in opers:
        p, q, r, s = o
        print(p, q, r, s)

if __name__ == "__main__":
    main()

Solution (Python):


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

    stroke = []
    direction = 1
    for i in range(w):
        if direction == 1:
            st, ed = 0, h
        else:
            st, ed = h - 1, -1
        for j in range(st, ed, direction):
            stroke.append((j, i))
        st, ed = ed, st
        direction *= -1

    moves = []
    cnt = 0
    for s, e in zip(stroke, stroke[1:]):
        if a[s[0]][s[1]] % 2:
            cnt += 1
            moves.append((s, e))
            a[e[0]][e[1]] += 1
    
    print(cnt)
    for s, e in moves:
        print("{} {} {} {}".format(s[0] + 1, s[1] + 1, e[0] + 1, e[1] + 1))


submit()

Solution (Python):
h,w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(map(int,input().split())))
ans = []
for i in range(h):
    for j in range(w):
        if j == w-1:
            if grid[i][j] % 2 == 1 and i != h-1:
                grid[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
        elif grid[i][j] % 2 == 1:
            grid[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])
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 h in range(H)]

ans = []

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


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

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

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

ans = []
flag = False

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

print(len(ans))
for i in ans:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

Solution (Python):


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

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

for i in range(H):
    for j in range(W):
        if i == H-1 and j == W-1:
            break
            
        elif A[i][j]%2 == 1:          
            if j == W-1:
                A[i][j] -= 1
                A[i+1][j] += 1
                ans_loc.append((i+1, j+1, i+2, j+1))
            else:
                A[i][j] -= 1
                A[i][j+1] += 1
                ans_loc.append((i+1, j+1, i+1, j+2))
            
print(len(ans_loc))
for i in ans_loc:
    print(' '.join(map(str, i)))

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

A = []

for i in range(H):
    A.append(list(map(int, input().split())))
    
ans_loc = []
ans_count = 0

for i in range(H):
    for j in range(W):
        if i == H-1 and j == W-1:
            break
        elif i%2 == 0:
            x = j
            y = i
            if j == W-1:
                x_d = 0
                y_d = 1
            else:
                x_d = 1
                y_d = 0
             
        else:
            x = (W-j-1)
            y = i
            if j == W-1:
                x_d = 0
                y_d = 1
            else:
                x_d = -1
                y_d = 0
                
        if A[y][x]%2 == 1:
            A[y][x] -= 1
            A[y+y_d][x+x_d] += 1
            ans_loc.append((y+1,x+1,y+y_d+1,x+x_d+1))
            ans_count += 1

print(ans_count)

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

Solution (Python):
import numpy as np
import sys

H, W = map(int, input().split())
I = np.array(sys.stdin.read().split(), np.int64).reshape(H,-1)
grid = np.zeros([H,W])
grid[np.where(I%2==1)] = 1

h_move = np.zeros([H,W-1])
s = np.zeros(H)
for i in range(H):
	cond = 0
	for j in range(W):
		if cond == 0:
			if grid[i,j] == 0:
				continue
			else:
				if j == W-1:
					s[i] = 1
				else:
					h_move[i,j] = 1
					cond = 1
		else:
			if grid[i,j] == 0:
				if j == W-1:
					s[i] = 1
				else:
					h_move[i,j] = 1
			else:
				cond = 0
	
v_move = np.zeros(H)
cond = 0
for i in range(H-1):
	if cond == 0:
		if s[i] == 0:
			continue
		else:
			v_move[i] = 1
			cond = 1
	else:
		if s[i] == 0:
			v_move[i] = 1
		else:
			cond = 0

n = h_move.sum() + v_move.sum()

print(int(n))
for i in range(H):
	for j in range(W-1):
		if h_move[i,j] == 1:
			print(i+1,j+1,i+1,j+2)
for i in range(H-1):
	if v_move[i] == 1:
		print(i+1,W,i+2,W)

Solution (Python):
h, w = map(int, input().split())
a = [0]*h
for i in range(h):
  a[i] = [int(x)%2 for x in input().split()]

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

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

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

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

Solution (Python):

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

def get_next():
    for h in range(H):
        if h % 2:
            for w in range(W-1, -1, -1):
                yield h, w
        else:
            for w in range(W):
                yield h, w


ret = []
routes = list(get_next())
prv_h, prv_w = routes[0]
for h, w in routes[1:]:
    if table[prv_h][prv_w] % 2:
        ret.append((prv_h, prv_w, h, w))
        table[h][w] += 1

    prv_h, prv_w = h, w


print(len(ret))
for prv_h, prv_w, h, w in ret:
    print(prv_h + 1, prv_w + 1, h + 1, w + 1)

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

oplist=[]
for i in range(H):
  for j in range(W):
    if mat[i][j]%2==1:
      if i==H-1 and j==W-1:
        break
      if j==W-1:
        mat[i][j]-=1
        mat[i+1][j]+=1
        oplist.append([i+1,j+1,i+2,j+1])
      else:
        mat[i][j]-=1
        mat[i][j+1]+=1
        oplist.append([i+1,j+1,i+1,j+2])
        
print(len(oplist))
for op in oplist:
  op_str=map(str,op)
  print(" ".join(op_str))

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,w = inm()
a = []
seq = []
for i in range(h):
    a.append(inl())
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            seq.append((i,j,i,j+1))
            a[i][j+1] += 1
    if a[i][w-1]%2==1 and i<h-1:
        seq.append((i,w-1,i+1,w-1))
        a[i+1][w-1] += 1
print(len(seq))
for z in seq:
    print("{} {} {} {}".format(z[0]+1,z[1]+1,z[2]+1,z[3]+1))

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

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

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

N=len(ans)
print(N)
for i in range(0,N):
    x,y,z,w=ans[i]
    print(x+1,y+1,z+1,w+1)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
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 STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
a = [LIST() for _ in range(h)]
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 == 1:
                y = i
                x = j + 1
                if x >= w:
                    y += 1
                    x = w - 1
                if y < h:
                    a[y][x] += 1
                    ans.append([str(i + 1), str(j + 1), str(y + 1), str(x + 1)])
    else:
        for j in reversed(range(w)):
            if a[i][j] % 2 == 1:
                y = i
                x = j - 1
                if x < 0:
                    y += 1
                    x = 0
                if y < h:
                    a[y][x] += 1
                    ans.append([str(i + 1), str(j + 1), str(y + 1), str(x + 1)])
print(len(ans))
for i in range(len(ans)):
    print(' '.join(ans[i]))