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())
flag = False
ans = []
for i in range(h):
    A=list(map(int,input().split()))
    if i%2==0:
        r=range(w)
    else:
        r=range(w-1,-1,-1)
    for j in r:
        a=A[j]
        if (i>0 or j>0) and flag:
            ans.append(f"{prev_i+1} {prev_j+1} {i+1} {j+1}")
        if flag:
            if a%2==0:
                flag = True
            else:
                flag = False
        else:
            if a%2==0:
                flag = False
            else:
                flag = True
        prev_i = i
        prev_j = j
print(len(ans))
print("\n".join(ans))

Solution (Python):
H, W = map(int, input().split())
D = []
res = []
for _ in range(H):
    D.append(list(map(int, input().split())))
for i in range(H-1):
    for j in range(W):
        if D[i][j]%2:
            D[i+1][j] += 1
            res.append((i+1,j+1,i+2,j+1))
for j in range(W-1):
    if D[H-1][j]%2:
        D[H-1][j+1] += 1
        res.append((H,j+1, H, j+2))
print(len(res))
for i,j,k,l in res:
    print(i,j,k,l)

Solution (Python):

from collections import deque

icase=0
if icase==0:
    h,w=map(int,input().split())
    a=[[0]*w for i in range(h)]
    for i in range(h):
        a[i]=list(map(int,input().split()))        
elif icase==1: 
    h,w=2,3
    a=[[1, 2, 3], [0, 1, 1]]
elif icase==2: 
    h,w=3,2
    a=[[1, 0], [2, 1], [1, 0]]
elif icase==3: 
    h,w=1,5
    a=[[9, 9, 9, 9, 9]]


astat=0
im=-1
jm=-1
q=deque()

for i in range(h):
    if i%2==0:
        wst=0
        wed=w
        wpt=1
    else:
        wst=w-1
        wed=-1
        wpt=-1
    for j in range(wst,wed,wpt):

        if a[i][j]%2==1 and astat==0:
            astat=1

        elif a[i][j]%2==1 and astat==1:
            q.append((im,jm,i,j))

            astat=0
        elif a[i][j]%2==0 and astat==0:
            astat=0

        elif a[i][j]%2==0 and astat==1:
            astat=1
            q.append((im,jm,i,j))

        im=i
        jm=j
        
print(len(q))
for i in range(len(q)):
    yf,xf,yt,xt=q.popleft()
    stra=str(yf+1)+" "+str(xf+1)+" "+str(yt+1)+" "+str(xt+1)
    print(stra)

Solution (Python):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    ans = []
    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
                ans.append([h+1,w+1,h+1,w+2])

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



if __name__ == "__main__":
    main()

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


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

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

Solution (Python):
f=lambda:[*map(int,input().split())]
r=range
h,w=f()
g=[f() for _ in r(h)]
a=[]
for x in r(h):
  for y in r(w):
    if g[x][y]%2 and (x+1)*(y+1)<h*w:
      if (t:=y+1)<w: s=x
      elif (s:=x+1)<h: t=y
      g[x][y]-=1; g[s][t]+=1; a+=[(x+1,y+1,s+1,t+1)]
print(len(a))
for l in a: print(*l)

Solution (Python):
f=lambda:[*map(int,input().split())]
h,w=f()
g=[f() for _ in range(h)]
a=[]
for x in range(h):
  for y in range(w):
    if g[x][y]%2 and (x+1)*(y+1)<h*w:
      if (t:=y+1)<w: s=x
      elif (s:=x+1)<h: t=y
      g[x][y]-=1
      g[s][t]+=1
      a+=[(x+1,y+1,s+1,t+1)]
print(len(a))
for l in a: print(*l)

Solution (Python):
f=lambda:[*map(int,input().split())]
h,w=f()
g=[f() for _ in range(h)]
tx=ty=0
a=[]
for y in range(h):
  for x in range(w):
    if y%2:
      if tx: nx,ny=tx-1,ty
      else: nx,ny=tx,ty+1
    else:
      if tx<w-1: nx,ny=tx+1,ty
      else: nx,ny=tx,ty+1
    if ny==h: break
    if g[ty][tx]%2:
      g[ty][tx]-=1
      g[ny][nx]+=1
      a+=[[ty+1,tx+1,ny+1,nx+1]]
    ty,tx=ny,nx
  if ny==h: break
print(len(a))
for l in a: print(*l)

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

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


cnt = 0
for ih in range(H):
    for iw in range(W-1):
        if a[ih][iw]%2 == 0:
            continue
        else:
            a[ih][iw] -= 1
            a[ih][iw+1] += 1
            cnt += 1
            operation.append([ih+1,iw+1,ih+1,iw+2])

for ih in range(H-1):
    if a[ih][W-1]%2 == 0:
        continue
    else:
        a[ih][W-1] -= 1
        a[ih+1][W-1] += 1
        cnt += 1
        operation.append([ih+1,W,ih+2,W])
print(cnt)
for ope in operation:
    print(*ope)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W = map(int, readline().split())
    A = list(list(map(int, readline().split())) for _ in range(H))
    move = []
    for i in range(H):
        for j in range(W - 1):
            if A[i][j] % 2:
                A[i][j] -= 1
                A[i][j + 1] += 1
                move.append([i + 1, j + 1, i + 1, j + 2])
    for i in range(H - 1):
        if A[i][W - 1] % 2:
            A[i][W - 1] -= 1
            A[i + 1][W - 1] += 1
            move.append([i + 1, W, i + 2, W])
    print(len(move))
    for m in move:
        print(m[0],m[1],m[2],m[3])


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    odd = []

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

    ans = []
    for (x, y), (z, w) in zip(*[iter(odd)] * 2):
        tmp = []
        tmp.append((x, y))
        while (x, y) != (z, w):
            if x % 2 == 1:
                if y == W:
                    x += 1
                else:
                    y += 1
            else:
                if y == 1:
                    x += 1
                else:
                    y -= 1
            tmp.append((x, y))

        for i in range(len(tmp) - 1):
            ans.append((tmp[i][0], tmp[i][1], tmp[i + 1][0], tmp[i + 1][1]))

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

    return


if __name__ == '__main__':
    main()

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

L = []
for i in range(h):
    for j in range(w):
        if c[i][j]%2 == 1:
            
            if j != w-1:
                c[i][j] -= 1
                c[i][j+1] += 1
                L.append([str(i+1),str(j+1),str(i+1),str(j+2)])
                
            else:
                if i != h-1:
                    c[i][j] -=1
                    c[i+1][j] += 1
                    L.append([str(i+1),str(j+1),str(i+2),str(j+1)])
                    
print(len(L))
for x in L:
    print(" ".join(x))

Solution (Python):
h,w=map(int,input().split())
ans=[]
a=[list(map(int,input().split())) for i in range(h)]
flg=True
for i in range(h):
    if flg:
        for j in range(w):
            if a[i][j]%2==1:
                if j<w-1:
                    a[i][j+1]+=1
                    ans.append((i+1,j+1,i+1,j+2))
                if j==w-1:
                    if i<h-1:
                        a[i+1][j]+=1
                        ans.append((i+1,j+1,i+2,j+1))
        flg=False
    else:
        flg=True
        for j in range(w-1,-1,-1):
            if a[i][j]%2==1:
                if j>0:
                    a[i][j-1]+=1
                    ans.append((i+1,j+1,i+1,j))
                if j==0:
                    if i<h-1:
                        a[i+1][j]+=1
                        ans.append((i+1,j+1,i+2,j+1))
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    a = [LI() for _ in range(H)]

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

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

    
    

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

if __name__ == '__main__':
    resolve()

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

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

cnt = 0
op_list = []
for i in range(len(q) - 1):
    if grid[q[i][0]][q[i][1]] % 2 == 0:
        pass
    else:
        grid[q[i][0]][q[i][1]] -= 1
        grid[q[i + 1][0]][q[i + 1][1]] += 1
        cnt += 1
        op_list.append([q[i][0], q[i][1], q[i + 1][0], q[i + 1][1]])
print(cnt)
for op in op_list:
    print(op[0] + 1, op[1] + 1, op[2] + 1, op[3] + 1)

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

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

print(cnt)
for ans_i in ans:
    print(*ans_i)

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

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

N = 0
ans_arr = []
for qi in range(len(q)):
    i = q[qi][0]
    j = q[qi][1]
    if a[i][j] % 2 == 0:
        pass
    elif a[i][j] % 2 == 1 and qi != len(q) - 1:
        N += 1
        a[i][j] -= 1
        a[q[qi + 1][0]][q[qi + 1][1]] += 1
        ans_arr.append([i, j, q[qi + 1][0], q[qi + 1][1]])

print(N)
for x1, x2, x3, x4 in ans_arr:
    print(x1 + 1, x2 + 1, x3 + 1, x4 + 1)

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

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

N = 0
ans_arr = []
for qi in range(len(q)):
    i = q[qi][0]
    j = q[qi][1]
    if a[i][j] % 2 == 0:
        pass
    elif a[i][j] % 2 == 1 and qi != len(q) - 1:
        N += 1
        a[i][j] -= 1
        a[q[qi + 1][0]][q[qi + 1][1]] += 1
        ans_arr.append([i, j, q[qi + 1][0], q[qi + 1][1]])

print(N)
for x1, x2, x3, x4 in ans_arr:
    print(x1 + 1, x2 + 1, x3 + 1, x4 + 1)

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    b = [int(i) % 2 for i in input().split()]
    a.append(b)
c = []
odd = 0
n = 0
while n <h:
    if odd == 0:
        for i in range(w):
            c.append([n,i])
        odd = 1
    elif odd == 1:
        for i in range(w-1,-1,-1):
            c.append([n,i])
        odd = 0
    n +=1
ans = []
for i in range(len(c)):
    if a[c[i][0]][c[i][1]] == 1:
        if i == len(c)-1:
            break
        ans.append([str(c[i][0]+1), str(c[i][1]+1), str(c[i+1][0]+1), str(c[i+1][1]+1)])
        a[c[i+1][0]][c[i+1][1]] +=1
print(len(ans))
for i in range(len(ans)):
    print(' '.join(ans[i]))

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

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

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

ans = []

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

print(len(ans))
for i, j, ni, nj in ans:
    print(i+1, j+1 , ni+1, nj+1)

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
func=[]
for i in range(h):
    for j in range(w):
        if a[i][j] & 1:
            if j < w - 1:
                a[i][j + 1] += 1
                a[i][j] -= 1
                func.append((i, j, i, j + 1))

            elif i < h - 1:
                a[i + 1][j] += 1
                a[i][j] -= 1
                func.append((i, j, i + 1, j))



print(len(func))
for y, x, i, j in func:
    print(y + 1, x + 1, i + 1, j + 1)

Solution (Python):











h, w = map(int, input().split())

matrix = []
for _ in range(h):
    matrix.append([int(i) for i in input().split()])


ans_move = []
for i in range(h):
    if i % 2 == 0: 
        for j in range(w):
            if matrix[i][j] % 2 == 1:
                if j == w - 1 and i != h - 1: 
                    matrix[i][j] -= 1
                    matrix[i + 1][j] += 1
                    ans_move.append([i + 1, j + 1, i + 1 + 1, j + 1])
                elif j != w - 1:
                    matrix[i][j] -= 1
                    matrix[i][j + 1] += 1
                    ans_move.append([i + 1, j + 1, i + 1, j + 1 + 1])
    else: 
        for j in range(w)[::-1]:
            if matrix[i][j] % 2 == 1:
                if j == 0 and i != h - 1: 
                    matrix[i][j] -= 1
                    matrix[i + 1][j] += 1
                    ans_move.append([i + 1, j + 1, i + 1 + 1, j + 1])
                elif j != 0:
                    matrix[i][j] -= 1
                    matrix[i][j - 1] += 1
                    ans_move.append([i + 1, j + 1, i + 1, j - 1 + 1])
ans = len(ans_move)
print(ans)
for m in ans_move:
    print(*m)

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

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

rlt = []
  
f = 0
for i in range(H):
  if i % 2 == 0:
    for j in range(W):
      if mp[i][j] % 2 == 1:
        f = (f + 1) % 2
      if f == 1:
        if j < W -1:
          rlt.append((i+1,j+1,i+1,j+2))
        else:
          rlt.append((i+1,j+1,i+2,j+1))
  else:
    for j in range(W-1,-1,-1):
      if mp[i][j] % 2 == 1:
        f = (f + 1) % 2
      if f == 1:
        if j > 0:
          rlt.append((i+1,j+1,i+1,j))
        else:
          rlt.append((i+1,j+1,i+2,j+1))
  
if f == 1:
  rlt.pop(-1)
  
print(len(rlt))
for t in rlt:
  print(" ".join(map(str, t)))

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    H, W = read_ints()
    A = []
    for _ in range(H):
        A.append(read_ints())
    answer = []
    last = None
    for i in range(H):
        for j in range(W):
            if i%2 == 1:
                j = W-j-1
            if last is not None and A[last[0]][last[1]]%2 == 1:
                A[i][j] += 1
                answer.append((last[0]+1, last[1]+1, i+1, j+1))
            last = (i, j)
    print(len(answer))
    for a in answer:
        print(*a)


if __name__ == '__main__':
    solve()

Solution (Python):

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

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


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

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

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

Solution (Python):
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(list(map(int,input().split())))
    n = []
    for i in range(h):
        for j in range(w):
            if a[i][j]%2==1:
                flg=0
                if i<h-1:
                    if a[i+1][j]%2==1:
                        a[i+1][j]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i+2,j+1])
                        flg=1
                elif 0<i:
                    if a[i-1][j]%2==1:
                        a[i-1][j]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i,j+1])
                        flg=1
                elif j<w-1:
                    if a[i][j+1]%2==1:
                        a[i][j+1]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i+1,j+2])
                        flg=1
                elif 0<j:
                    if a[i][j-1]%2==1:
                        a[i][j-1]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i+1,j])
                        flg=1
                if flg==0:
                    if i<h-1:
                        a[i+1][j]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i+2,j+1])
                    elif j<w-1:
                        a[i][j+1]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i+1,j+2])
                    elif i>0:
                        a[i-1][j]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i,j+1])
                    elif j>0:
                        a[i][j-1]+=1
                        a[i][j]-=1
                        n.append([i+1,j+1,i+1,j])
    print(len(n))
    for i in range(len(n)):
        print(' '.join(list(map(str,n[i]))))

if __name__ == "__main__":
    main()

Solution (Python):
H,W=map(int,input().split())
N=0
L= [list(map(int,input().split(" "))) for i in range(H)]
ans1=list()
ans2=list()
ans3=list()
ans4=list()
for i in range(H):
  for j in range(W):
    if i==H-1:
      if j==W-1:
        break
      else:
        for k in range(L[i][j]%2):
          ans1.append(i+1)
          ans2.append(j+1)
          ans3.append(i+1)
          ans4.append(j+2)
        L[i][j+1]+=L[i][j]%2
        N+=L[i][j]%2
    else:
      for k in range(L[i][j]%2):
        ans1.append(i+1)
        ans2.append(j+1)
        ans3.append(i+2)
        ans4.append(j+1)
      L[i+1][j]+=L[i][j]%2
      N+=L[i][j]%2
print(N)
for i in range(N):
  print(ans1[i],ans2[i],ans3[i],ans4[i])

Solution (Python):

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


    out = []
    def move(x1,y1,x2,y2):
        A[y1][x1] -= 1
        A[y2][x2] += 1
        out.append('{} {} {} {}'.format(y1+1,x1+1,y2+1,x2+1))
    for i in range(H):
        if i & 1:
            for j in range(W-1):
                if A[i][j] & 1:
                    move(j,i,j+1,i)
            if A[i][W-1] & 1 and i < H-1:
                move(W-1,i,W-1,i+1)
        else:
            for j in range(W-1,0,-1):
                if A[i][j] & 1:
                    move(j,i,j-1,i)
            if A[i][0] & 1 and i < H-1:
                move(0,i,0,i+1)
    print(len(out))
    print('\n'.join(out))








main()

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):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w = MAP()
a = [[0]*(w+1)]
for i in range(1, h+1):
    a.append([0] + LIST())
ans = []
flag = False
for i in range(1, h+1):
    if i % 2 == 1:
        for j in range(1, w+1):
            if a[i][j] % 2 == 1:
                flag = not flag
            if flag:
                if j < w:
                    ans.append([i,j,i,j+1])
                elif i < h:
                    ans.append([i,j,i+1,j])
    else:
        for j in range(w, 0, -1):
            if a[i][j] % 2 == 1:
                flag = not flag
            if flag:
                if j > 1:
                    ans.append([i,j,i,j-1])
                elif i < h:
                    ans.append([i,j,i+1,j])

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

Solution (Python):


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

reverse = 0
count = 0
print_list = []
for h_ in range(h):
    iter_ = range(w)
    if reverse == 1:
        iter_ = reversed(iter_)
    for w_ in iter_:
        if a[h_][w_] % 2 != 0:
            a[h_][w_] -= 1
            if reverse == 0 and w_ == (w-1):
                ww, hh = w_, h_+1
            elif reverse == 1 and w_ == 0:
                ww, hh = w_, h_+1
            else:
                ww, hh = w_+1, h_

            if hh == h:
                continue
            count += 1
            a[hh][ww] += 1

            print_list.append([h_+1, w_+1, hh+1, ww+1])

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

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

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

for hi in range(h):
    for wi in range(w):
        if A[hi][wi]%2:
            if hi+1<h:
                A[hi][wi] -= 1
                A[hi+1][wi] += 1
                Ans.append((hi+1, wi+1, hi+1+1, wi+1))
            elif wi+1<w:
                A[hi][wi] -= 1
                A[hi][wi+1] += 1
                Ans.append((hi+1, wi+1, hi+1, wi+1+1))
print(len(Ans))
for _ans in Ans:
    print(*_ans)

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

ans = []
for y in range(h):
    for x in range(w - 1):
        if aa[y][x] & 1 == 1:
            ans.append((y, x, y, x + 1))
            aa[y][x] -= 1
            aa[y][x + 1] += 1
for y in range(h - 1):
    if aa[y][w - 1] & 1 == 1:
        ans.append((y, w - 1, y + 1, w - 1))
        aa[y][w - 1] -= 1
        aa[y + 1][w - 1] += 1

print(len(ans))
for a in ans:
    print(' '.join(map(lambda x: str(x + 1), a)))

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

path = []
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            x = (i, j)
            path.append(x)
    else:
        for j in range(W - 1, -1, -1):
            x = (i, j)
            path.append(x)

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

Solution (Python):

import sys
input = sys.stdin.readline  
H,W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]


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


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

Solution (Python):
h, w = map(int, input().split())
g = []
for i in range(h):
    g += list(map(int, input().split()))
res = []
for j in range(h):
    for i in range(w):
        for k in [(1,0),(0,1)]:
            if i+k[0]>=0 and i+k[0]<w and j+k[1]>=0 and j+k[1]<h:
                idx_cur = j * w + i
                idx_nex = (j+k[1]) * w + i+k[0]
                if g[idx_cur] % 2 != 0:
                    g[idx_cur] -= 1
                    g[idx_nex] += 1
                    res.append([j+1,i+1,j+k[1]+1,i+k[0]+1])
print(len(res))
for i in res:
    print(*i)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n, m = [int(x) for x in input().split()]
    ans = []
    c = 0
    for i in range(n):
        r = [int(x) for x in input().split()]
        for j in range(m):
            if i + 1 == n and j + 1 == m: continue
            if i % 2:
                j = m - j - 1
            r[j] += c
            c = r[j] % 2
            if c:
                x = i + 1
                y = j + 1
                if i % 2:
                    if y == 1:
                        ans.append((x, y, x + 1, y))
                    else:
                        ans.append((x, y, x, y - 1))
                else:
                    if y == m:
                        ans.append((x, y, x + 1, y))
                    else:
                        ans.append((x, y, x, y + 1))
    print(len(ans))
    for r in ans:
        print(*r)


t = 1

for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

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

ans=[]
for i in range(H):
    for j in range(W):
        
        if i==H-1 and j==W-1:
            continue
        if a[i][j]%2==1:
            if j!=W-1:
                ans.append((i,j,i,j+1))
                a[i][j+1]+=1
            else:
                ans.append((i,j,i+1,j))
                a[i+1][j]+=1
print(len(ans))
for aa in ans:
    print(*[aaa+1 for aaa in aa])