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())
l=[]
for i in range(H):
  l.append(list(map(int,input().split())))
  
x,y=0,0
p=1
J=[]
ans=0
if(H,W)==(1,1):
  print(0)
else:
  while y<H:
    if y%2==0:
      if x<W-1:
        nx=x+1
        ny=y
      else:
        nx=x
        ny=y+1
    else:
      if x>0:
        nx=x-1
        ny=y
      else:
        nx=x
        ny=y+1
    if l[y][x]%2==1:
      l[ny][nx]+=1
      ans+=1
      J.append((y+1,x+1,ny+1,nx+1))
    x,y=nx,ny
    if x==[0,W-1][H%2] and y==H-1:
      break

  print(ans)
  for a,b,c,d in J:
    print(a,b,c,d)

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

H,W=rl()
a = [rl() for y in range(H)]

ans = []
cnt = 0
for y in range(1,H+1):
    odd = 0
    for x in range(1,W):
        if a[y-1][x-1]%2: odd ^= 1
        if odd == 1:
            cnt += 1
            ans.append([y,x,y,x+1])
    if odd==1:
        a[y-1][W-1] += 1

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

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

Solution (Python):
def make_them_even(H: int, W: int, A: list)->list:
    odds = []
    for h in range(H):
        for w in range(W):
            if h % 2 == 0 and A[h][w] % 2 == 1:
                odds.append((h+1, w+1))
            elif h % 2 == 1 and A[h][W-w-1] % 2 == 1:
                odds.append((h+1, W-w))

    res = []
    for i in range(len(odds) // 2):
        (h1, w1), (h2, w2) = odds[2*i], odds[2*i+1]

        while h1 != h2 or w1 != w2:
            

            
            if h1 == h2:
                
                target_w = w2
            elif h1 % 2 == 1:
                
                target_w = W
            else:
                
                target_w = 1

            
            step = 1 if w1 < target_w else -1
            while w1 != target_w:
                res.append((h1, w1, h1, w1+step))
                w1 = w1 + step

            
            if h1 != h2:
                res.append((h1, w1, h1+1, w1))
                h1 += 1

    return res


if __name__ == "__main__":
    H = 0
    H, W = map(int, input().split())
    A = [[int(s) for s in input().split()] for _ in range(H)]
    ans = make_them_even(H, W, A)
    print(len(ans))
    for a in ans:
        print(' '.join(map(str, a)))

Solution (Python):
def compute_zigzag_distance(c1,c2,size):
    m,n = size
    x1,y1 = c1
    x2,y2 = c2
    dis = 0

    if (x2 - x1)%2 == 0:
        return (x2 - x1)*n + (y2 - y1)*(1 - x1%2 * 2)
    elif (x2 - x1)%2 == 1:
        return (x2 - x1)*n + (n - y2 - y1 -1)*(1 - x1%2 * 2)
def print_zigzag_path(c1,c2,size):
    m,n = size
    x1,y1 = c1
    x2,y2 = c2
    x ,y  = x1 + 1,y1 + 1
    while (x,y)!=(x2 + 1,y2 + 1):
        print(str(x)+" "+str(y),end=" ")
        
        if x%2 == 1:
            if y==n:
                x += 1
            else:
                y += 1
        else:
            if y == 1:
                x += 1
            else:
                y -= 1
        print(str(x)+" "+str(y))
m,n = map(int,input().split())

odd_idx = []

for i in range(m):
    line = list(map(int,input().split()))
    
    for j in range(n)[::(1-i%2 * 2)]:
        if line[j]%2 == 1:
            odd_idx.append((i,j))

s = 0
for i in range(0,len(odd_idx)-1,2):
        
    tmp = compute_zigzag_distance(odd_idx[i],odd_idx[i+1],(m,n))
    
    s += tmp
print(s)
for i in range(0,len(odd_idx)-1,2):    
    print_zigzag_path(odd_idx[i],odd_idx[i+1],(m,n))

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

answer = []

for i in range(H):
    l = L[i]
    if i < H-1:
        if i%2==0:
            for j in range(W):
                if l[j]%2==1:
                    l[j] -= 1
                    if j==W-1:
                        answer.append( (i,j,i+1,j) )
                        L[i+1][j] += 1
                    else:
                        answer.append( (i,j,i,j+1) )
                        l[j+1] += 1
        else:
            for jj in range(W):
                j = (W-1)-jj
                if l[j]%2==1:
                    l[j] -= 1
                    if j==0:
                        answer.append( (i,j,i+1,j) )
                        L[i+1][j] += 1
                    else:
                        answer.append( (i,j,i,j-1) )
                        l[j-1] += 1
    else:
        if i%2==0:
            for j in range(W):
                if l[j]%2==1:
                    l[j] -= 1
                    if j==W-1:
                        continue
                    else:
                        answer.append( (i,j,i,j+1) )
                        l[j+1] += 1
        else:
            for jj in range(W):
                j = (W-1)-jj
                if l[j]%2==1:
                    l[j] -= 1
                    if j==0:
                        continue
                    else:
                        answer.append( (i,j,i,j-1) )
                        l[j-1] += 1
                    
print(len(answer))
for a in answer:
    print('%d %d %d %d' % (a[0]+1,a[1]+1,a[2]+1,a[3]+1))

Solution (Python):
import numpy as np
h,w = map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(h)],dtype = "int")
ans=[]
for p in range(h):
    for q in range(w-1):
            if(A[p][q]%2==1):
                A[p][q+1] +=1
                A[p][q] -=1
                ans.append([p+1,q+1,p+1,q+2])
                
for p in range(h-1):
    if(A[p][w-1]%2==1):
        A[p+1][w-1] += 1
        A[p][w-1] -= 1
        ans.append([p+1,w,p+2,w])
print(len(ans))
for a in ans:
    print(a[0],a[1],a[2],a[3])

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

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

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

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

ans = []
def operate(i, j, k, l):
    a[i][j] -= 1
    a[k][l] += 1
    ans.append([i+1, j+1, k+1, l+1])

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

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

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

ans = []
def operate(i, j, k, l):
    a[i][j] -= 1
    a[k][l] += 1
    ans.append([i+1, j+1, k+1, l+1])

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

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

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

ans = []
def operate(i, j, k, l):
    a[i][j] -= 1
    a[k][l] += 1
    ans.append([i+1, j+1, k+1, l+1])

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

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

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

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

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

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

ans = []
ope = []
def operate(i, j, k, l):
    a[i][j] -= 1
    a[k][l] += 1
    ans.append([i+1, j+1, k+1, l+1])

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

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

Solution (Python):
def main():
    H, W = map(int, input().split())
    coins = [list(map(int, input().split())) for _ in range(H)]
    moves = []
    for i in range(1, H+1):
        for j in range(1, W+1):
            if i == H and j == W:
                break
            if j == W:
                ni, nj = i+1, j
            else:
                ni, nj = i, j+1
            if coins[i-1][j-1] % 2 == 1:
                coins[i-1][j-1] -= 1
                coins[ni-1][nj-1] += 1
                moves.append((i, j, ni, nj))
    print(len(moves))
    for i, j, ni, nj in moves:
        print(i, j, ni, nj)


if __name__ == "__main__":
    main()

Solution (Python):
h, w = map(int,input().split())
row = [0]*h
ans = []
for i in range(h):
    prev = 0
    for j, a in enumerate(map(lambda x:int(x)%2,input().split())):
        if a:
            if prev:
                prev = 0
                continue
            else:
                prev = 1
        if prev:
            if j == w-1:
                row[i] = 1
            else:
                ans.append((i+1,j+1,i+1,j+2))
prev = 0
for i, a in enumerate(row):
    if a:
        if prev:
            prev = 0
            continue
        else:
            prev = 1
    if prev:
        if i == h-1:
                break
        else:
            ans.append((i+1,w,i+2,w))

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

Solution (Python):
import numpy as np
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
move=[]
for i in range(h):
    for j in range(w):
        if a[i][j]%2:
            if j<w-1:
                move.append((i,j,i,j+1))
                a[i][j+1]+=1
            elif i<h-1:
                move.append((i,j,i+1,j))
                a[i+1][j]+=1
print(len(move))
for x,y,x2,y2 in move:
    print(x+1,y+1,x2+1,y2+1)

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
move = []
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1:
            if j+1 < w:
                a[i][j+1] += 1
                move.append((i,j,i,j+1))
            elif i+1 < h:
                a[i+1][j] += 1
                move.append((i,j,i+1,j))
print(len(move))
for x, y, xp, yp in move:
    print(x+1,y+1,xp+1,yp+1)

Solution (Python):
h,w = [int(i) for i in input().split(" ")]
a = [[]] * (h + 1)

for i in range(1, h + 1):
    a[i] = [0] + [int(j) for j in input().split(" ")]
    
pw = ""
c = 0

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if a[y][x] % 2 == 1:
            if x == w:
                if y != h:
                    a[y + 1][x] += 1
                    a[y][x] -= 1
                    pw += " ".join(map(str, [y, x, y + 1, x])) + "\n"
                    c += 1
            else:
                a[y][x + 1] += 1
                a[y][x] -= 1
                pw += " ".join(map(str, [y, x, y, x + 1])) + "\n"
                c += 1
print(c)
print(pw)

Solution (Python):
h, w = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(h)]
out = []
for i in range(h):
    for j in range(w):
        ii, ij, nii, nij = 0, 0, 0, 0
        ii = i
        ij = j if i%2==0 else w-1-j
        if (i%2==0 and ij==w-1) or (i%2==1 and ij==0): nii = i+1
        else: nii = i
        if i%2==0 and ij<w-1: nij = ij+1
        elif i%2==1 and ij>0: nij = ij-1
        else: nij = ij
        if grid[ii][ij]%2==1 and nii<h:
            grid[ii][ij] -= 1
            grid[nii][nij] += 1
            out.append([ii+1,ij+1,nii+1,nij+1])
print(len(out))
for i in out:
    print(i[0],i[1],i[2],i[3])

Solution (Python):
H, W  = map(int, input().split())
m = []
for i in range(H):
    t = list(map(int, input().split()))
    m.append(t)
s = 0
u = 0
ans =0
l = []
for i in range(H):
    if u%2==0:
        for j in range(W):
            if i==H-1 and j ==W-1:break
            if m[i][j]%2 ==1:
                s+=1
            if s%2==1 and j !=W-1:
                ans+=1
                l.append([i+1,j+1,i+1,j+2])
            elif s%2==1:
                ans+=1
                l.append([i+1,j+1,i+2,j+1])
    else:
        for j in reversed(range(W)):
            if i==H-1 and j ==0:break
            if m[i][j]%2 ==1:
                s+=1
            if s%2==1 and j !=0:
                ans+=1
                l.append([i+1,j+1,i+1,j])
            elif s%2==1:
                ans+=1
                l.append([i+1,j+1,i+2,j+1])
    u+=1
print(ans)
for p,q,w,e in l:
    print(p,q,w,e)

Solution (Python):
H,W=map(int,input().split())
Coin=[]
for h in range(H):
    Coin.append(list(map(int,input().split())))
def next(h,w):
    if (-1)**h>0:
        if w+1==W:
            w2=w
            h2=h+1
        else:
            w2=w+1
            h2=h
    else:
        if w==0:
            w2=w
            h2=h+1
        else:
            w2=w-1
            h2=h
    return h2,w2
ans=[]
h=0
w=0
while(1):
    if Coin[h][w]%2==0:
        if next(h,w)[0]==H:
            break
        h,w=next(h,w)
    else:
        if next(h,w)[0]==H:
            break
        ans.append([h,w])
        h,w=next(h,w)
        Coin[h][w]+=1
    
print(len(ans))

for i in range(len(ans)):
    h,w=ans[i]
    h2,w2=next(h,w)
    print(h+1,w+1,h2+1,w2+1)

Solution (Python):


import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline












def get_route(h, w):
	ret = []
	i = 0
	while i < h:
		
		for j in range(w):
			ret.append([i, j])
		i += 1
		
		if i == h:
			return(ret)
		
		
		for j in range(w-1, -1, -1):
			ret.append([i, j])
		i += 1
	return(ret)


if __name__ == '__main__':
	
	H, W = map(int, input().rstrip().split())
	coins_s = []
	for i in range(H):
		coins_s.append(list(map(int, input().rstrip().split())))
		for j in range(W):
			coins_s[i][j] = coins_s[i][j] % 2

	
	route_s = get_route(H, W)[1:]
	ans_s = []

	i_prev, j_prev = [0, 0]
	for i, j in route_s:
		if coins_s[i_prev][j_prev] == 1:
			ans_s.append([i_prev, j_prev, i, j])
			coins_s[i][j] = (coins_s[i][j] + 1) % 2
		i_prev, j_prev = [i, j]

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

Solution (Python):
def main():
    H, W = map(int, input().split())
    a = [[0] * W]
    for _ in range(H):
        ai = list(map(int, input().split()))
        ai.insert(0, 0)
        a.append(ai)
    ans = []
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if a[i][j] % 2 == 0:
                continue
            if W >= j + 1:
                a[i][j] -= 1
                a[i][j + 1] += 1
                ans.append([i, j, i, j + 1])
        if H >= i + 1 and a[i][j] % 2 != 0:
            a[i][j] -= 1
            a[i + 1][j] += 1
            ans.append([i, j, i + 1, j])
    print(len(ans))
    for row in ans:
        print(' '.join(list(map(str, row))))


main()

Solution (Python):
def output(moves):
    print(len(moves))
    for a,b,c,d in moves:
        print(a+1,b+1,c+1,d+1)


def move(x, y, dx, dy, a, moves):
    if a[x][y]%2 != 0:
        a[x+dx][y+dy] += 1
        moves.append((x, y, x+dx, y+dy))


def main():
    H, W = list(map(int, input().split(' ')))
    a = []
    for i in range(H):
        a.append(list(map(int, input().split(' '))))
    x = 0
    y = 0
    dy = 1
    moves = []
    while True:
        if (x+1 == H and y+1 == W and dy == 1) or (x+1 == H and y == 0 and dy == -1):
            break
        elif y+1 == W and dy == 1:
            move(x, y, 1, 0, a, moves)
            x += 1
            dy = -1
        elif y == 0 and dy == -1:
            move(x, y, 1, 0, a, moves)
            x += 1
            dy = 1
        else:
            move(x, y, 0, dy, a, moves)
            y += dy

    output(moves)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    a = [[0] * W]
    for _ in range(H):
        ai = list(map(int, input().split()))
        ai.insert(0, 0)
        a.append(ai)
    N = 0
    yx = []
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if a[i][j] % 2 == 0:
                continue
            if W >= j + 1:
                a[i][j] -= 1
                a[i][j + 1] += 1
                N += 1
                yx.append([i, j, i, j + 1])
            elif H >= i + 1:
                a[i][j] -= 1
                a[i + 1][j] += 1
                N += 1
                yx.append([i, j, i + 1, j])
    print(N)
    for row in yx:
        print(' '.join(list(map(str, row))))


main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    a = [[0] * W]
    for _ in range(H):
        ai = list(map(int, input().split()))
        ai.insert(0, 0)
        a.append(ai)
    N = 0
    yx = []
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if a[i][j] % 2 == 0:
                continue
            if W >= j + 1:
                a[i][j] -= 1
                a[i][j + 1] += 1
                N += 1
                yx.append([i, j, i, j + 1])
            elif H >= i + 1:
                a[i][j] -= 1
                a[i + 1][j] += 1
                N += 1
                yx.append([i, j, i + 1, j])
        if H > i + 1 and a[i][j] % 2 != 0:
            a[i][j] -= 1
            a[i + 1][j] += 1
            N += 1
            yx.append([i, j + 1, i + 1, j])
    print(N)
    for row in yx:
        print(' '.join(list(map(str, row))))


main()

Solution (Python):
dimensions = raw_input()
h,w = int(dimensions.split(" ")[0]),int(dimensions.split(" ")[1])

matrix = []
for i in range(h):
	values = raw_input()
	matrix.append([int(i) for i in values.split(" ")])

trace = []
for i in range(h):
	start = 0 
	end = w
	step = 1
	if i%2!=0:
		start = w-1
		end = -1
		step = -1
	for j in range(start,end,step):
		trace.append([(i,j),matrix[i][j]])

moviments = []
for i in range(len(trace)-1):
	if trace[i][1]%2!=0:
		trace[i+1][1] += trace[i][1]
		moviments.append(str(trace[i][0][0]+1)+" "+str(trace[i][0][1]+1)+" "+str(trace[i+1][0][0]+1)+" "+str(trace[i+1][0][1]+1))
print(len(moviments))
for i in moviments:
	print(i)

Solution (Python):
import sys

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

  count = 0
  manup = []
  for y in range(H):
    for x in range(W):
      if M[y][x] % 2 == 1:
        if x < (W-1):
          count += 1
          manup.append([y+1, x+1, y+1, x+2])
          M[y][x+1] += 1
        elif y < H-1:
          count += 1
          manup.append([y+1, x+1, y+2, x+1])
          M[y+1][x] += 1
        else:
          continue
  
  print(count)
  if count > 0:
    for m in manup:
      print('{} {} {} {}'.format(m[0], m[1], m[2], m[3]))

if __name__ == '__main__':
  main()

Solution (Python):
h, w = map(int, input().split())
a_array = [[int(x) for x in input().split()] for x in range(h)]
visited_array = [[False for x in range(w)] for y in range(h)]
root_array = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            root_array.append([i, j])
    if i % 2 == 1:
        for j in reversed(range(w)):
            root_array.append([i, j])
res = []
for n in range(len(root_array)-1):
    i, j = root_array[n]
    next_i, next_j = root_array[n + 1]
    if visited_array[i][j]:
        continue
    visited_array[i][j] = True
    if a_array[i][j] % 2 == 1:
        res.append([i+1, j+1, next_i+1, next_j+1])
        a_array[next_i][next_j] += 1
        a_array[i][j] -= 1

print(len(res))
for root in res:
    print(" ".join([str(x) for x in root]))

Solution (Python):
h,w = (int(i) for i in input().split())
a = []
ans = []
ct = 0
for i in range(h):
  tmp = list(int(i) for i in input().split())
  a.append(tmp)
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
       ans.append([i+1,j+1,i+1,j+2])
      elif i+1 != h:
       a[i+1][j] += 1
       ans.append([i+1,j+1,i+2,j+1])
      else:
       break
  else:
    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])
      elif i+1 != h:
       a[i+1][j] += 1
       ans.append([i+1,j+1,i+2,j+1])
      else:
        break
ct = len(ans)
print(ct)
for i in range(ct):
 print(*ans[i])

Solution (Python):
from itertools import product

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

move = [(-1, 0), (0, -1), (0, 1), (1, 0)]

cord = []

N = 0



for i, j in product(range(H), range(W)):
    
    if A[i][j] % 2 == 0:
        continue
    else:
        
        
        

        
        
        
        
        
        

        
        A[i][j] -= 1
        if i == H - 1:
            
            if j != W - 1:
                A[i][j + 1] += 1
                N += 1
                cord.append((i + 1, j + 1, i + 1, j + 2))
            else:
                
                A[i][j] += 1
        else:
            
            A[i + 1][j] += 1
            N += 1
            cord.append((i + 1, j + 1, i + 2, j + 1))

print(N)
for c in cord:
    print(*c)

Solution (Python):
from itertools import product

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

move = [(-1, 0), (0, -1), (0, 1), (1, 0)]

cord = []

N = 0



for i, j in product(range(H), range(W)):
    
    if A[i][j] % 2 == 0:
        continue
    else:
        
        
        

        
        
        
        
        
        

        
        A[i][j] -= 1
        if i == H - 1:
            
            if j != W - 1:
                A[i][j + 1] += 1
                N += 1
                cord.append((i + 1, j + 1, i + 1, j + 2))
            else:
                
                A[i][j] += 1
        else:
            
            A[i + 1][j] += 1
            N += 1
            cord.append((i + 1, j + 1, i + 2, j + 1))

print(N)
for c in cord:
    print(*c)

Solution (Python):
h,w=map(int,input().split())
A=[]
for _ in range(h):
    A.append(list(map(int,input().split())))
n=0
B=[]
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
                    A[i][j+1]+=1
                    n+=1
                    B.append([i+1,j+1,i+1,j+2])
                elif i!=h-1:
                    A[i][j]-=1
                    A[i+1][j]+=1
                    n+=1
                    B.append([i+1,j+1,i+2,j+1])
    else:
        for j in range(w):
            if A[i][w-j-1]%2==1:
                if j!=w-1:
                    A[i][w-j-1]-=1
                    A[i][w-j-2]+=1
                    n+=1
                    B.append([i+1,w-j,i+1,w-j-1])
                elif i!=h-1:
                    A[i][w-j-1]-=1
                    A[i+1][w-j-1]+=1
                    n+=1
                    B.append([i+1,w-j,i+2,w-j])
print(n)
for i in range(n):
    print(' '.join(map(str,B[i])))

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

count = 0
ans = []
for i in range(0, h-1, 2):
    for j in range(w):
        if lst[i][j] % 2 == 1:
            count += 1
            if j == w-1:
                lst[i+1][j] += 1
                ans.append((i+1, j+1, i+2, j+1))
            else:
                lst[i][j+1] += 1
                ans.append((i+1, j+1, i+1, j+2))
    for j in reversed(range(w)):
        if lst[i+1][j] % 2 == 1:
            if j == 0 and i+1 == h-1:
                pass
            elif j == 0:
                lst[i+2][j] += 1
                ans.append((i+2, j+1, i+3, j+1))
                count += 1
            else:
                lst[i+1][j-1] += 1
                ans.append((i+2, j+1, i+2, j))
                count += 1
if h % 2 == 1:
    for j in range(w):
        if lst[-1][j] % 2 == 1:
            if j == w-1:
                pass
            else:
                lst[-1][j+1] += 1
                ans.append((h, j+1, h, j+2))
                count += 1
                
print(count)
for a,b,c,d in ans:
    print(a,b,c,d)

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

Solution (Python):

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

diff = lambda a,b: abs(a[0]-b[0]) + abs(a[1]-b[1])

trainsition_list = []
for h in range(H):
    step = 1 if h%2==0 else -1
    for w in range(W)[::step]:
        trainsition_list.append( (h,w) )

ans_tuple = []
n = 0
for pos,next_pos in zip(trainsition_list, trainsition_list[1:]):
    h,w = pos
    if a[h][w] % 2 == 1:
        nh,nw = next_pos
        a[nh][nw] += 1
        ans_tuple.append( (h,w,nh,nw) )
        n += 1

print(n)
for atp in ans_tuple:
    print( *(map(lambda x: x+1, atp)))

Solution (Python):

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

diff = lambda a,b: abs(a[0]-b[0]) + abs(a[1]-b[1])

trainsition_list = []
for h in range(H):
    step = 1 if h%2==0 else -1
    for w in range(W)[::step]:
        trainsition_list.append( (h,w) )

ans_tuple = []

n = 0
for pos,next_pos in zip(trainsition_list, trainsition_list[1:]):
    h,w = pos
    if a[h][w] % 2 == 1:
        nh,nw = next_pos
        a[nh][nw] += 1
        
        ans_tuple.append( (h,w,nh,nw) )
        n += 1
print(n)
for atp in ans_tuple:
    print( *(map(lambda x: x+1, atp)))

Solution (Python):
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W = IL()
l = []
end = []
ans = []

l = [IL() for i in range(H)]

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

for i in range(H):
    if sum(l[i])%2 != 0:
        end.append(1)
    else:
        end.append(0)

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

print(len(ans))
for i in ans:
    a = str(i[0])
    for j in range(1,len(i)): 
        a +=" "+str(i[j])
    print(a)

Solution (Python):
H,W = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(H)]
cnt = 0
print_list = []
for i in range(H):
    for j in range(W):
        if (i,j) == (H-1,W-1):
            break
        if grid[i][j] % 2 == 1:
            cnt += 1
            if i != H-1:
                grid[i][j] -= 1
                grid[i+1][j] += 1
                print_list.append([i+1,j+1,i+2,j+1])
            elif i == H-1:
                grid[i][j] -= 1
                grid[i][j+1] += 1
                print_list.append([i+1,j+1,i+1,j+2])

def debug():
    num = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] % 2 == 0:
                num += 1
    print("偶数は{}個です".format(num))

def output():
    print(cnt)
    for p in print_list:
        print(p[0],p[1],p[2],p[3])

output()

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

ans = []
for i,al in enumerate(A):
    for j in range(W-1):
        if al[j] & 1:
            A[i][j    ] -= 1
            A[i][j + 1] += 1
            ans.append((i + 1, j + 1, i + 1, j + 2))

for i,al in enumerate(A[:-1]):
    if al[-1] & 1:
        A[i  ][-1] -= 1
        A[i+1][-1] += 1
        ans.append((i + 1, W, i + 2, W))

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

Solution (Python):
H,W = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(H)]
data = []
cnt = 0
for i in range(H-1):
    for j in range(W):
        if s[i][j] % 2 != 0:
            cnt += 1
            s[i+1][j] += 1
            data.append([i+1,j+1,i+2,j+1])




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

print(cnt)

for i in data:
    print(i[0],i[1],i[2],i[3])