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):



def inpl(): return list(map(int, input().split()))


H, W = inpl()
board = []
for i in range(H):
    board.append(inpl())

ans = []
cnt = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if w + 1 < W:
                    board[h][w + 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w + 2])
                    cnt += 1
                elif h + 1 < H:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
                    cnt += 1

    else:
        for w in range(W)[::-1]:
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if 0 < w:
                    board[h][w - 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w])
                    cnt += 1
                elif h + 1 < H:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
                    cnt += 1

print(cnt)

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

Solution (Python):


H,W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
a_eo = [[a[i][j] % 2 for j in range(W)] for i in range(H)]

N = 0
move = ""
for i in range(H):
    for j in range(W):
        if a_eo[i][j] == 1:
            if j < W-1 and 1 in a_eo[i][j+1:]:
                a[i][j] -= 1
                a[i][j+1] += 1
                a_eo[i][j] = 0
                a_eo[i][j+1] = (a_eo[i][j+1] + 1) % 2
                N += 1
                move += "%d %d %d %d\n" % (i+1, j+1, i+1, j+1+1)
            elif i < H-1 and 1 not in a_eo[i][j+1:]:
                a[i][j] -= 1
                a[i+1][j] += 1
                a_eo[i][j] = 0
                a_eo[i+1][j] = (a_eo[i+1][j] + 1) % 2
                N += 1
                move += "%d %d %d %d\n" % (i+1, j+1, i+1+1, j+1)
            else:
                break

print("%d\n" % N + move)

Solution (Python):

h,w=map(int,input().split())
field=[]
d=[]
for i in range(h):
    field.append(list(map(int,input().split())))
    d.append(field[-1][:])
count=0
for i in range(h):
    for j in range(w):
        if field[i][j]%2==1:
            count+=1

ans=[]

for i in range(h):
    if i%2==0:
        for j in range(w):
            if field[i][j]%2==1 and count>1:
                if j!=w-1:
                    ans.append([i,j,i,j+1])
                    field[i][j+1]+=1
                    if field[i][j+1]%2==0:
                        count-=2
                else:
                    ans.append([i,j,i+1,j])
                    field[i+1][j]+=1
                    if field[i+1][j]%2==0:
                        count-=2
    else:
        for j in range(w):
            j=w-1-j
            if field[i][j]%2==1 and count>1:
                if j!=0:
                    ans.append([i,j,i,j-1])
                    field[i][j-1]+=1
                    if field[i][j-1]%2==0:
                        count-=2
                else:
                    ans.append([i,j,i+1,j])
                    field[i+1][j]+=1
                    if field[i+1][j]%2==0:
                        count-=2
print(len(ans))
for i in range(len(ans)):
    print(ans[i][0]+1,ans[i][1]+1,ans[i][2]+1,ans[i][3]+1)

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-1):
		if a[i][j]%2 == 0:
			continue
		
		l.append((i+1, j+1, i+1, j+2))
		a[i][j] -= 1
		a[i][j+1] += 1
 
for i in range(H-1):
	if a[i][W-1]%2 == 0:
		continue
	
	l.append((i+1, W, i+2, W))
	a[i][W-1] -= 1
	a[i+1][W-1] += 1
 
print(len(l))
 
for y, x, y_, x_ in l:
	print('{} {} {} {}'.format(y, x, y_, x_))

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

ret=[]
temp=0
N=0

for y in range(H):
    for x in range(W-1):
        if A[y][x] % 2 != 0:
            A[y][x] -= 1
            A[y][x+1] += 1
            ret.append(str(y+1) + " " + str(x+1) + " " + str(y+1) + " " + str(x+1+1))
            N+=1

for y in range(H-1):
    if A[y][W-1] % 2 != 0:
        A[y][W-1] -= 1
        A[y+1][W-1] += 1
        ret.append(str(y+1) + " " + str(W) + " " + str(y+1+1) + " " + str(W))
        N+=1
        
print (N)
for r in ret:
    print (r)

Solution (Python):
from itertools import product

H, W = map(int, input().split())

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

output = ''
direction = -1
idou = 0
last_i = 0
last_j = 0
count = 0
j = -1
for i in range(H):
    direction *= -1
    j += direction
    for _ in range(W):
        if idou == 1:
            count += 1
            output += '{} {} {} {}\n'.format(last_i+1, last_j+1, i+1, j+1)
        if (a[i][j] + idou) % 2 == 1:
            idou = 1
        else:
            idou = 0
        last_i = i
        last_j = j
        j += direction

output = str(count) + '\n' + output.strip()
print(output)

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

a = [[int(i) for i in input().split()] for _ in range(H)]
N = 0
ans = ''

for y in range(H):
    for x in range(W):
        if a[y][x] % 2:
            for del_y, del_x in ([1, 0], [0, 1]):
                new_y, new_x = y + del_y, x + del_x
                if new_y<=H-1 and new_x<=W-1:
                    if a[new_y][new_x] % 2:
                        a[y][x] -= 1
                        a[new_y][new_x] += 1
                        N += 1
                        ans += "{0} {1} {2} {3}\n".format(y+1, x+1, new_y+1, new_x+1) 
                        break
            else:
                if x == W-1 and y == H-1:
                    pass
                elif x == W-1:
                    a[y][x] -= 1
                    a[y+1][x] += 1
                    N += 1
                    ans += "{0} {1} {2} {3}\n".format(y+1, x+1, y+1+1, x+1)
                else:
                    a[y][x] -= 1
                    a[y][x+1] += 1
                    N += 1
                    ans += "{0} {1} {2} {3}\n".format(y+1, x+1, y+1, x+1+1)

ans = "{}\n".format(N) + ans[:-1]
print(ans)

Solution (Python):
H, W = [int(i) for i in input().split()]
A = []
for i in range(H):
    A.append([int(i) for i in input().split()])
counter_bound = H * W
counter = 0
B = []
for i in range(H):
    if i % 2 == 0:
        tmp = range(W)
        direction = 1
    else:
        tmp = range(W-1,-1,-1)
        direction = -1
    for j in tmp:
        counter += 1
        if counter < counter_bound:
            if A[i][j] % 2:
                A[i][j] -= 1
                if j == tmp[-1]:
                    A[i+1][j] += 1
                    B.append((i+1,j+1,i+2, j+1))
                else:
                    A[i][j+direction] += 1
                    B.append((i+1,j+1,i+1,j+direction+1))
print(len(B))
for b in B:
    print(*b, sep= " ")

Solution (Python):
import math


def main():
    H, W = [int(a) for a in input().split()]
    A = [[int(a) for a in input().split()] for _ in range(H)]

    od = None
    res = []
    for i in range(H):
        if i % 2 == 0:
            r = range(W)
        else:
            r = reversed(range(W))
        for j in r:
            cell = A[i][j]
            if od is None:
                if cell % 2 != 0:
                    od = i, j
            else:
                res.append((od[0],od[1], i, j))
                if cell % 2 == 0:
                    od = i, j
                else:
                    od = None

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


if __name__ == '__main__':
    main()

Solution (Python):
h, w = map(int, input().split())
A = []
for i in range(h):
    if i%2 == 1:
        A.extend(reversed(list(map(int, input().split()))))
    else:
        A.extend(list(map(int, input().split())))
ans = []

def calcPos(i):
    if i//w % 2 == 0:
        return i//w + 1, i%w + 1
    else:
        return i//w + 1, w - i%w

for i in range(h*w-1):
    if A[i] % 2 == 1:
        A[i] -= 1
        A[i+1] += 1
        x,y = calcPos(i)
        x_,y_ = calcPos(i+1)
        ans.append("%d %d %d %d" % (x,y,x_,y_))
print(len(ans))
print(*ans, sep='\n')

Solution (Python):
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for i in range(H)]
n=0
B=[]
for j in range(H-1):
    for i in range(W):
        if A[j][i]%2!=0:
            
            A[j][i]-=1
            A[j+1][i]+=1
            n+=1
            B.append([j+1,i+1,j+2,i+1])
for i in range(W-1):
    if A[H-1][i]%2!=0:
        
        A[H-1][i]-=1
        A[H-1][i+1]+=1
        n+=1
        B.append([H,i+1,H,i+2])
print(n)
for i in range(len(B)):
    print(' '.join(map(str,B[i])))

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-1):
		if a[i][j]%2 == 0:
			continue
		
		l.append((i+1, j+1, i+1, j+2))
		a[i][j] -= 1
		a[i][j+1] += 1

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

print(len(l))

for y, x, y_, x_ in l:
	print('{} {} {} {}'.format(y, x, y_, x_))

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

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

ww = 2*w
m = 0
l = []

def pos(i):
    y = i // ww
    y *= 2
    ri = i % ww
    if ri < w:
        x = ri
    else:
        x = ww - ri - 1
        y += 1
    return y, x

for i in range(h*w-1):
    y, x = pos(i)
    if a[y][x] % 2 != m:
        yy, xx = pos(i+1)
        l.append((y+1, x+1, yy+1, xx+1))
        m = 1
    else:
        m = 0

print(len(l))
for y, x, yy, xx in l:
    print(y, x, yy, xx)

Solution (Python):
import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

r = True
act = list()
for i in range(1, h+1):
  r = not r
  for j in sorted(range(1, w+1), reverse=r):
    if m[i-1, j-1] % 2 == 1:
      if not r:
        
        if j == w:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        
        else:
          m[i-1, j] += 1
          act.append((i, j, i, j+1))
      else:
        
        if j == 1:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        
        else:
          m[i-1, j-2] += 1
          act.append((i, j, i, j-1))
    
    
print(len(act))
[print(*x) for x in act]

Solution (Python):
n, m = map(int, raw_input().split())
a = []
for i in range(n):
    row = map(int, raw_input().split())
    a.append(row)
op = []
for i in range(n):
    for j in range(m - 1):
        if a[i][j] % 2 == 1:
            a[i][j + 1] += 1
            op.append([i + 1, j + 1, i + 1, j + 2])
for i in range(n - 1):
    if a[i][m - 1] % 2 == 1:
        a[i + 1][m - 1] += 1
        op.append([i + 1, m, i + 2, m])
print len(op)
for tup in op:
    print " ".join(map(str, tup))

Solution (Python):
import numpy

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

board = numpy.reshape(board,(H,W))
cboard = board.copy()

move = []

for i in range(H):
    for j in range(W-1):
        if board[i,j] % 2 == 1:
            board[i,j+1] += 1
            board[i,j] += -1
            move.append([i+1,j+1,i+1,j+2])
            
for i in range(H-1):
    if board[i,W-1] % 2 == 1:
        board[i,W-1] += -1
        board[i+1,W-1] +=1
        move.append([i+1,W,i+2,W])
        
print(len(move))
for m in move:
    print(*m)

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

"""
counter = 0
B = [[0] * W] * H
ans = []


def dfs(x, y, counter):
    if B[x][y] == 1 or A[x][y] % 2 == 0:
        pass
    else:
        B[x][y] = 1
        for dx in range(-1, 2):
            for dy in range(-1, 2):
                if abs(dx) + abs(dy) == 1:
                    nx = x + dx
                    ny = y + dy
                    if 0 <= nx <= H-1 and 0 <= ny <= W-1:
                        if B[nx][ny] == 0 and A[nx][ny] % 2 == 1:
                            counter += 1
                            dfs(nx, ny, counter)
"""
ans = []
for i in range(H-1):
    for j in range(W):
        if A[i][j] % 2 == 1:
            ans.append([i+1, j+1, i+2, j+1])
            A[i+1][j] += 1
        else:
            pass


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


print(len(ans))
for i, j, i2, j2 in ans:
    print(i, j, i2, j2)

Solution (Python):
h,w = map(int, input().split())
d = [list(map(int,input().split())) for i in range(h)]
l = []
for i in range(h):
  if i%2==0:
    for j in range(w):
      l.append([i,j])
  else:
    for j in range(w-1,-1,-1):
      l.append([i,j])
m = 0
x = []
for i in range(len(l)-1):
  if d[l[i][0]][l[i][1]]%2==1:
    d[l[i][0]][l[i][1]] -= 1
    d[l[i+1][0]][l[i+1][1]] += 1
    x.append(i)
    m += 1
print(m)
for i in x:
  print(l[i][0]+1, l[i][1]+1, l[i+1][0]+1, l[i+1][1]+1)

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

a = [[0] * h for j in range(w)]
for y in range(h):
    for x, b in enumerate(map(int, input().split())):
        a[x][y] = b


ret = []
cnt = 0
for y in range(h):
    for x in range(w - 1):
        if a[x][y] % 2 == 1:
            a[x+1][y] += 1
            cnt += 1
            ret.append("{} {} {} {}".format(y+1, x+1, y+1, x+2))

for y in range(h - 1):
    if a[-1][y] % 2 == 1:
        a[-1][y+1] += 1
        cnt += 1
        ret.append("{} {} {} {}".format(y+1, w, y+2, w))

print(cnt)
for i in ret:
    print(i)

Solution (Python):
h, w = (int(i) for i in input().split(' '))


a=[]
for i in range(h):
    a.append([int(j) for j in input().split(' ')])

j = 0
p = []
tr = []
picked = False

for i in range(h):
                
    step = -1 if i%2 else 1
    j = w-1 if i%2 else 0
    while j >=0 and j < w:
        if a[i][j] % 2:
            if picked == False:
                picked = True
            else:
                tr.append([i,j])
                picked = False
                for t_index in range(len(tr)-1):
                    p.append((tr[t_index], tr[t_index+1]))
                tr = []

        if picked:
            tr.append([i,j])
        j = j + step

print(len(p))
for ans in p:
    print(ans[0][0]+1,ans[0][1]+1,ans[1][0]+1, ans[1][1]+1)

Solution (Python):
H, W = map(int, input().split())
a = []
for h in range(H):
    a.append([int(i) for i in input().split()])
def func(H, W, i):
    h_tmp = i // W
    w_tmp = i % W
    if h_tmp % 2 == 1:
        w_tmp = W - w_tmp - 1
    return  h_tmp, w_tmp
res = []
for i in range(0, H*W-1):
    h, w = func(H, W, i)
    if a[h][w] % 2 == 1:
        h1, w1 = func(H, W, i+1)
        a[h1][w1] += 1
        res.append(['{} {} {} {}'.format(h+1, w+1, h1+1, w1+1)])
print(len(res))
for i in range(len(res)):
    print(res[i][0])

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

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

board = [list(map(int,input().split())) for x in range(H)]
moves = []
for i in range(H):
    for j in range(W):
        if board[i][j] % 2 == 1:
            if i < H - 1 and (board[i+1][j] % 2 == 1 or j == W - 1):
                moves.append([i+1,j+1,i+2,j+1])
                board[i+1][j] += 1
            elif j < W - 1:
                moves.append([i+1,j+1,i+1,j+2])
                board[i][j+1] += 1

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

Solution (Python):


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


ops = []


oddrow = []
for r, row in enumerate(A):
    for i in range(len(row) - 1):
        if row[i] % 2 != 0:
            row[i]     -= 1
            row[i + 1] += 1
            ops.append((r, i, r, i+1))
    
    if r + 1 < H and row[-1] % 2 != 0:
        A[r]    [-1] -= 1
        A[r + 1][-1] += 1
        ops.append((r, W-1, r+1, W-1))


print(len(ops))
for op in ops:
    print(' '.join([str(x+1) for x in op]))

Solution (Python):
inputs = list(map(lambda x: int(x), input().strip().split()))

H = inputs[0]
W = inputs[1]

ahw = []

for i in range(H):
    w =list(map(lambda x: int(x), input().strip().split())) 
    ahw.append(w)

N = 0
hasCoin = 0
sousa = []

for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if ahw[i][j] % 2 == 0:
                continue

            if not j == W - 1:
                ahw[i][j] = ahw[i][j] - 1
                ahw[i][j+1] = ahw[i][j+1] + 1
                sousa.append("{} {} {} {}".format(i+1, j+1, i+1 , j+2))
                N += 1
            else:
                if i != H - 1:
                    ahw[i][j] = ahw[i][j] - 1
                    ahw[i+1][j] = ahw[i+1][j] + 1
                    sousa.append("{} {} {} {}".format(i+1, j+1, i+2 , j+1))
                    N += 1
    else:
        for j in range(W - 1, -1, -1):
            if ahw[i][j] % 2 == 0:
                continue

            if not j == 0:
                ahw[i][j] = ahw[i][j] - 1
                ahw[i][j-1] = ahw[i][j-1] + 1
                sousa.append("{} {} {} {}".format(i+1, j+1, i+1 , j))
                N += 1
            else:
                if i != H - 1:
                    ahw[i][j] = ahw[i][j] - 1
                    ahw[i+1][j] = ahw[i+1][j] + 1
                    sousa.append("{} {} {} {}".format(i+1, j+1, i+2 , j+1))
                    N += 1

print(N)
for el in sousa:
    print(el)

Solution (Python):



import sys


def main():
    h, w = [int(v) for v in sys.stdin.readline().rstrip().split(' ')]

    field = []

    for i in range(h):
        field.append([int(v) for v in sys.stdin.readline().rstrip().split(' ')])
            
    move = [[False for j in range(w)] for i in range(h)]
    count = 0

    for i in range(h):
        if (i&1)==1:
            for j in range(w-2, -1, -1):
                if (field[i][j+1]&1)==1:
                    move[i][j+1] = True
                    field[i][j+1] -= 1
                    field[i][j] += 1
                    count += 1
            if i<h-1 and (field[i][0]&1)==1:
                move[i][0] = True
                field[i][0]-=1
                field[i+1][0]+=1
                count += 1
        else:
            for j in range(1, w, +1):
                if (field[i][j-1]&1)==1:
                    move[i][j-1] = True
                    field[i][j-1] -= 1
                    field[i][j] += 1
                    count += 1
            if i<h-1 and (field[i][w-1]&1)==1:
                move[i][w-1] = True
                field[i][w-1]-=1
                field[i+1][w-1]+=1
                count += 1

    print(count)
    for i in range(h):
        if (i&1)==1:
            for j in range(w-2, -1, -1):
                if (move[i][j+1]):
                    print(i+1,j+2,i+1,j+1)
            if move[i][0]:
                print(i+1,1,i+2,1)
        else:
            for j in range(1, w, +1):
                if (move[i][j-1]):
                    print(i+1,j,i+1,j+1)
            if move[i][w-1]:
                print(i+1,w,i+2,w)

if __name__=="__main__":
    main()

Solution (Python):
h,w=map(int,input().split())
result=[]
b=[0]
for i in range(1,h+1):
    a=[0]+list(map(int,input().split()))
    r=[]
    for j in range(1,w+1):
        if len(r)==2:
            result.append([i,j-1,i,j])
        
        if a[j]%2==1:
            r+=[i,j]
            if len(r)==4:
                r=[]
    if len(r)==2:
        b.append(1)
    else:
        b.append(0)
r=[]
for i in range(1,h+1):
        if len(r)==2:
            result.append([i-1,w,i,w])
        
        if b[i]%2==1:
            r+=[i,j]
            if len(r)==4:
                r=[]
l=len(result)
print(l)
for i in range(l):
    print(result[i][0],result[i][1],result[i][2],result[i][3])

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

g = [map(int, raw_input().split()) for _ in range(H)]

mvs = []
for i in xrange(H):
    r = range(W) if i % 2 == 0 else range(W)[::-1]
    mv = 1 if i%2==0 else -1
    for j in r:
        if g[i][j] % 2 == 0:
            continue
        if 0<=j+mv and j+mv < W:
            g[i][j] -=1
            g[i][j+mv] +=1

            mvs.append((i+1,j+1,i+1,j+mv+1))
        elif i+1 < H:
            g[i][j] -= 1
            g[i+1][j] += 1
            mvs.append((i+1,j+1,i+2,j+1))

print len(mvs)
for m in mvs:
    print "%d %d %d %d" % m

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

grid = []

for i in range(H):
    grid.append(list(map(int, input().split())))

ope = []
tmp = True
p = 0
for h in range(H):
    if(tmp is True):
        W_list = [j for j in range(W)]
        tmp = False
    else:
        W_list = [j for j in reversed(range(W))]
        tmp = True

    for j in range(len(W_list)):
        w = W_list[j]
        if((grid[h][w] + p) % 2 == 0):
            p = 0
            continue

        if(w == W_list[-1]):
            nw = w
            nh = h + 1
        else:
            nw = W_list[j + 1]
            nh = h
        if(nh == H):
            continue

        ope.append([h + 1, w + 1, nh + 1, nw + 1])
        p = 1

print(len(ope))
for h, w, nh, nw in ope:
    print(h, w, nh, nw)

Solution (Python):


if __name__ == "__main__":
    H, W = list(map(int, input().split()))
    
    xs = [[0 for w in range(W)] for h in range(H)]
    for h in range(H):
        a = list(map(int, input().split()))
        for w in range(W):
            xs[h][w] = a[w]

    
    ops = []
    for h in range(H):
        for w in range(W):
            if xs[h][w]%2 != 0:
                
                if w < W-1:
                    
                    xs[h][w] -= 1
                    xs[h][w+1] += 1
                    ops.append("{} {} {} {}".format(h+1, w+1, h+1, w+1+1))
                elif w == W-1 and h != H-1:
                    
                    xs[h][w] -= 1
                    xs[h+1][w] += 1
                    ops.append("{} {} {} {}".format(h+1, w+1, h+1+1, w+1))
    print(len(ops))
    for op in ops:
        print(op)

Solution (Python):
h,w = map(int,input().split())
a = [[] for i in range(0,h)]
for i in range(0,h):
    A = list(map(int, input().split()))
    a[i].extend(A)
way = []
for i in range(0,h):
    for j in range(0,w):
        if i%2==0:
            way.append((i,j))
        else:
            way.append((i,w-j-1))
ans = []
for num in range(0,h*w-1):
    i,j = way[num]
    ni,nj = way[num+1]
    if a[i][j]%2 == 1:
        a[ni][nj] += 1
        ans.append((i,j,ni,nj))
print(len(ans))
for num in range(0,len(ans)):
    i,j,ni,nj= ans[num]
    print(i+1,j+1,ni+1,nj+1)

Solution (Python):
h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
i = 0
j = 0
k = 0
l = 0
ans = []
n = 1
while n < h*w:
    k += 2*((j+1)%2)-1
    if k == w or k == -1:
        k -= (k+abs(k))//k-1
        l += 1
    if a[j][i]%2 == 1:
        a[l][k] += 1
        ans.append([j+1,i+1,l+1,k+1])
    i = k
    j = l
    n += 1
print(len(ans))
for i in ans:
    for j in range(3):
        print(i[j], end = " ")
    print(i[-1])

Solution (Python):
H, W = map(int, input().split())
a = [[int(j) for j in input().split()] for i in range(H)]
N = 0
ans = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 0:
            continue
        if i + 1 >= H and j + 1 >= W:
            continue
        ti = i
        tj = j
        if i + 1 >= H:
            tj += 1
        else:
            ti += 1
        a[i][j]-=1
        a[ti][tj] += 1
        N += 1
        ans.append((i+1,j+1,ti+1,tj+1))

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

Solution (Python):




"""








"""
def get_input():
    height, width = (int(i) for i in input().split(' '))

    target = [[int(w) for w in input().split(" ")] for h in range(height)]
    size = [height, width]

    return size, target

def oshituke(size, target):
    """
    >>> oshituke([2, 3], [[1,2,3],[0,1,1]])
    """
    res = []
    for h in range(size[0]):
        for w in range(size[1]):
            if target[h][w] % 2 == 1:
                mode = checker(size, h, w)
                if mode == "b":
                    target[h][w] -= 1
                    target[h+1][w] += 1
                    res.append(' '.join([str(i) for i in [h+1, w+1, h+2, w+1]]))
                elif mode == "l":
                    target[h][w] -= 1
                    target[h][w+1] += 1
                    res.append(' '.join([str(i) for i in [h+1, w+1, h+1, w+2]]))

    print(len(res))
    _ = [print(i) for i in res]
    return


def checker(size, now_height, now_width):
    if now_height + 1 < size[0]:
        return "b"
    elif now_width + 1 < size[1]:
        return "l"
    return None

if __name__ == '__main__':
    
    
    size, target = get_input()
    oshituke(size, target)

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

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

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


ijlist =[]
for i,ahli in enumerate(alili):
    if i%2 ==1:
        ahli.reverse()
    for j,a in enumerate(ahli):
        ijlist.append((i+1,(1-i%2)*(j+1)+(i%2)*(w-j),a))


ans =[]

flag = False
for x,(i,j,a) in enumerate(ijlist):
    if a%2 == 1:
        flag = not flag
    if flag and (not x==len(ijlist)-1):
        (ii,jj,aa) = ijlist[x+1]
        ans.append((i,j,ii,jj))

n = len(ans)

print(n)
for i,j,k,l in ans:
    print(i,j,k,l)

Solution (Python):
"""
D - Make Them Even
行列のすべての要素を偶数にする(1つ奇数はok)
別に最低数ではない
一筆書きに総当たりすれば、いつかおわる
"""

height, width = map(int, input().split())

matrix = [[0 for h in range(width)] for w in range(height)]

for h in range(height):
    temp_w = []
    for part in input().split():
        temp_w.append(int(part))

    for w in range(width):
        
        matrix[h][w] = temp_w[w] % 2

move_list = []
for h in range(height):
    for w in range(width):
        cmp_h1 = h
        cmp_h2 = h
        cmp_w1 = w
        cmp_w2 = w + 1

        
        if (h % 2) != 0:
            w = width - w - 1
            cmp_w1 = w
            cmp_w2 = w - 1
            end = 0
        else:
            end = width - 1

        
        if end == cmp_w1:
            cmp_h2 = h + 1
            cmp_w2 = cmp_w1
        
        
        if cmp_h2 == height:
            continue
        
        
        if matrix[cmp_h1][cmp_w1] != 0:
            matrix[cmp_h2][cmp_w2] ^= 1
            move_list.append([cmp_h1+1, cmp_w1+1, cmp_h2+1, cmp_w2+1])

print(len(move_list))
for move in move_list:
    print("%d %d %d %d" % (move[0], move[1], move[2], move[3]))

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

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

for i in range(H):
  if sum(A[i]) % 2 == 1 and i < H-1:
    kurikosi_flag = True
  else:
    kurikosi_flag = False
   
  for j in range(W):
    
    if A[i][j] % 2 == 0:
      continue
    elif kurikosi_flag:
      Q.append([i+1, j+1, i+2, j+1])
      A[i+1][j] += 1
      kurikosi_flag = False
    elif i < H-1:
      Q.append([i+1, j+1, i+1, j+2])
      A[i][j+1] += 1
    elif j+1 < W:
      Q.append([i+1, j+1, i+1, j+2])
      A[i][j+1] += 1
      
print(len(Q))
for i in range(len(Q)):
  print(" ".join(map(str,Q[i])))

Solution (Python):
tate_yoko = list(map(int, input().split()))
tate = tate_yoko[0]
yoko = tate_yoko[1]
matrix = []
operation = []
count = 0
hoge = 0
x = 1
y = 1
coin_flag = False
printing1 = 0
printing2 = 0
printing3 = 0
printing4 = 0


for i in range(tate):
    list1 = list(map(int, input().split()))
    matrix.append(list1)

for j in range(tate * yoko):
    if matrix[y - 1][x - 1] % 2 == 1:
        if not coin_flag:
            matrix[y - 1][x - 1] = matrix[y - 1][x - 1] - 1
            coin_flag = True
            printing1 = y
            printing2 = x
        elif coin_flag:
            matrix[y - 1][x - 1] = matrix[y - 1][x - 1] + 1
            coin_flag = False
            printing3 = y
            printing4 = x
            operation.append([printing1, printing2, printing3, printing4])
            count = count + 1
            hoge = 0
    elif matrix[y - 1][x - 1] % 2 == 0:
        if coin_flag:
            printing3 = y
            printing4 = x
            operation.append([printing1, printing2, printing3, printing4])
            count = count + 1
            hoge = hoge + 1
            printing1 = y
            printing2 = x
    if y % 2 == 1:
        if x == yoko:
            y = y + 1
        else:
            x = x + 1
    elif y % 2 == 0:
        if x == 1:
            y = y + 1
        else:
            x = x - 1

if not coin_flag:
    hoge = 0
print(count - hoge)
length = len(operation)
for l in range(hoge):
    operation.pop(length - hoge)
for k in range(len(operation)):
    syuturyoku = " ".join(list(map(str, operation[k])))
    print(syuturyoku)