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

Solution (Python):
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
for i in range(H):
    for j in range(W):
        A[i][j] = A[i][j]%2
flag=0
for i in range(H):
    if i%2==0:
        for j in range(W):
            if A[i][j]==1:
                cur = (i,j)
                flag=1
                break
        if flag==1:break
    else:
        for j in range(W-1,-1,-1):
            if A[i][j]==1:
                cur = (i,j)
                flag = 1
                break
        if flag==1:break
B = []
if flag==0:
    N=0
else:
    i,j = cur
    ind = 1
    while i<H:
        if i%2==0:
            while j<W:
                if j==W-1:
                    if ind==1 and i<H-1:
                        B.append([(i,j),(i+1,j)])
                    i += 1
                    if i<H and A[i][j]==1:
                        ind = 1-ind
                    break
                else:
                    if ind==1:
                        B.append([(i,j),(i,j+1)])
                    j += 1
                    if A[i][j]==1:
                        ind = 1-ind
        else:
            while j>=0:
                if j==0:
                    if ind==1 and i<H-1:
                        B.append([(i,j),(i+1,j)])
                    i += 1
                    if i<H and A[i][j]==1:
                        ind = 1-ind
                    break
                else:
                    if ind==1:
                        B.append([(i,j),(i,j-1)])
                    j -= 1
                    if A[i][j]==1:
                        ind = 1-ind
    N = len(B)
print(N)
for i in range(N):
    (i1,j1),(i2,j2)=B[i]
    print(i1+1,j1+1,i2+1,j2+1)

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


ans=[]
count=0
for h in range(H):
    for w in range(W):
        if h%2==1:
            w=W-1-w
        if h==0 and w==0:
            px,py=0,0
            pre=0
            if A[h][w]%2==0:
                continue
            else:
                A[h][w]-=1
                pre=1
        else:
            if pre>0:
                A[h][w]+=pre
                pre=0
                ans.append([px+1,py+1,h+1,w+1])
                count+=1
            if A[h][w]%2==1:
                A[h][w]-=1
                pre=1
                px,py=h,w


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

Solution (Python):

def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i+1, j+1, i+1, j+2])
                    a[i][j+1] += 1
                    a[i][j] -= 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] % 2 == 0:
                continue
            else:
                ans.append([i+1, j+1, i+2, j+1])
                a[i+1][w-1] += 1
                a[i][w-1] -= 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()

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):
    if i%2:
        for j in range(W-1,0,-1):
            if a[i][j]%2:
                a[i][j] -= 1
                a[i][j-1] += 1
                ans.append([i+1,j+1,i+1,j])
        if i != H-1 and a[i][0]%2:
            a[i][0] -= 1
            a[i+1][0] += 1
            ans.append([i+1,1,i+2,1])

    else:
        for j in range(W-1):
            if a[i][j]%2:
                a[i][j] -= 1
                a[i][j+1] += 1
                ans.append([i+1,j+1,i+1,j+2])
        if i != H-1 and a[i][W-1]%2:
            a[i][W-1] -= 1
            a[i+1][W-1] += 1
            ans.append([i+1,W,i+2,W])
print(len(ans))
for an in ans:
    print(' '.join(map(str,an)))

Solution (Python):
import sys
from collections import Counter
from collections import deque
import math
import fractions
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
g=[lmp() for i in range(h)]
step=[]
for i in range(h):
    if i%2==0:
        for k in range(w):
            step.append([i,k])
    else:
        for k in range(w):
            step.append([i,w-k-1])
ans=[]
for i in range(len(step)-1):
    if g[step[i][0]][step[i][1]]%2==1:
        g[step[i][0]][step[i][1]]-=1
        g[step[i+1][0]][step[i+1][1]]+=1
        ans.append([step[i][0]+1,step[i][1]+1,step[i+1][0]+1,step[i+1][1]+1])
print(len(ans))
for a in ans:
    print(*a)

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

Solution (Python):
import sys
from collections import Counter, deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = []
    for h in range(H):
        for w in range(W) if h % 2 == 0 else reversed(range(W)):
            if h % 2 == 0:
                if A[h][w] % 2:
                    if w == W - 1:
                        if h == H - 1:
                            continue
                        else:
                            A[h][w] -= 1
                            A[h + 1][w] += 1
                            res.append([h + 1, w + 1, h + 2, w + 1])
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        res.append([h + 1, w + 1, h + 1, w + 2])
            else:
                if A[h][w] % 2:
                    if w == 0:
                        if h == H - 1:
                            continue
                        else:
                            A[h][w] -= 1
                            A[h + 1][w] += 1
                            res.append([h + 1, w + 1, h + 2, w + 1])
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        res.append([h + 1, w + 1, h + 1, w])
    print(len(res))
    for i in res:
        print(*i)



if __name__ == '__main__':
    resolve()

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

ans_num=0
ans_l=[]
for i in range(h):
  for j in range(w):
    if j!=w-1:
      if l[i][j]%2==1:
        l[i][j]-=1
        l[i][j+1]+=1
        ans_num+=1
        ans_l.append([i+1,j+1,i+1,j+1+1])
    elif i!=h-1:
      if l[i][j]%2==1:
        l[i][j]-=1
        l[i+1][j]+=1
        ans_num+=1
        ans_l.append([i+1,j+1,i+1+1,j+1])


print(ans_num)
for i in ans_l:
  print(*i)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    h, w = ns()
    mat = [na() for _ in range(h)]

    n = 0
    ans = []
    for y in range(h):
        for x in range(w - 1):
            if mat[y][x] % 2:
                mat[y][x] -= 1
                mat[y][x + 1] += 1
                ans.append((y + 1, x + 1, y + 1, x + 1 + 1))
                n += 1

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

    print(n)
    for item in ans:
        print(*item, sep=" ")


if __name__ == '__main__':
    main()

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

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

ans = []

dp = [ list ( map(int,input().split()) )  for i in range(H)]

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

ni=0
nj=0
st=0
sw=0
lis = []
while (True):
    
    tmp =[]
    if a[ni][nj]%2==1:
        st=1
        tmp.extend([ni+1,nj+1])
    if sw==0 and nj<w-1:
        nj+=1
    elif sw==1 and nj>0:
        nj-=1
    elif nj==w-1 or nj==0:
        ni+=1
        sw=1-sw
    
    if ni>h-1:
        break
    if st==1:
        a[ni][nj]+=1
        tmp.extend([ni+1,nj+1])
        lis.append(tmp)
    st=0
print(len(lis))
for i in range(len(lis)):
    print(*lis[i])

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

result = []
y = 0
while y < H:
    x = 0
    while x < W:
        if a[y][x] % 2 == 1:
            if x == W - 1:
                if y == H - 1:
                    break
                else:
                    result.append('%d %d %d %d' % (y + 1, x + 1, y + 2, x + 1))
                    a[y + 1][x] += 1
            else:
                result.append('%d %d %d %d' % (y + 1, x + 1, y + 1, x + 2))
                a[y][x + 1] += 1
        x += 1
    if y == H - 1:
        break
    y += 1
    x = W - 1
    while x >= 0:
        if a[y][x] % 2 == 1:
            if x == 0:
                if y == H - 1:
                    break
                else:
                    result.append('%d %d %d %d' % (y + 1, x + 1, y + 2, x + 1))
                    a[y + 1][x] += 1
            else:
                result.append('%d %d %d %d' % (y + 1, x + 1, y + 1, x))
                a[y][x - 1] += 1
        x -= 1
    y += 1

print(len(result))
print('\n'.join(result))

Solution (Python):






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

    operates = []
    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
                operates.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
        if i < H-1 and a[i][-1] % 2 == 1:
            a[i][-1] -= 1
            a[i+1][-1] += 1
            operates.append("{} {} {} {}".format(i+1, W, i+2, W))

    N = len(operates)
    print(N)
    for i in range(N):
        print(operates[i])


main()

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

Solution (Python):
def nxt(y, x, h, w):
    if y % 2 == 0:
        if x < w - 1:
            yn, xn = y, x + 1
        else:
            yn, xn = y + 1, w - 1
    else:
        if x > 0:
            yn, xn = y, x - 1
        else:
            yn, xn = y + 1, 0
    return yn, xn


h, w = map(int, input().split())
a = []

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

ret = []

for i in range(h * w - 1):
    y = i // w
    if y % 2 == 0:
        x = i % w
    else:
        x = w - 1 - (i % w)
    if a[y][x] % 2 != 0:
        yn, xn = nxt(y, x, h, w)
        ret.append((y+1, x+1, yn+1, xn+1))
        a[yn][xn] += 1

print(len(ret))
for item in ret:
    print(' '.join(map(str, item)))

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

a = [[2]*(W+2)]
pos = []
for i in range(H):
    aa = list(map(int, input().split()))
    aaa = [ai%2 for ai in aa]
    a.append([2] + aaa + [2])
a.append([2]*(W+2))

temp = [[1, 1]]
visited = [[0]*(W+2) for _ in range(H+2)]
visited[1][1] = 1
ans = []
while temp:
    q = temp.pop()
    if a[q[0]][q[1]] % 2 == 1:
        old = q[:]
        da = 1
    else:
        old = [-1, -1]
        da = 0
        
    for dy, dx in [[0, 1], [0, -1], [1, 0]]:
        nxt = a[q[0]+dy][q[1]+dx]
        if nxt == 2 or visited[q[0]+dy][q[1]+dx] == 1: continue
        else:
            temp.append([q[0]+dy, q[1]+dx])
            visited[q[0]+dy][q[1]+dx] = 1
            if old != [-1, -1]: ans.append([old[0], old[1], q[0]+dy, q[1]+dx])
            a[q[0]+dy][q[1]+dx] += da
            break

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




H, W = mi()
S = [li() for _ in range(H)]
f = 0
ans = []

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




H, W = mi()
S = [li() for _ in range(H)]
f = 0
ans = []

for j in range(W):
    if not j%2:
        for i in range(H):
            if f:
                ans.append([pi, pj, i+1, j+1])
            if S[i][j] % 2:
                f = 1 - f
            pi, pj = i+1, j+1
    if j%2:
        for i in reversed(range(H)):
            if f:
                ans.append([pi, pj, i+1, j+1])
            if S[i][j] % 2:
                f = 1 - f
            pi, pj = i+1, j+1


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

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

Solution (Python):
H, W = map(int, input().split())
state = False
moves = []
ans = []
for i in range(H):
    row = tuple(zip(range(W), map(int, input().split())))
    for j, a in reversed(row) if i & 1 else row:
        if a & 1:
            state = not state
            if not state:
                moves.append((i + 1, j + 1))
                for pair in zip(moves[:-1], moves[1:]):
                    ans.append(sum(pair, tuple()))
                moves = []
        if state:
            moves.append((i + 1, j + 1))
print(len(ans))
for a in ans:
    print(*a)

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

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

ans = []
isFromExist = False
x = 0
y = 0
vec = 1
count = 0
while count < H*W:
    if not isFromExist:
        if As[y][x] % 2 == 1:
            from_yx = [y, x]
            isFromExist = True
    else:
        now = [y, x]
        ans.append(from_yx + now)
        if As[y][x] % 2 == 1:
            isFromExist = False
        else:
            from_yx = now

    if vec == 1 and x == W-1:
        vec = -1
        y += 1
    elif vec == -1 and x == 0:
        vec = 1
        y += 1
    else:
        x += vec * 1
    count += 1


N = len(ans)
print(N)
for i in range(N):
    for j in range(4):
        if j == 3:
            print(ans[i][j] + 1)
        else:
            print(ans[i][j] + 1, '', end='')

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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

H, W = getNM()
maze = []
for i in range(H):
    a = getList()
    maze.append(a)

ans = []


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


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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


h, w = Is()
A = LIR(h)
ANS = []
for i in range(h-1):
    for j in range(w):
        if A[i][j] % 2 != 0:
            ANS.append((i, j, i+1, j))
            A[i+1][j] += 1

for j in range(w-1):
    if A[h-1][j] % 2 != 0:
        ANS.append((h-1, j, h-1, j+1))
        A[h-1][j+1] += 1

print(len(ANS))
for x, y, xd, yd in ANS:
    print("{} {} {} {}".format(x+1, y+1, xd+1, yd+1))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w=map(int,input().split())
    A=[[int(_) for _ in input().split()] for i in range(h)]
    ans=[]
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if A[i][j]%2==1:
                    if j<w-1:
                        A[i][j+1]+=1
                        A[i][j]-=1
                        ans.append((i+1,j+1,i+1,j+2))
                    else:
                        if i+1==h:break
                        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,-1,-1):
                if A[i][j]%2==1:
                    if j>0:
                        A[i][j-1]+=1
                        A[i][j]-=1
                        ans.append((i+1,j+1,i+1,j))
                    else:
                        if i+1==h:break
                        A[i+1][j]+=1
                        A[i][j]-=1
                        ans.append((i+1,j+1,i+2,j+1))
    print(len(ans))
    for a in ans:
        print(*a)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w=map(int,input().split())
    A=[[int(_) for _ in input().split()] for i in range(h)]
    ans=[]
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if A[i][j]%2==1:
                    if j<w-1:
                        A[i][j+1]+=1
                        A[i][j]-=1
                        ans.append((i+1,j+1,i+1,j+2))
                    else:
                        if i+1==h:break
                        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,-1,-1):
                if A[i][j]%2==1:
                    if j>0:
                        A[i][j-1]+=1
                        A[i][j]-=1
                        ans.append((i+1,j+1,i+1,j))
                    else:
                        if i+1==h:break
                        A[i+1][j]+=1
                        A[i][j]-=1
                        ans.append((i+1,j+1,i+2,j+1))
    print(len(ans))
    for a in ans:
        print(*a)

if __name__=='__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
num=[list(map(int,input().split())) for i in range(h)]
ctrl=[]
cnt=0
for i in range(h):
  for j in range(w):
    if i==h-1:
      if j==w-1:pass
      else:
        if num[i][j]%2==1:
          num[i][j]-=1
          num[i][j+1]+=1
          ctrl.append([i+1,j+1,i+1,j+2])
          cnt+=1
    else:
      if num[i][j]%2==1:
        num[i][j]-=1
        num[i+1][j]+=1
        ctrl.append([i+1,j+1,i+2,j+1])
        cnt+=1
print(cnt)
for i in range(cnt):
  print(ctrl[i][0],ctrl[i][1],ctrl[i][2],ctrl[i][3])

Solution (Python):
def main():
    H, W = list(map(int, input().split(' ')))
    a = [list(map(int, input().split(' '))) for _ in range(H)]
    cnt = 0
    history = list()
    for h in range(H):
        for w in range(W - 1):
            if a[h][w] % 2 == 1:
                a[h][w] -= 1
                a[h][w + 1] += 1
                history.append((h + 1, w + 1, h + 1, w + 2))
                cnt += 1
    for h in range(H - 1):
        if a[h][W - 1] % 2 == 1:
            a[h][W - 1] -= 1
            a[h + 1][W - 1] += 1
            history.append((h + 1, W, h + 2, W))
            cnt += 1
    print(cnt)
    for hist in history:
        print(' '.join(map(str, hist)))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod=10**9+7

h,w=MI()
lis=[LI() for i in range(h)]
pos=[0 for i in range(h*w)]
nums=[0 for i in range(h*w)]
count=0
for i in range(h):
    for j in range(w):
        if i%2==0:
            k=j
        else:
            k=w-j-1
        nums[count]=lis[i][k]
        pos[count]=[i+1,k+1]
        count+=1


c=0
for i in range(h*w):
    if nums[i]%2==1:
        c+=1
u=[]
for i in range(h*w-1):
    if nums[i]%2==1:
        nums[i+1]+=1
        u.append([pos[i],pos[i+1]])
        
print(len(u))
for i in range(len(u)):
    print(*u[i][0],end=" ")
    print(*u[i][1])

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

a = []

for _ in range(H):
    a.append(list(map(int,input().split())))

n_order = 0
order = []
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
                a[i][j] -= 1
                n_order += 1
                order.append([i+1,j+1,i+1,j+2])
        else:
            if a[i][j]%2 == 1:
                try:
                    a[i][j] -= 1
                    a[i+1][j] += 1
                    n_order += 1
                    order.append([i+1,j+1,i+2,j+1])
                except:
                    pass

print(n_order)
for i in order:
    print(*i)

Solution (Python):
inf = 10 ** 15
mod = 10 ** 9 + 7
h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
    if i%2 == 0:
        for j in range(w-1):
            if a[i][j] != 0:
                if a[i][j]%2 == 1:    
                    ans.append([i,j,i,j+1])
                    a[i][j]-=1
                    a[i][j+1]+=1
        if i < h-1 and a[i][w-1]%2 == 1:
            ans.append([i, w-1, i+1, w-1])
            a[i][w-1]-=1
            a[i+1][w-1]+=1
    else:
        for j in range(w-1):
            if a[i][w-1-j]%2 == 1:
                ans.append([i,w-1-j,i,w-1-j-1])
                a[i][w-1-j]-=1
                a[i][w-1-j-1]+=1
        if i < h-1 and a[i][0]%2 == 1:
            ans.append([i,0,i+1,0])
            a[i][0]-=1
            a[i+1][0]+=1
print(len(ans))
for x,y,nx,ny in ans:
    print('{} {} {} {}'.format(x+1,y+1,nx+1,ny+1))

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

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

print(len(res))
for resi in res:
    print(' '.join(map(str, resi)))

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w = LI()
a = [LI() for _ in range(h)]

ans = []
dx, dy = [1, 0], [0, 1]
for i in range(h):
    for j in range(w):
        if a[i][j] % 2:
            for k in range(2):
                ny, nx = i + dy[k], j + dx[k]
                if 0 <= ny < h and 0 <= nx < w:
                    if a[ny][nx] % 2:
                        a[ny][nx] += 1
                        a[i][j] -= 1
                        ans.append((i, j, ny, nx))
                        break
            else:
                if j + 1 < w:
                    a[i][j+1] += 1
                    a[i][j] -= 1
                    ans.append((i, j, i, j+1))
                elif i + 1 < h:
                    a[i+1][j] += 1
                    a[i][j] -= 1
                    ans.append((i, j, i+1, j))

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