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 bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


H, W = list(map(int, sys.stdin.buffer.readline().split()))
A = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(H)]

X = []
Y = []
for i in range(H):
    if i % 2 == 0:
        X += list(range(W))
    else:
        X += list(reversed(range(W)))
    Y += [i] * W

op = []
for i in range(len(X) - 1):
    x1, y1 = X[i], Y[i]
    x2, y2 = X[i + 1], Y[i + 1]
    if A[y1][x1] % 2 == 1:
        op.append((y1 + 1, x1 + 1, y2 + 1, x2 + 1))
        A[y2][x2] += 1
print(len(op))
for row in op:
    print(*row)

Solution (Python):


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

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

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

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

Solution (Python):
H,W=map(int,input().split())
A=[0]*H
for i in range(H):
    A[i]=list(map(int,input().split()))
    for j in range(W):
        A[i][j]%=2
f=0
LIST=[]
for i in range(H):
    if(i%2==0):
        t=0
    else:
        t=W-1
    for j in range(W):
        k=abs(j-t)
        if(A[i][k]==1):
            if(f==1):
                q=i
                w=k
                while(True):
                    T=[]
                    T.append(a+1)
                    T.append(b+1)
                    if((b==0 and a%2==1) or (b==(W-1) and a%2==0)):
                        a+=1
                    elif(a%2==0):
                        b+=1
                    else:
                        b-=1
                    T.append(a+1)
                    T.append(b+1)
                    LIST.append(T)                        
                    if(q==a and w==b):
                        f=0
                        A[a][b]=0
                        break
                    
            else:
                a=i
                b=k
                A[a][b]=0
                f=1
        
print(len(LIST))
for i in range(len(LIST)):
    T=""
    for j in range(len(LIST[i])):
        T=T+str(LIST[i][j])+" "
    print(T[0:-1])

Solution (Python):
H,W = map(int,input().split())
A = [[0 for _ in range(W+1)]]
sumA = 0
for _ in range(H):
  row = [0] + list(map(int,input().split())) 
  A.append(row)
  sumA = sum(row)



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

print(c_num)
[print(*pro) for pro in pros]

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

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

print(len(ans))
for yp,xp,yn,xn in ans:
  print('{} {} {} {}'.format(yp,xp,yn,xn))

Solution (Python):
H, W = map(int, input().split())
field = [list(map(int, input().split())) for _ in range(H)]
direction = []
h_flag = False
for i, line in enumerate(field):
    v_flag = False
    for j, coin in enumerate(line):
        if v_flag:
            coin += 1
        if h_flag and j == W-1:
            coin += 1

        if coin % 2 == 0:
            v_flag = False
            if j == W-1:
                h_flag = False
        else:
            if j == W-1:
                h_flag = True
                if i == H-1:
                    continue
                direction.append("{} {} {} {}".format(i+1,j+1,i+2,j+1))
                continue
            v_flag = True
            direction.append("{} {} {} {}".format(i+1,j+1,i+1,j+2))
print(len(direction))
for line in direction:
    print(line)

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

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

def evenChk(nn):
    if nn % 2 == 0:
        return True
    else:
        return False


msg=[]
for i in range(H):
    for j in range(W-1):
        if evenChk(A[i][j]):
                continue
        else:
            A[i][j+1]+=1
            msg.append([i+ofs,j+ofs,i+ofs,j+ofs+1])

for i in range(H-1):
    if evenChk(A[i][W-1]):
        continue
    else:
        A[i+1][W-1]+=1
        msg.append([i+ofs,W+ofs-1,i+ofs+1,W+ofs-1])

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

Solution (Python):
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) 
rs = lambda: stdin.readline().rstrip()  

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

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

print(len(l))
print('\n'.join('{} {} {} {}'.format(a+1, b+1, c+1, d+1) for a, b, c, d in l))

Solution (Python):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [[]*W for _ in range(H)]
odds = [-1] * H
for i in range(H):
	M[i] = MAP()
	odds[i] = sum([1 for m in M[i] if m%2])

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

print(len(ans))
for a in ans:
	print(' '.join(list(map(str, [i+1 for i in a]))))

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w = inpl()
a = [inpl() for i in range(h)]
res = []
for y in range(h-1):
    for x in range(w):
        if a[y][x]%2:
            a[y][x] -= 1
            a[y+1][x] += 1
            res.append([y+1,x+1,y+2,x+1])
for x in range(w-1):
    if a[h-1][x]%2:
        a[h-1][x] -= 1
        a[h-1][x+1] += 1
        res.append([h,x+1,h,x+2])
print(len(res))
for i in res:
    print(*i)

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

Solution (Python):
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
s = []
res = []

for i in range(H):
  if i % 2:
    for j in range(W):
      s.append((i, j))
  else:
    for j in range(W - 1, -1, -1):
      s.append((i, j))
for i in range(H * W - 1):
  y, x = s[i]
  if a[y][x] % 2:
    res.append((y + 1, x + 1, s[i + 1][0] + 1, s[i + 1][1] + 1))
    a[s[i + 1][0]][s[i + 1][1]] += 1
print(len(res))
for r in res: print(*r)

Solution (Python):
h, w = map(int, input().split())
grid = [[i & 1 for i in map(int, input().split())] for _ in range(h)]


ans = []

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

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

print(len(ans))
for i in ans:
    print(*i, sep=" ")

Solution (Python):
h, w = map(int, input().split())
grid = [[i & 1 for i in map(int, input().split())] for _ in range(h)]


ans = []

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

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

print(len(ans))
for i in ans:
    print(*i, sep=" ")

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
grid = build_grid(H, W, 0, int)

ans = []
moving = False
for i in range(H):
    for j in range(W):
        
        if i % 2 == 1:
            j = W - j - 1
        
        if moving:
            grid[i][j] += 1
            moving = False
            t = (i, j)
            ans.append((s, t))
        
        if grid[i][j] % 2 == 1:
            moving = True
            grid[i][j] -= 1
            s = (i, j)

print(len(ans))
for (h1, w1), (h2, w2) in ans:
    print(h1+1, w1+1, h2+1, w2+1)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    A=LLIN(H)
    odds=[]
    ans=[]
    for i in range(H):
        if i&1:
            for j in range(W)[::-1]:
                if A[i][j]&1:
                    if j==0:
                        dy=1
                        dx=0
                    else:
                        dy=0
                        dx=-1
                    if i+dy!=H:
                        
                        ans.append((i+1,j+1,i+dy+1,j+dx+1))
                        A[i+dy][j+dx]+=1
        else:
            for j in range(W):
                if A[i][j]&1:
                    if j==W-1:
                        dy=1
                        dx=0
                    else:
                        dy=0
                        dx=1
                    if i+dy!=H:
                       
                        ans.append((i+1,j+1,i+dy+1,j+dx+1))
                        A[i+dy][j+dx]+=1

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


if __name__ == '__main__':
  main()

Solution (Python):
def main():
    H, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    coin_sum = 0
    for a in A:
        coin_sum += sum(a)
    ope_xy = []
    if coin_sum % 2 == 0:
        for h in range(H):
            for w in range(W):
                if A[h][w] & 1:
                    A[h][w] -= 1
                    if w < W - 1:
                        A[h][w + 1] += 1
                        ope_xy.append((h, w, h, w+1))
                    elif h < H - 1:
                        A[h + 1][w] += 1
                        ope_xy.append((h, w, h+1, w))
                    elif w == W - 1 and h == H - 1:
                        if A[h][w-1] & 1:
                            A[h][w-1] += 1
                            ope_xy.append((h, w, h, w-1))
                        else:
                            A[h-1][w] += 1
                            ope_xy.append((h, w, h-1, w))
    else:
        for h in range(H):
            for w in range(W):
                if A[h][w] & 1:
                    A[h][w] -= 1
                    if w < W - 1:
                        A[h][w + 1] += 1
                        ope_xy.append((h, w, h, w+1))
                    elif h < H - 1:
                        A[h + 1][w] += 1
                        ope_xy.append((h, w, h+1, w))
    print(len(ope_xy))
    for xy in ope_xy:
        print(xy[0] + 1, xy[1] + 1, xy[2] + 1, xy[3] + 1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import numpy as np
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
masu = np.zeros((H, W), dtype=int)
for h in range(H):
    masu[h] = [int(x) for x in input().strip().split()]

def nextp(p, H, W):
    if p[0] % 2 == 0 and p[1] == W-1:
        p[0] += 1
        return p[0] < H
    if p[0] % 2 == 1 and p[1] == 0:
        p[0] += 1
        return p[0] < H
    if p[0] % 2 == 0:
        p[1] += 1
        return True
    else:
        p[1] -= 1
        return True

ans = []
p = [0, 0]
not_end = True
while True:
    if masu[p[0], p[1]] % 2 == 1:
        masu[p[0], p[1]] -= 1
        p_ = p[:]
        not_end = nextp(p, H, W)
        if not not_end:
            masu[p_[0], p_[1]] += 1
            break
        ans.append([p_[0]+1, p_[1]+1, p[0]+1, p[1]+1])
        while True:
            if masu[p[0], p[1]] % 2 == 1:
                masu[p[0], p[1]] += 1
                not_end = nextp(p, H, W)
                break
            p_ = p[:]
            not_end = nextp(p, H, W)
            if not_end:
                ans.append([p_[0]+1, p_[1]+1, p[0]+1, p[1]+1])
                continue
            masu[p_[0], p[1]] += 1
            break
    else:
        not_end = nextp(p, H, W)
    if not_end:
        continue
    break

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

Solution (Python):

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

ODD = list()
RESULT = list()
BEFORE = [0, 0]

for i  in range(H):
    a_list = list(map(int, input().split()))
    w_range = range(W)
    
    if i%2 == 1:
        w_range = w_range[::-1]
    for j in w_range:
        if a_list[j] % 2 == 1:
            if ODD:
                ODD.pop()
                RESULT.append(BEFORE+[i+1,j+1])
            else:
                ODD.append([i+1, j+1])
        else:
            if ODD:
                RESULT.append(BEFORE+[i+1, j+1])
        BEFORE = [i+1, j+1]
print(len(RESULT))
for result in RESULT:
    print(" ".join([str(s) for s in result]))

Solution (Python):
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
flag = False
prev = [-1, -1]
ans = []
for i in range(0, H, 2):
    for j in range(W):
        if flag:
            ans.append(" ".join(map(str, [prev[0], prev[1], i+1, j+1])))
            a[i][j] += 1
            flag = False
        if a[i][j] % 2 == 1:
            flag = True
            prev = [i+1, j+1]
    if i < H-1:
        for j in reversed(range(W)):
            if flag:
                ans.append(" ".join(map(str, [prev[0], prev[1], i+2, j+1])))
                a[i+1][j] += 1
                flag = False
            if a[i+1][j] % 2 == 1:
                flag = True
                a[i+1][j] -= 1
                prev = [i+2, j+1]

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

Solution (Python):

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False



def main():
    H, W = MI()
    graph = [None] * H
    ans = []

    for i in range(H):
        graph[i] = list(MI())

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

    for idx, (i, j) in enumerate(q):
        coin = graph[i][j]
        if coin % 2 == 1 and idx + 1 < len(q):
            ni, nj = q[idx+1]
            graph[i][j] -= 1
            graph[ni][nj] += 1
            ans.append([i+1, j+1, ni+1, nj+1])

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


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

choices = []
for i in range(len(access) - 1):
    hi, wi = access[i]
    hi1, wi1 = access[i + 1]
    
    if A[hi][wi] % 2 == 1:
        A[hi][wi] -= 1
        A[hi1][wi1] += 1
        choices.append((hi, wi, hi1, wi1))

print(len(choices))

for x, y, z, w in choices:
    print(x + 1, y + 1, z + 1, w + 1)

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

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

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

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

    for w in range(W-1):
        if A[H-1][w] % 2 != 0:
            A[H-1][w+1] += 1
            ope.append((H,w+1,H,w+2))

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    H, W = map(int, readline().split())
    A = np.array([
        list(map(lambda x: int(x) % 2,
                 readline().split())) for _ in range(H)
    ])

    aa = []
    for h in range(H):
        for w in range(W - 1):
            if A[h, w] == 1:
                A[h, w + 1] += 1
                aa.append([h + 1, w + 1, h + 1, w + 2])

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

    print(len(aa))

    for a in aa:
        print(*a)


main()

Solution (Python):
h,w=map(int,input().split())
field=[]
for i in range(h):
    field.append(list(map(int,input().split())))
opr=0
ans=[]
for j in range(h):
    for k in range(w):
          if field[j][k]%2==1 and k!=w-1:
              field[j][k]-=1
              field[j][k+1]+=1
              opr+=1
              ans.append([j+1,k+1,j+1,k+2])
          elif field[j][k]%2==1 and k==w-1 and j<h-1: 
              field[j][k]-=1
              field[j+1][k]+=1
              opr+=1
              ans.append([j+1,k+1,j+2,k+1]) 
   
print(opr)
for l in range(len(ans)):
    print(ans[l][0],ans[l][1],ans[l][2],ans[l][3])

Solution (Python):
H,W = map(int,input().split())
A = [list(map(int, input().split(' '))) for i in range(H)]
A = [[A[i][j] % 2 for j in range(W)] for i in range(H)]
Ainv = []
for i in range(H):
    if i % 2 == 0:
        Ainv.append(A[i])
    else:
        Ainv.append(A[i][::-1])
flg = 0
pls = []
for i in range(H):
    for j in range(W):
        if Ainv[i][j] == 1:
            flg += 1
            if i % 2 == 0:
                pls.append([i+1,j+1])
            else:
                pls.append([i+1,W-j])
ans = []
for i in range(1,len(pls),2):
    goal = pls[i]
    start = pls[i-1]
    while start != goal:
        ps0 = start[0]
        ps1 = start[1]
        if start[0] % 2 != 0:
            if start[1] < W:
                start[1] += 1
            else:
                start = [start[0]+1,W]
        else:
            if start[1] > 1:
                start[1] -= 1
            else:
                start = [start[0]+1,1]
        ans.append([ps0,ps1,start[0],start[1]])

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()

h, w = map(int, input().split())
field = [None] * h
for i in range(h):
    field[i] = list(map(lambda x: int(x) % 2, input().split()))

outs = []

for i in range(h-1):
    for j in range(w):
        if not field[i][j]: continue
        field[i+1][j] = int(field[i+1][j] ^ 1)
        outs.append((i+1, j+1, i+2, j+1))

for i in range(w-1):
    if not field[h-1][i]: continue
    field[h-1][i+1] = int(field[h-1][i+1] ^ 1)
    outs.append((h, i+1, h, i+2))

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

Solution (Python):


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

yx = []
for i in range(H*W):
    y = i // W
    x = W - i % W - 1 if y % 2 else i % W 
    yx.append((y, x))

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

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

Solution (Python):
def solve(h, w, a):
    xs = list(range(w))
    v = []
    for y in range(h):
        for x in xs:
            v.append((x, y))
        xs = xs[::-1]
    res = []
    for i in range(len(v) - 1):
        x, y = v[i]
        nx, ny = v[i+1]
        if a[y][x] % 2 != 0:
            a[ny][nx] += 1
            res.append((y+1, x+1, ny+1, nx+1))
    print(len(res))
    for y, x, ny, nx in res:
        print(y, x, ny, nx)

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

Solution (Python):
H,W=map(int,input().split())
grid=[None]*H
for i in range(H):
  grid[i]=list(map(int,input().split()))
  
ans=[]
for i in range(H):
  for j in range(W):
    if grid[i][j]%2==1:
      if j+1<W:
        grid[i][j]-=1
        grid[i][j+1]+=1
        ans.append([i+1,j+1,i+1,j+1+1])
      elif i+1<H:
        grid[i][j]-=1
        grid[i+1][j]+=1
        ans.append([i+1,j+1,i+1+1,j+1])
      else:
        continue        

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

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

ans = []
last_row = []
for h in range(H):
    line = grid[h]
    for w in range(W-1):
        if line[w] % 2 == 1:
            ans.append((h+1, w+1, h+1, w+2))
            line[w+1] += 1
    last_row.append(line[-1])

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

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

Solution (Python):
H, W = map(int, input().split())
a = [[int(i) for i in input().split()] for _ in range(H)]
ans = []
for y in range(H):
    for x in range(W):
        if a[y][x] % 2 == 1:
            if y == H-1 and x == W-1:
                break
            if y < H-1:
                a[y][x] -= 1
                a[y+1][x] += 1
                ans.append((y+1, x+1, y+2, x+1))
            else:
                a[y][x] -= 1
                a[y][x+1] += 1
                ans.append((y+1, x+1, y+1, x+2))

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

Solution (Python):

import sys

def solve(H: int, W: int, a: "List[List[int]]"):
    answer = []
    for y in range(H):
        if y%2 == 0:
            for x in range(W):
                if a[y][x]%2 ==1:
                    if x+1 < W:
                        a[y][x+1] += 1
                        answer.append((y+1,x+1,y+1,x+2))
                    elif y+1 < H:
                        a[y+1][x] += 1
                        answer.append((y+1,x+1,y+2,x+1))                       
        else:
            for x in range(W-1,-1,-1):
                if a[y][x]%2 ==1:
                    if x-1 >= 0:
                        a[y][x-1] += 1
                        answer.append((y+1,x+1,y+1,x))
                    elif y+1 < H:
                        a[y+1][x] += 1
                        answer.append((y+1,x+1,y+2,x+1))                       
 
    
    print(len(answer))
    for aa in answer:
        print(" ".join(map(str,aa)))


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    a = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  
    solve(H, W, a)

if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
ans=[]
for i in range(n):
  for j in range(m-1):
    if l[i][j]%2==1:
      ans.append([str(i+1),str(j+1),str(i+1),str(j+2)])
      l[i][j]=2
      l[i][j+1]+=1
for i in range(n-1):
  if l[i][-1]%2==1:
    ans.append([str(i+1),str(m),str(i+2),str(m)])
    l[i][-1]=2
    l[i+1][-1]+=1
print(len(ans))
for i in range(len(ans)):
  print(" ".join(ans[i]))