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):
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    h, w, *a = map(int, s.split())
    *a, = chunked(a, w)
    ans = []
    for i in range(h):
        for j in range(w - 1):
            if a[i][j] % 2 == 1:
                ans.append("{} {} {} {}".format(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("{} {} {} {}".format(i + 1, w, i + 2, w))
            a[i + 1][w - 1] += 1
    return "{}\n".format(len(ans)) + "\n".join(ans)


n, m = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

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

def next():
    i = j = k = 0
    while k < H*W - 1:
        k += 1
        i = k // W
        if k % W != 0:
            j += (-1)**(i)
        
        yield i, j

log = []
i = j = 0
n = next()
for ni, nj in n:
    if coins[i][j] % 2 == 1:
        coins[i][j] -= 1
        coins[ni][nj] += 1
        log.append((i+1, j+1, ni+1, nj+1))
    i, j = ni, nj

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

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

cn = 0
ope = []
for i in range(h):
    for j in range(w):
        if A[i][j]%2 != 0:
            if i != h-1:
                A[i+1][j] += 1
                cn += 1
                ope.append("{0} {1} {2} {3}".format(i+1,j+1,i+2,j+1))
            elif j != w-1:
                A[i][j+1] += 1
                ope.append("{0} {1} {2} {3}".format(i+1,j+1,i+1,j+2))
                cn += 1
            A[i][j] -= 1
print(cn)
for i in ope:
    print(i)

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

def migrate1(i,t,w):
    s1 = t[0]
    for j in range(w-1):
        if s1[i][j] % 2 == 0:
            continue
        else:
            t[1].append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            t[2] += 1
            s1[i][j] -= 1
            s1[i][j+1] += 1
    if s1[i][w-1] % 2 == 1:
        t[1].append(str(i+1)+" "+str(w)+" "+str(i+2)+ " "+str(w))
        t[2] += 1
        s1[i][w-1] -= 1
        s1[i+1][w-1] += 1
    return t

def migrate2(h,t):
    s1 = t[0]
    for j in range(w-1):
        if s1[h-1][j] % 2 == 0:
            continue
        else:
            t[1].append(str(h)+" "+str(j+1)+" "+str(h)+" "+str(j+2))
            t[2] += 1
            s1[h-1][j] -= 1
            s1[h-1][j+1] += 1
    return t


for i in range(h-1):
    t = migrate1(i,t,w)

t = migrate2(h,t)

print(t[2])
for i in range(len(t[1])):
    print(t[1][i])

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

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

hw = []

for i in range(h):
  line = list(map(int,input().split()))
  line.append(0) 
  hw.append(line)
  
n = 0
xy = []
  
for i in range(h-1):
  for j in range(w):
    if hw[i][j] % 2 == 1:
      if hw[i][j+1] % 2 == 1:
        hw[i][j] -= 1
        hw[i][j+1] += 1
        n += 1
        xy.append([i+1,j+1,i+1,j+2])
      else:
        hw[i][j] -= 1
        hw[i+1][j] += 1
        n += 1
        xy.append([i+1,j+1,i+2,j+1])

for i in range(w-1):
  if hw[h-1][i] % 2 == 1:
    hw[h-1][i] -= 1
    hw[h-1][i+1] += 1
    n += 1
    xy.append([h,i+1,h,i+2])
    
print(n)
for i in xy:
  print(' '.join(map(str,i)))

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

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

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

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

N = 0
x = 0
y = 0
flag = False
res = []
tmp_x = 0
tmp_y = 0

for i in range(H*W):
    if flag:
        res.append([tmp_x + 1, tmp_y + 1, x + 1, y + 1])
        A[y][x] += 1
        N += 1
        
    if A[y][x]%2 == 1:
        flag = True
    else:
        flag = False
        
    tmp_x = x
    tmp_y = y
    if x == W - 1 and y%2 == 0:
        y += 1
        
    elif x == 0 and y%2 == 1:
        y += 1
        
    elif y%2 == 0:
        x += 1
    else:
        x -= 1

            
print(N)

for r in res:
    print(r[1], r[0], r[3], r[2])

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h,w = f()
    g = [ f() for i in range(h)]

    cnt = 0
    ans = []
    for i in range(h):
        for j in range(w):
            if g[i][j]%2 == 0:
                continue
            else:
                if j+1<w  and (g[i][j+1]%2 == 1 or i+1 == h):
                    g[i][j+1] += 1
                    cnt+=1
                    ans += [(i+1, j+1, i+1, j+1+1)]

                elif i+1<h:
                    g[i+1][j] += 1
                    cnt+=1
                    ans += [(i+1, j+1, i+2, j+1)]

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



solve()

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

Solution (Python):

import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd



def solve(H: int, W: int, a: "List[List[int]]"):
    def xy(i):
        y = i // W
        x = (i % W)
        if (y % 2 == 1):
            x = (W - 1) - x
        return y ,x

    result = []
    for i in range(H * W-1):
        y, x = xy(i)
        if (a[y][x] % 2) == 1:
            y2, x2 = xy(i+1)
            a[y][x] -= 1
            a[y2][x2] += 1
            result.append("{} {} {} {}".format((y+1), (x+1), (y2+1), (x2+1)))

    return str(len(result)) + '\n' + '\n'.join(result)


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) ]  
    result = solve(H, W, a)
    print(result)

if __name__ == '__main__':
    main()

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

ans=0
ans_out=[]
for j in range(H):
    for i in range(W):
        if(a[j][i]%2!=0):
            if(i!=W-1):
                ans+=1
                a[j][i+1]+=1
                ans_out.append(str(j+1)+" "+str(i+1)+" "+str(j+1)+" "+str(i+2))
            else:
                if(j!=H-1):
                    a[j+1][i]+=1
                    ans+=1
                    ans_out.append(str(j+1)+" "+str(i+1)+" "+str(j+2)+" "+str(i+1))
print(ans)
for j in ans_out:
    print(j)

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





answer = []

def to_move(y,x,y_,x_):
  
  if A[y-1][x-1]%2:
    answer.append((y,x,y_,x_))
    A[y-1][x-1] -=1
    A[y_-1][x_-1] += 1

for h in range(1,H+1):
  for w in range(1,W):
    to_move(h,w,h,w+1)

for h in range(1,H):
  to_move(h,W,h+1,W)
  
print(len(answer))
for a in answer:
  print(' '.join([str(x) for x in a]))

Solution (Python):
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

h,w = m()

a = []
ans = []
for i in range(h):
	a.append(l())

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 ans in ans:
	print(*ans)

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


H,W = map(int,input().split())
c = [list(map(int,input().split())) for i in range(H)]
bool = 0
op = 0
res = deque()
for i in range(H):
    if bool == 0:
        for j in range(W):
            if c[i][j] % 2:
                if i==H-1 and j==W-1:
                    continue
                elif j < W-1:
                    res.append((i+1,j+1,i+1,j+2))
                    c[i][j+1] += 1
                    op += 1
                else:
                    res.append((i+1,j+1,i+2,j+1))
                    c[i+1][j] +=1
                    op += 1
        bool = 1
    else:
        for j in range(W)[::-1]:
            if c[i][j]%2:
                if i==H-1 and j == 0:
                    continue
                elif j > 0:
                    res.append((i+1,j+1,i+1,j))
                    c[i][j-1] += 1
                    op += 1
                else:
                    res.append((i+1,j+1,i+2,j+1))
                    c[i+1][j] += 1
                    op += 1
        bool = 0
print(op)
while res:
    a,b,c,d = res.popleft()
    print(a,b,c,d)

Solution (Python):

"""
D - Make Them Even
https://atcoder.jp/contests/abc109/tasks/abc109_d

"""
import sys


def solve(H, W, grid):
    ans = []
    for y, row in enumerate(grid):
        row_sum = sum(row)
        can_drop = row_sum % 2
        for x, c in enumerate(row):
            if c % 2:
                if can_drop and y != H-1:
                    ans.append([y+1, x+1, y+2, x+1])
                    grid[y][x] -= 1
                    grid[y+1][x] += 1
                    can_drop = False
                elif x != W-1:
                    grid[y][x] -= 1
                    ans.append([y+1, x+1, y+1, x+2])
                    grid[y][x+1] += 1
    return len(ans), ans


def main(args):
    H, W = map(int, input().split())
    grid = [[int(a) for a in input().split()] for _ in range(H)]
    N, ans = solve(H, W, grid)
    print(N)
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
h,w=map(int,input().split())
grid=[["
ans=[]
for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j]%2>0:
            if type(grid[i][j+1])==int:
                grid[i][j]-=1
                grid[i][j+1]+=1
                ans.append([i,j,i,j+1])
            elif type(grid[i+1][j])==int:
                grid[i][j]-=1
                grid[i+1][j]+=1
                ans.append([i,j,i+1,j])
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Solution (Python):
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
ans=[]
for i in range(H):
  for j in range(W):
    if i%2 == 0:
      if j != W-1:
        if A[i][j]%2 == 1:
          A[i][j+1]+=1
          ans.append([i+1,j+1,i+1,j+2])
      else:
        if A[i][j]%2 == 1 and i < H-1:
          A[i+1][j]+=1
          ans.append([i+1,j+1,i+2,j+1])
    else:
      if j != W-1:
        if A[i][W-1-j]%2 == 1:
          A[i][W-2-j]+=1
          ans.append([i+1,W-j,i+1,W-j-1])
      else:
        if A[i][W-1-j]%2 == 1 and i < H-1:
          A[i+1][W-1-j]+=1
          ans.append([i+1,W-j,i+2,W-j])
print(len(ans))
for i in range(len(ans)):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])

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

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

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

Solution (Python):

H, W = map(int,input().split())
As = []
for i in range(H):
    As.append(list(map(int,input().split())))
routes = []
for i in range(H):
    for j in range(W):
        if i%2 == 0:
            routes.append((i+1,j+1))
        else:
            routes.append((i+1,W-j))
n = len(routes)
mvs = []
cnt = 0
for i in range(n-1):
    hi,wi = routes[i]
    hi2,wi2 = routes[i+1]
    if As[hi-1][wi-1] % 2 == 1:
        As[hi2-1][wi2-1] += 1
        mvs.append([hi,wi,hi2,wi2])
        cnt += 1

print(cnt)
for h1,w1,h2,w2 in mvs:
    print(h1,w1,h2,w2)

Solution (Python):
H, W = map(int,input().split())
A = [list(map(int,input().split())) for k in range(H)]
N = 0
B = []
for h in range(H):
    for w in range(W-1):
        if A[h][w]%2==1:
            N += 1
            B.append([h+1,w+1,h+1,w+2])
            A[h][w] -= 1
            A[h][w+1] += 1

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

print(N)
for b in B:
    print(" ".join(map(str,b)))

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h, w = li()
grid = [list(li()) for _ in range(h)]

cnt = 0
ans = []

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

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

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

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:
            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 ans in ans:
    print(*ans)

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

Solution (Python):
h,w=map(int,input().split())
A=[]
for i in range(h):
  A.append([int(i) for i in input().split()])
Ans=[]
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 ans in Ans:
  print(*ans)

Solution (Python):
def gcd(x,y):
    x,y=max(abs(x),abs(y)),min(abs(x),abs(y))
    if x%y==0:
        return y
    while x%y==0:
        x,y=y,x%y
    return y

h,w=map(int,input().split())
a=[]
for i in range(h):
    b=[int(j) for j in input().split()]
    if i%2==0:
        b=b
    else:
        b=b[::-1]
    a+=b
ans=[]
def rs1(x):
    j,k=1+x//w,1+x-w*(x//w)
    if j%2==0:
        k=w-k+1
    return j,k
for i in range(h*w-1):
    if a[i]%2==1:
        ans.append((rs1(i)+rs1(i+1)))
        a[i+1]+=1
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):
import numpy as np

if __name__ == '__main__':
    res = []
    H, W = map(int, input().split())
    f = [list(map(int, input().split())) for i in range(H)]
    for x in range(W-1, 0, -1):
        for y in range(H-1, -1, -1):
            if f[y][x] % 2 == 1:
                res.append((y+1, x+1, y+1, x))
                f[y][x-1] += 1
                f[y][x] -= 1
    for y in range(H-1, 0, -1):
        if f[y][0] % 2 == 1:
            res.append((y+1, 1, y, 1))
            f[y][0] -= 1
            f[y-1][0] += 1

    print(len(res))
    for y1, x1, y2, x2 in res:
        print(y1, x1, y2, x2)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





def main():
    h, w = intin()
    alistlist = []
    for i in range(h):
        alistlist.append(intina())

    anslist = []

    for i in range(h):
        for j in range(w):

            if i >= h - 1 and j >= w - 1:
                continue

            if alistlist[i][j] & 1:
                alistlist[i][j] -= 1
                dst_x = i+(j+1)//w
                dst_y = min(j+1, w-1)
                alistlist[dst_x][dst_y] += 1
                anslist.append((i+1, j+1, dst_x+1, dst_y+1))

    print(len(anslist))
    for ans in anslist:
        print('%d %d %d %d' % ans)


if __name__ == '__main__':
    main()

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

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

print(len(moves))
for m in moves:
    print(' '.join(map(str, m)))

Solution (Python):
h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
moves = [0]
for y in range(h):
  for x in range(w-1):
    if a[y][x]%2:
      moves[0] += 1
      moves.append("{} {} {} {}".format(y+1,x+1,y+1,x+2))
      a[y][x] -= 1
      a[y][x+1] += 1
x = w-1
for y in range(h-1):
  if a[y][x]%2:
    moves[0] += 1
    moves.append("{} {} {} {}".format(y+1,x+1,y+2,x+1))
    a[y][x] -= 1
    a[y+1][x] += 1
for x in moves:
  print(x)

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

H,W = inpl()
MAP = [inpl() for i in range(H)]

flag = False 
ans = []
for y in range(H):
	if y%2 == 0:
		xx = range(W)
	else:
		xx = reversed(range(W))
	for x in xx:
		if flag:
			ans.append([by,bx,y,x])
		if MAP[y][x]%2 == 1:
			flag = not flag
		bx,by = x,y

print(len(ans))
for a,zu,nya,n in ans:
	print(a+1,zu+1,nya+1,n+1)

Solution (Python):
H,W=[int(a) for a in input().split(" ")]
tab=[[int(a) for a in input().split(" ")] for i in range(H)]
ans = []
moving=False
i,j=0,0
dx=1
while i<H and j<W:
    moving = not moving if tab[i][j]%2 == 1 else moving
    ni,nj=i,j
    if (dx>0 and j==W-1) or (dx<0 and j==0):
        ni=i+1
        dx*=-1
    else:
        nj=j+dx
    if moving and ni<H and nj<W:
        ans.append([i+1,j+1,ni+1,nj+1])
    i,j=ni,nj
print(len(ans))
for row in ans:
    print(" ".join([str(x) for x in row]))

Solution (Python):
h,w=map(int,input().split())
a_list=[]
for i in range(h):
    sub_list=list(map(int,input().split()))
    a_list.append(sub_list)
i=0
j=0
count=0
answer=[]
while not count==h*w-1:
    count=count+1
    if i%2==0:
        if j==w-1:
            i_n=i+1
            j_n=j
        else:
            i_n=i
            j_n=j+1
    else:
        if j==0:
            i_n=i+1
            j_n=j
        else:
            i_n=i
            j_n=j-1
    if a_list[i][j]%2==0:
        pass
    else:
        a_list[i_n][j_n]=a_list[i_n][j_n]+1
        answer.append('%s %s %s %s' %(i+1,j+1,i_n+1,j_n+1))
    i=i_n
    j=j_n
print(len(answer))
for i in answer:
    print(i)

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

odd_cells = []
for y in range(H):
    for x in range(W):
        x = x if y % 2 == 0 else W-x-1
        if A[y][x] % 2 == 1:
            odd_cells.append([x+1, y+1])

ans_operation = []
for i in range(0, len(odd_cells)-1, 2):
    source = odd_cells[i]
    dist = odd_cells[i+1]
    while not (source[0] == dist[0] and source[1] == dist[1]):
        if (source[0] == W and source[1] % 2 == 1) or\
                (source[0] == 1 and source[1] % 2 == 0):
            ans_operation.append(source+[source[0], source[1]+1])
            source[1] += 1
        else:
            direction = 1 if source[1] % 2 == 1 else -1
            ans_operation.append(source+[source[0]+direction, source[1]])
            source[0] += direction

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

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

mr=[]
md=[]
for h in range(H):
    for w in range(W):
        if a[h][w]%2!=0 and w<W-1:
            mr.append((h,w))
            a[h][w+1]+=1
    if a[h][w]%2!=0 and h<H-1:
        md.append((h,w))
        a[h+1][w]+=1
print(len(mr)+len(md))
for i in range(len(mr)):
    print(mr[i][0]+1,mr[i][1]+1,mr[i][0]+1,mr[i][1]+2)
for i in range(len(md)):
    print(md[i][0]+1,md[i][1]+1,md[i][0]+2,md[i][1]+1)

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

for i in range(h):
  for j in range(w):
    if i != h - 1 or j != w - 1:
      if a[i][j] % 2 != 0:
        a[i][j] -= 1
        if j == w - 1:
          a[i + 1][j] += 1
          yxyx += [i + 1, j + 1, i + 2, w]
        else:
          a[i][j + 1] += 1
          yxyx += [i + 1, j + 1, i + 1, j + 2]
        n += 1

print(n)
for i in range(n):
  print(yxyx[4 * i], yxyx[4 * i + 1], yxyx[4 * i + 2], yxyx[4 * i + 3])

Solution (Python):

H, W = map(int, input().split())
A_raw = [[int(i) for i in input().split()] for j in range(H)]

c = 1
A = []
d = {}
for h in range(H):
    if h % 2 == 0:
        for a in A_raw[h]:
            A.append(a)
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)]))
    else:
        for a in A_raw[h][::-1]:
            A.append(a)
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)[::-1]]))
    c += W

c = 0
ans = []
for i in range(len(A)-1):
    if A[i] % 2 == 1:
        A[i+1] += 1
        A[i] -= 1
        c += 1
        ans.append([d[i+1], d[i+2]])
print(c)
for x in ans:
    print(x[0][0], x[0][1], x[1][0], x[1][1])

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

show=False
prev=(-1,-1)
ans=[]

for h in range(H):
	for w in range(W) if h % 2 else range(W-1, -1, -1):
		if show:
			ph,pw=prev
			ans.append((ph+1, pw+1, h+1, w+1))
		if a[h][w] % 2 == 1:
			show = not show
		prev=(h,w)

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

Solution (Python):
def f(h, w):
    t = [list(map(int, input().split())) for _ in range(h)]
    i = j = 0
    dj = 1
    ans = []
    ido = 0
    while i < h:
        if t[i][j] % 2:
            if ido:
                stog[2:4] = [i + 1, j + 1]
                log += [stog]
                ans += log
                ido = 0
            else:
                ido = 1
                stog = [i + 1, j + 1, 0, 0]
                log = []
        else:
            if ido:
                stog[2:4] = [i + 1, j + 1]
                log += [stog]
                stog = [i + 1, j + 1, 0, 0]
        j += dj
        if j == w or j == -1:
            i += 1
            dj *= -1
            j += dj
    print(len(ans))
    for x in ans:
        print(*x)


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

Solution (Python):
h, w = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(h)]
kisu = []
kisu_count = 0
i = j = 0
dj = 1
ans = []
ido = 0
while i < h:
    if t[i][j] % 2:
        if ido:
            stog[2:4] = [i + 1, j + 1]
            log += [stog]
            ans += log
            ido = 0
        else:
            ido = 1
            stog = [i + 1, j + 1, 0, 0]
            log = []
    else:
        if ido:
            stog[2:4] = [i + 1, j + 1]
            log += [stog]
            stog = [i + 1, j + 1, 0, 0]
    j += dj
    if j == w or j == -1:
        i += 1
        dj *= -1
        j += dj
print(len(ans))
for x in ans:
    print(*x)

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

N = 0
s = [] 
for i in range(H):
  s.append(list(map(int, input().split())))
  
ans = []
for i in range(H):
  for j in range(W):
    if s[i][j] % 2 == 1:
      if j != W-1: 
        s[i][j] -= 1
        s[i][j+1] += 1
        ans.append(str(i+1) + " " + str(j+1) + " " + str(i+1) + " " + str(j+2)) 
        N += 1
      else:
        
        if i != H-1:
          s[i][j] -= 1
          s[i+1][j] += 1
          ans.append(str(i+1) + " " + str(j+1) + " " + str(i+2) + " " + str(j+1)) 
          N += 1

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

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


coin = [None]
for h in range(H):
  coin.append([None]+[int(x) for x in input().split()])



moves = []


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


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


N = len(moves)
print(N)
for a,b,c,d in moves:
  print(a,b,c,d)

Solution (Python):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


h, w = map(int, input().split(' '))
a = [list(map(int, input().split(' '))) for i in range(h)]
l = []
for r in range(h):
    for c in range(w):
        if a[r][c]%2:
            if c+1<w:
                l.append([r, c, r, c+1])
                a[r][c+1]+=1
            elif r+1<h:
                l.append([r, c, r+1, c])
                a[r+1][c]+=1
print(len(l))
for i in l:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)