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):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
H,W = map(int,input().split())
a=[[0] for f in range(H)]
ans=[]
for i in range(H):
 a[i]=list(map(int,input().split()))
for i in range(H):
 for j in range(W-1):
  if a[i][j]%2==1 :
   ans.append([i+1,j+1,i+1,j+2])
   a[i][j+1]+=1
for i in range(H-1):
 if a[i][W-1]%2==1 :
  ans.append([i+1,W,i+2,W])
  a[i+1][W-1]+=1
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)]
z=[]
m=[]
for i in range(h):
  for j in range(w)[::(-1)**i]:
    m.append((i,j))
for i in range(h*w-1):
  x,y=m[i]
  if a[x][y]%2:
    X,Y=m[i+1]
    z.append([x+1,y+1,X+1,Y+1])
    a[X][Y]+=1
print(len(z))
for i in z:
  print(*i)

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


def generate_unagi():
    for i in range(h):
        if i % 2 == 0:
            for j in range(w):
                yield (i, j)
        else:
            for j in reversed(range(w)):
                yield (i, j)


ans = []
it = list(generate_unagi())
for (i, j), (i2, j2) in zip(it, it[1:]):
    if fld[i][j] % 2 == 0:
        continue
    fld[i][j] -= 1
    fld[i2][j2] += 1
    ans.append((i+1, j+1, i2+1, j2+1))

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

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

ans = []
for i in range(h):
    for j in range(w):
        if fld[i][j] % 2 == 0:
            continue

        if j < w-1:
            if fld[i][j+1] % 2 == 1:
                ans.append((i+1, j+1, i+1, j+2))
                fld[i][j] -= 1
                fld[i][j+1] += 1
                continue

        if i < h-1:
            if fld[i+1][j] % 2 == 1:
                ans.append((i+1, j+1, i+2, j+1))
                fld[i][j] -= 1
                fld[i+1][j] += 1
                continue

        if j < w-1:
            ans.append((i+1, j+1, i+1, j+2))
            fld[i][j] -= 1
            fld[i][j+1] += 1
            continue

        if i < h-1:
            ans.append((i+1, j+1, i+2, j+1))
            fld[i][j] -= 1
            fld[i+1][j] += 1
            continue


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

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

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

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

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

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

Solution (Python):
import sys
readline = sys.stdin.readline

def main():
    H, W = map(int, readline().rstrip().split())
    A = [list(map(int, readline().rstrip().split())) for _ in range(H)]
    res = []
    cnt = 0
    for h in range(H):
        for w in range(W-1):
            if A[h][w] % 2 == 1:
                A[h][w+1] += 1
                cnt += 1
                res.append('{} {} {} {}'.format(h+1, w+1, h+1, w+2))

    for h in range(H-1):
        if A[h][W-1] % 2 == 1:
            A[h+1][W-1] += 1
            cnt += 1
            res.append('{} {} {} {}'.format(h+1, W, h+2, W))
    
    print(cnt)
    print(*res, sep='\n')


if __name__ == '__main__':
    main()

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


S = []
for i in range(h):
    if i & 1:
        for j in range(w-1):
            if A[i][j] & 1:
                S.append([i+1, j+1, i+1, j+2])
                A[i][j+1] += 1
        if A[i][w-1] & 1 and i < h-1:
            S.append([i+1, w, i+2, w])
            A[i+1][w-1] += 1
    else:
        for j in reversed(range(1, w)):
            if A[i][j] & 1:
                S.append([i+1, j+1, i+1, j])
                A[i][j-1] += 1
        if A[i][0] & 1 and i < h-1:
            S.append([i+1, 1, i+2, 1])
            A[i+1][0] += 1

print(len(S))
for x in S:
    print(" ".join([str(n) for n in x]))

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Ans = []
cnt = 0
for i in range(H):
    for j in range(W):
        if (i == H-1) and (j == W-1):
            continue
        if A[i][j] % 2 != 0:
            if j == W-1:
                A[i + 1][j] += 1
                Ans.append((str(i+1), str(j+1), str(i+2), str(j+1)))
            else:
                A[i][j + 1] += 1
                Ans.append((str(i+1), str(j+1), str(i+1), str(j+2)))

print(len(Ans))
for ans in Ans:
    print(' '.join(ans))

Solution (Python):
def main():
    h, w, *a = map(int, open(0).read().split())

    cnt = 0
    ans = ''
    for k in range(h * w):
        i, j = divmod(k, w)

        if a[k] % 2 == 0:
            continue
        if j != w - 1:
            cnt += 1
            a[k + 1] += 1
            ans += '{0} {1} {2} {3}\n'.format(i + 1, j + 1, i + 1, j + 2)
        elif i != h - 1:
            cnt += 1
            a[k + w] += 1
            ans += '{0} {1} {2} {3}\n'.format(i + +2, j + 1, i + 1, j + 1)
        else:
            pass
    print(cnt)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    h, w, *a = map(int, open(0).read().split())
    m = [a[i * w:(i + 1) * w] for i in range(h)]
    m.append([2] * w)

    ans = ''
    cnt = 0
    for i in range(h):
        for j in range(w):
            if m[i][j] % 2 == 0:
                continue
            if j != w - 1:
                cnt += 1
                m[i][j + 1] += 1
                ans += '{0} {1} {2} {3}\n'.format(i + 1, j + 1, i + 1, j + 2)
            elif i != h - 1:
                cnt += 1
                m[i + 1][j] += 1
                ans += '{0} {1} {2} {3}\n'.format(i + +2, j + 1, i + 1, j + 1)
            else:
                pass
    print(cnt)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
h , w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
zyun = []
for i in range(1,h+1):
    if i % 2 == 1:
        for j in range(1,w+1):
            zyun.append((i,j))
    elif i % 2 == 0:
        for j in reversed(range(1,w+1)):
            zyun.append((i,j))
p = 0
cou = 0
ans = []
for y , x in zyun:
    if p == 0 and a[y-1][x-1] % 2 == 1:
        maey = y
        maex = x
        p = 1
    elif p == 1:
        ans.append([maey,maex,y,x])
        cou += 1
        if a[y-1][x-1] % 2 == 0:
            maey = y
            maex = x
        elif a[y-1][x-1] % 2 == 1:
            p = 0
print(cou)
for i in range(len(ans)):
    print(*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 == 1:
            a[i][j] -= 1
            a[i][j+1] += 1
            ans.append([i, j, i, j+1])

w = W - 1
for i in range(H-1):
    if a[i][w] % 2 == 1:
        a[i][w] -= 1
        a[i+1][w] += 1
        ans.append([i, w, i+1, w])
print(len(ans))
aaaa = [list(map(lambda x: x+1, li)) for li in ans]
for x,y,z,a in aaaa:
    print(x, y, z, a)

Solution (Python):


H, W = map(int, input().split())
A = [[0] * W for _ in range(H)]
for i in range(H):
    A[i] = list(int(x) for x in input().split())

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

cnt = 0
arr = []
for idx in range(len(path)-1):
    if A[path[idx][0]][path[idx][1]]%2 == 1:
        A[path[idx][0]][path[idx][1]] -= 1
        A[path[idx+1][0]][path[idx+1][1]] += 1
        cnt += 1
        arr.append((path[idx][0]+1, path[idx][1]+1, path[idx+1][0]+1, path[idx+1][1]+1))

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

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    h, w = list(map(int, input().strip().split()))
    a = []
    for i in range(h):
        a.append(list(map(int, input().strip().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:
                    a[i+1][j] += 1
                    p = i+2
                    q = j+1
                else:
                    a[i][j+1] += 1
                    p = i+1
                    q = j+2
                a[i][j] -= 1
                ans.append((i+1, j+1, p, q))
    print(len(ans))
    for t in ans:
        print(*t)
if __name__ == '__main__':
    main()

Solution (Python):
H,W=map(int,input().split())
a=[0]*H
for i in range(H):
  a[i]=list(map(int,input().split()))
  
move_even = [ (0,1) ,(1,0) ]
move_odd  = [ (0,-1),(1,0) ]
cnt=0
ans_list=[]

for i in range(H):
  if i%2==0:  
    for j in range(W):
      for move in move_even:
        p = i+move[0]
        q = j+move[1]
        if 0<=p<=H-1 and 0<=q<=W-1:
          if a[i][j]%2==1:
            a[i][j] += -1
            a[p][q] +=  1
            ans_list.append([i+1,j+1,p+1,q+1])
            cnt+=1
            break                
  else: 
    for j in range(W-1,-1,-1):
      for move in move_odd:
        p = i+move[0]
        q = j+move[1]
        if 0<=p<=H-1 and 0<=q<=W-1:
          if a[i][j]%2==1:
            a[i][j] += -1
            a[p][q] +=  1
            ans_list.append([i+1,j+1,p+1,q+1])
            cnt +=1
            break         
print(cnt)
for queue in ans_list:
  print(*queue)

Solution (Python):
h, w = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(h)]
s = []
for i in range(h):
    for j in range(w-1):
        if m[i][j] & 1:
            s.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
            m[i][j+1] += 1
for i in range(h-1):
    if m[i][w-1] & 1:
        s.append("{} {} {} {}".format(i+1, w, i+2, w))
        m[i+1][w-1] += 1
print(len(s))
print("\n".join(s))

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

a = []

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

d = 1
x = 0

moving = 0

ans = []

st = []

prev_y = 0
prev_x = 0

for y in range(h):
    while 0 <= x < w:
        if moving == 0 and a[y][x] % 2 != 0:
            moving = 1
        elif moving == 1 and a[y][x] % 2 != 0:
            st.append(' '.join(list(map(str, [prev_y+1, prev_x+1, y+1, x+1]))))
            moving = 0
            ans += st
            st = []
        elif moving == 1 and a[y][x] % 2 == 0:
            st.append(' '.join(list(map(str, [prev_y+1, prev_x+1, y+1, x+1]))))
        prev_y = y
        prev_x = x

        x += d

    d *= (-1)
    x += d

print(len(ans))

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

Solution (Python):
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
A = [None] * H
for i in range(H):
  A[i] = list(map(int,readline().split()))
  



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

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

Solution (Python):
(h,w),*a=[map(int,o.split())for o in open(0)]
B=[];l=[]
for y in range(h):
 *A,=a[y]
 for x in range(1,w):c=A[x-1]%2;l+=[(y+1,x,y+1,x+1)]*c;A[x]+=c
 B+=A[w-1],
 if y and B[-2]%2:l+=(y,w,y+1,w),;B[y]+=1
print(len(l))
for a in l:print(*a)

Solution (Python):
(h,w),*a=[map(int,o.split())for o in open(0)]
B=[];l=[]
for y in range(h):
 *A,=a[y];x=0
 for x in range(1,w):c=A[x-1]%2;l+=[(y+1,x,y+1,x+1)]*c;A[x]+=c
 B+=A[x],
 if y and B[-2]%2:l+=(y,w,y+1,w),;B[y]+=1
print(len(l))
for a in l:print(*a)

Solution (Python):
(h,w),*a=[map(int,o.split())for o in open(0)]
B=[];l=[]
for y in range(h):
 *A,=a[y];x=0
 for x in range(1,w):
  if A[x-1]%2:l+=(y+1,x,y+1,x+1),;A[x]+=1
 B+=A[x],
 if y and B[-2]%2:l+=(y,w,y+1,w),;B[y]+=1
print(len(l))
for a in l:print(*a)

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

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

Solution (Python):
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    cnt = 0
    manip = []
    for i in range(H):
        for j in range(W - 1):
            if A[i][j] % 2 != 0:
                cnt += 1
                manip.append((i, j, i, j + 1))
                A[i][j] -= 1
                A[i][j + 1] += 1
    
    for i in range(H - 1):
        if A[i][W - 1] % 2 != 0:
            cnt += 1
            manip.append((i, W - 1, i + 1, W - 1))
            A[i][W - 1] -= 1
            A[i + 1][W - 1] += 1
    
    print(cnt)
    for a, b, c, d in manip:
        print("{} {} {} {}".format(a + 1, b + 1, c + 1, d + 1))


                



if __name__ == "__main__":
    main()

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

    ans = []
    for r, row in enumerate(A):
        for c, cell in enumerate(row):
            if c == W - 1:
                if cell & 1 and r != H - 1:
                    A[r + 1][c] += 1
                    ans.append((r, c, r + 1, c))
            else:
                if cell & 1:
                    A[r][c + 1] += 1
                    ans.append((r, c, r, c + 1))
    print(len(ans))
    for opr in ans:
        print(*map(lambda x: x + 1, opr))


if __name__ == '__main__':
    main()

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

    nh = 0
    nw = 0
    ans = []
    haveCoin = False
    while True:

        if field[nh][nw] % 2 != 0:
            if haveCoin:
                haveCoin = False
            else:
                haveCoin = True
        
        frm = [nh+1,nw+1]

        if nh % 2 == 0:
            nw += 1
            if nw == W:
                nh += 1
                nw = W-1
        else:
            nw -= 1
            if nw == -1:
                nh += 1
                nw = 0
        
        to = [nh+1,nw+1]

        if nh == H:
            break
            
        if haveCoin:
            ans.append(frm+to)
    
    print(len(ans))
    for elem in ans:
        print(*elem)

if __name__ == '__main__':
    solve()

Solution (Python):
from collections import deque
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
ans = deque()
y = 0
while y < H:
  x = 0 if y % 2 == 0 else W-1
  dx = 1 if y % 2 == 0 else -1
  d = 0
  while dx > 0 and x < W-1 or dx < 0 and x > 0:
    if A[y][x] % 2 == 1:
      ans.append("%d %d %d %d"%(y+1, x+1, y+1, x+dx+1))
      A[y][x] -= 1
      A[y][x+dx] += 1
    x += dx
  if A[y][x] % 2 == 1 and y < H-1:
    ans.append("%d %d %d %d"%(y+1, x+1, y+2, x+1))
    A[y][x] -= 1
    A[y+1][x] += 1
  y += 1
print(len(ans))
print("\n".join(ans))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





H,W = IL()
A = ILL(H)

x = 0
y = -1
temoti = None

if H%2 == 1:
  xg = W-1
else:
  xg = 0
yg = H-1


ans = []
while x!=xg or y!=yg:
  if x==0:
    if y%2 == 1:
      y += 1
    else:
      if W!=1:
        x += 1
      else:
        y += 1
  elif x==W-1:
    if y%2 == 1:
      x -= 1
    else:
      y += 1
  else:
    if y%2 == 1:
      x -= 1
    else:
      x += 1
  if temoti == None:
    if A[y][x] % 2 == 1:
      temoti = (y,x)
  else:
    if A[y][x] % 2 == 1: 
      ans.append([temoti[0]+1,temoti[1]+1,y+1,x+1])
      temoti = None
    else:
      ans.append([temoti[0]+1,temoti[1]+1,y+1,x+1])
      temoti = (y,x)
print(len(ans))    
for a in ans:
  print(*a)

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

cnt = 0
ope = []
for i in range(H):
    nowH = i
    for j in range(W):
        if i%2==1:
            nowW = W-1-j
        else:
            nowW = j

        if j==W-1:
            nextH = i+1
            nextW = nowW
        else:
            nextH = nowH
            if i%2==1:
                nextW = nowW-1
            if i%2==0:
                nextW = nowW+1

        if nextH>=H or nextW>=W:
            break

        if A[nowH][nowW]%2==1:
            A[nowH][nowW] += -1
            A[nextH][nextW] += 1
            ope.append([nowH+1,nowW+1,nextH+1,nextW+1])
            cnt+=1

print(cnt)
for i in range(len(ope)):
    print(ope[i][0],ope[i][1],ope[i][2],ope[i][3])

Solution (Python):
def make_path(l,y1,x1,y2,x2):
    current_x = x1
    current_y = y1
    if x2 == x1:
        for i in range(y2-y1):
            l.append((current_y,current_x,current_y+1,current_x))
            current_y += 1
    elif x2 > x1:
        if y1 % 2 == 1:
            for i in range(x2-x1):
                l.append((current_y,current_x,current_y,current_x+1))
                current_x += 1
            for i in range(y2-y1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
        else:
            l.append((current_y,current_x,current_y+1,current_x))
            current_y += 1
            for i in range(x2-x1):
                l.append((current_y,current_x,current_y,current_x+1))
                current_x += 1
            for i in range(y2-y1-1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
    else:
        if y1 % 2 == 1:
            l.append((current_y,current_x,current_y+1,current_x))
            current_y += 1
            for i in range(x1-x2):
                l.append((current_y,current_x,current_y,current_x-1))
                current_x -= 1
            for i in range(y2-y1-1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
        else:
            for i in range(x1-x2):
                l.append((current_y,current_x,current_y,current_x-1))
                current_x -= 1
            for i in range(y2-y1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
                
import numpy as np

H,W,*af = map(int, open(0).read().split())
a = np.array(af).reshape(H,W).tolist()
ab = [[x % 2 for x in y] for y in a]
rev = False
found_first = False
ans = []
temp = [0] * 4
x_count = 0
y_count = 0
for y in ab:
    y_count += 1
    if rev == False:
        x_count += 1
        for x in y:
            if x == 1:
                if found_first == False:
                    temp[0] = y_count
                    temp[1] = x_count
                    found_first = True
                else:
                    temp[2] = y_count
                    temp[3] = x_count
                    make_path(ans,*temp)
                    found_first = False
            x_count += 1
        rev = True
    else:
        x_count -= 1
        for x in reversed(y):
            if x == 1:
                if found_first == False:
                    temp[0] = y_count
                    temp[1] = x_count
                    found_first = True
                else:
                    temp[2] = y_count
                    temp[3] = x_count
                    make_path(ans,*temp)
                    found_first = False
            x_count -= 1
        rev = False
print(len(ans))
for x in ans:
    print(*x)

Solution (Python):
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
odd_num = 0
odd_point = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2:
            odd_num += 1
            odd_point += [[i, j]]
            a[i][j] = 1
        else:
            a[i][j] = 0

moves = []
i, j = 0, 0
direction = 1
while len(moves) < H*W-1:
    pre_i, pre_j = i, j
    if j+1 == W and direction == 1:
        i += 1
        direction *= -1
    elif j-1 == -1 and direction == -1:
        i += 1
        direction *= -1
    else:
        j += direction
    moves += [(pre_i, pre_j, i, j)]

flag = False
ans = []
for pre_i, pre_j, i, j in moves:
    if a[pre_i][pre_j] == 1:
        if flag == False:
            flag = True
        else:
            flag = False
    if flag:
        ans += [(pre_i+1, pre_j+1, i+1, j+1)]
print(len(ans))
for pre_i, pre_j, i, j in ans:
    print(pre_i, pre_j, i, j)

Solution (Python):
import sys


h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
d=[]
for i in range(h):
    for j in range(w):
        if a[i][j]%2==1:
             d.append((i,j))
n=len(d)
if n==0:
  print(0)
  exit()
d_s=set(d)
ans=[]
f=False
y=d[0][0]
x=d[0][1]
xp=x+1
yp=y
while True:
    if y%2==0:
      xp=x+1
    else:
      xp=x-1
    yp=y
    if (y,x) in d_s:
      while True:
          if (yp,xp) not in d_s and -1<xp<w and yp<h:
              if yp%2==0:
                  ans.append([y+1,x+1,yp+1,xp+1])
                  x=xp
                  xp+=1
              else:
                  ans.append([y+1,x+1,yp+1,xp+1])
                  x=xp
                  xp-=1
              y=yp
          elif (yp,xp) not in d_s and xp>w-1:
              xp=w-1
              yp+=1
          elif (yp,xp) not in d_s and xp<0:
              xp=0
              yp+=1
          elif (yp,xp) in d_s:
              ans.append([y+1,x+1,yp+1,xp+1])
              if yp%2==0:
                x=xp+1
                y=yp
              else:
                x=xp-1
                y=yp
              break
          elif yp>h-1:
            f=True
            break
      if f:
        break
    else:
      if y%2==0:
        x+=1
      else:
        x-=1
      if x>w-1:
        x=w-1
        y+=1
      elif x<0:
        x=0
        y+=1
    if y>h-1:
      break
print(len(ans))
for i in ans:
  print(*i)

Solution (Python):
h, w = map(int, input().split())
mat = []
for i in range(h):
  mat.append(list(map(int, input().split())))
sousa = []
for y in range(h):
  if y % 2 == 0:
    x = -1
    for x in range(w-1):
      if mat[y][x] % 2 == 1:
        mat[y][x] -= 1
        mat[y][x+1] += 1
        sousa.append((y+1, x+1, y+1, x+1+1))
    x += 1
    if mat[y][x] % 2 == 1 and y < h-1:
        mat[y][x] -= 1
        mat[y+1][x] += 1
        sousa.append((y+1, x+1, y+1+1, x+1))
  if y % 2 == 1:
    x = w
    for x in range(w-1, 0, -1):
      if mat[y][x] % 2 == 1:
        mat[y][x] -= 1
        mat[y][x-1] += 1
        sousa.append((y+1, x+1, y+1, x+1-1))
    x -= 1
    if mat[y][x] % 2 == 1 and y < h-1:
        mat[y][x] -= 1
        mat[y+1][x] += 1
        sousa.append((y+1, x+1, y+1+1, x+1))

print(len(sousa))
for y,x,y1,x1 in sousa:
  print(y,x,y1,x1)

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

query = []
for i in range(H):
    if i%2==0:
        lis = [(i, j) for i, j in enumerate(list(map(int, input().split())))]
    else:
        lis = [(i, j) for i, j in enumerate(list(map(int, input().split())))][::-1]
    query += lis

odd = 0
move = []
last = (0, 0)
for i, (w, q) in enumerate(query):
    if odd:
        move.append((last[0], last[1], i//W+1, w+1))
        if q%2==1:
            odd = 0
        else:
            last = (i//W+1, w+1)
    else:
        if q%2==1:
            odd = 1
            last = (i//W+1, w+1)

print(len(move))
for l in move:
    print(*l)

Solution (Python):
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
c = 0
N = 0
ans = []
for i in range(H):
  for j in range(W):
    if a[i][j]%2==1:
      if j+1<W:
        ans.append([i+1,j+1,i+1,j+2])
        a[i][j]-=1
        a[i][j+1]+=1
        N += 1
      elif i+1<H:
        a[i][j]-=1
        a[i+1][j]+=1
        ans.append([i+1,j+1,i+2,j+1])
        N += 1
    
        
print(N)
for i in range(N):
  L=[str(x) for x in ans[i]]
  L=" ".join(L)
  print(L)

Solution (Python):
H, W = map(int, input().split(' '))
A = [list(map(int, input().split(' '))) for i in range(H)]
cnt = 0
ans = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 0:
            continue
        tmp = ''
        flg = True
        for x, y in [[1, 0], [0, 1]]:
            if 0 <= i+x < H and 0 <= j+y < W:
                if A[i+x][j+y] % 2 != 0:
                    A[i][j] -= 1
                    cnt += 1
                    A[i+x][j+y] += 1
                    ans.append([i, j, i+x, j+y])
                    flg = False
                    break
                else:
                    tmp = [x, y]
        if flg and tmp:
            cnt += 1
            A[i+tmp[0]][j+tmp[1]] += 1
            A[i][j] -= 1
            ans.append([i, j, i+tmp[0], j+tmp[1]])
print(cnt)
for i, j, k, l in ans:
    print(i+1, j+1, k+1, l+1)