Problem:
 Score : 400 points    Problem Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i -th row and the j -th column will be denoted as Cell (i, j) .  In Cell (i, j) , a_{ij} coins are placed.  You can perform the following operation any number of times:  Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.  Maximize the number of cells containing an even number of coins.      Constraints  All values in input are integers.  1 \leq H, W \leq 500  0 \leq a_{ij} \leq 9         Input Input is given from Standard Input in the following format:  H  W  a_{11}  a_{12}  ...  a_{1W}  a_{21}  a_{22}  ...  a_{2W}  :  a_{H1}  a_{H2}  ...  a_{HW}       Output Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:  N  y_1  x_1  y_1'  x_1'  y_2  x_2  y_2'  x_2'  :  y_N  x_N  y_N'  x_N'   That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations.  In the (i+1) -th line ( 1 \leq i \leq N ), print four integers y_i, x_i, y_i' and x_i' ( 1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W ), representing the i -th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i') .  Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer .        Sample Input 1 2 3
1 2 3
0 1 1      Sample Output 1 3
2 2 2 3
1 1 1 2
1 3 1 2  Every cell contains an even number of coins after the following sequence of operations:   Move the coin in Cell (2, 2) to Cell (2, 3) .  Move the coin in Cell (1, 1) to Cell (1, 2) .  Move one of the coins in Cell (1, 3) to Cell (1, 2) .        Sample Input 2 3 2
1 0
2 1
1 0      Sample Output 2 3
1 1 1 2
1 2 2 2
3 1 3 2       Sample Input 3 1 5
9 9 9 9 9      Sample Output 3 2
1 1 1 2
1 3 1 4

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

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

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


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


ans = []

for hi in range(H):
    for wi in range(W):
        if a[hi][wi] % 2 == 1 and wi < W-1:
            
            ans.append([hi,wi,hi,wi+1])
            a[hi][wi] -= 1
            a[hi][wi+1] += 1

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

print(len(ans))
for i in range(len(ans)):
    x,y,dx,dy = ans[i]
    print(x+1,y+1,dx+1,dy+1)

Solution (Python):


H,W=map(int,raw_input().split())
a=[]
for i in range(H):
    aa=map(int,raw_input().split())
    a.append(aa)

history=[]
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
            history.append((i,j,i,j+1))
for i in range(H-1):
    if a[i][W-1]%2==1:
        a[i][W-1]-=1
        a[i+1][W-1]+=1
        history.append((i,W-1,i+1,W-1))
print(len(history))
for h in history:
    print("%d %d %d %d"%(h[0]+1, h[1]+1, h[2]+1, h[3]+1))

Solution (Python):
def calc(ind, width):
    from_x = (ind // width) + 1
    y_kari = ind % (width * 2)
    if y_kari >= width:
        from_y = width * 2 - y_kari
    else:
        from_y = y_kari + 1
    return from_x, from_y

def main():
    high, width = map(int, input().split())
    data = []
    for i in range(high):
        now_data = list(map(int, input().split()))
        if i % 2 == 1:
            now_data = reversed(now_data)
        data += now_data

    i = 0
    ans_list = []
    while i < high * width - 1:
        if data[i] % 2 == 0:
            i += 1
            continue

        next_ind = i + 1
        data[next_ind] += 1

        from_x, from_y = calc(i, width)
        next_x, next_y = calc(next_ind, width)

        ans_list.append([from_x, from_y, next_x, next_y])

        i += 1

    print(len(ans_list))
    for ele in ans_list:
        print(' '.join(map(str, ele)))


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

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

                else:
                    if a[i][j+1]%2==0:
                        ans_array.append([i,j,i+1,j])
                        
                        ans_cnt += 1
                        a[i+1][j]+=1
                    else: 
                        ans_array.append([i,j,i,j+1])
                        
                        ans_cnt += 1
                        a[i][j+1]+=1
            else:
                if j==W-1:
                    continue
                else:
                    ans_array.append([i,j,i,j+1])
                    
                    ans_cnt += 1
                    a[i][j+1]+=1
                    
                        


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

Solution (Python):

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

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

                else:
                    if a[i][j+1]%2==0:
                        ans_array.append([i,j,i+1,j])
                        
                        ans_cnt += 1
                        a[i+1][j]+=1
                    else: 
                        ans_array.append([i,j,i,j+1])
                        
                        ans_cnt += 1
                        a[i][j+1]+=1
            else:
                if j==W-1:
                    continue
                else:
                    ans_array.append([i,j,i,j+1])
                    
                    ans_cnt += 1
                    a[i][j+1]+=1
                    
                        


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

Solution (Python):
H,W=map(int,input().split())
A=[]
for i in range(H):
    A.append([int(j)%2 for j in input().split()])
reached=[[0]*W for i in range(H)]
L=[]
for i in range(H):
    for j in range(W-1):
        if A[i][j]==1:
            L.append([i+1,j+1,i+1,j+2])
            A[i][j]-=1
            A[i][j+1]=A[i][j+1]^1
for i in range(H-1):
    if A[i][W-1]==1:
        L.append([i+1,W,i+2,W])
        A[i][W-1]-=1
        A[i+1][W-1]=A[i+1][W-1]^1
print(len(L))
for i in range(len(L)):
    print(L[i][0],L[i][1],L[i][2],L[i][3])

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

for _ in range(H):
    BOARD.append(list(map(int, input().split())))

ans = []


move = False
prev_h = -1
prev_w = -1
for h in range(H):
    for w in (range(W) if h % 2 == 0 else reversed(range(W))):
        if move:
            ans.append((prev_h, prev_w, h, w))
            BOARD[prev_h][prev_w] -= 1
            BOARD[h][w] += 1
        cnt = BOARD[h][w]
        move = cnt % 2 == 1
        prev_h, prev_w = h, w



print(len(ans))
for row in ans:
    print(' '.join([str(r + 1) for r in row]))

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

res = []
for j in range(h)[::2]:
    for i in range(w):
        if e[j][i] % 2 == 1:
            if i < w-1:
                e[j][i+1] += 1
                res.append("{} {} {} {}".format(j+1, i+1, j+1, i+2))
            else:
                if j<h-1:
                    e[j+1][i] += 1
                    res.append("{} {} {} {}".format(j+1, i+1, j+2, i+1))

    if j+1 >= h:
        break

    for i in range(w)[::-1]:
        if e[j+1][i] % 2 == 1:
            if 0 < i:
                e[j+1][i-1] += 1
                res.append("{} {} {} {}".format(j+2, i+1, j+2, i))
            else:
                if j+1<h-1:
                    e[j+2][i] += 1
                    res.append("{} {} {} {}".format(j+2, i+1, j+3, i+1))

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

Solution (Python):

import sys


def solve(H: int, W: int, A: "List[List[int]]"):
    ret = []
    for r, R in enumerate(A):
        for c in range(len(R) - 1):
            val = R[c]
            if val % 2 == 1:
                ret.append([r, c, r, c + 1])
                R[c + 1] += 1
    for j in range(H - 1):
        val = A[j][W - 1]
        if val % 2 == 1:
            ret.append([j, W - 1, j + 1, W - 1])
            A[j + 1][W - 1] += 1
    print(len(ret))
    for r in ret:
        print(r[0] + 1, r[1] + 1, r[2] + 1, r[3] + 1)
    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):

import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	H, W = map(int, input().split(" "))
	A = []
	for _ in range(H):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		A.append(tmp)
	
	ans = []
	for i, val in enumerate(A):
		if i != len(A)-1:
			for j, vol in enumerate(val):
				if vol % 2 == 1:
					A[i][j] -= 1
					A[i+1][j] += 1
					tmp = "{} {} {} {}".format(i+1, j+1, i+2, j+1)
					ans.append(tmp)
		else:
			for j, vol in enumerate(val):
				if vol % 2 == 1:
					if j != len(A[i])-1:
						A[i][j] -= 1
						A[i][j+1] += 1
						tmp = "{} {} {} {}".format(i+1, j+1, i+1, j+2)
						ans.append(tmp)
		
	print(len(ans))
	for i in ans:
		print(i)
		
	
if __name__ == "__main__":
	main()

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

Solution (Python):
get_ints = lambda: [int(st) for st in input().split()]
H,W=get_ints()
inp=[get_ints() for i in range(H)]

res = []
for i in range(H):
    if not i % 2:
        for j in range(W):
            if inp[i][j] % 2:
                if j + 1 < W:
                    
                    res.append([i+1, j+1, i+1, j+2])
                    inp[i][j] -= 1
                    inp[i][j+1] += 1
                elif i + 1 < H:
                    res.append([i+1, j+1, i+2, j+1])
                    inp[i][j] -= 1
                    inp[i+1][j] += 1
                
    else:
        for j in reversed(range(W)):
            if inp[i][j] % 2:
                if j - 1 >= 0:
                    res.append([i+1, j+1, i+1, j])
                    inp[i][j] -= 1
                    inp[i][j-1] += 1
                elif i + 1 < H:
                    res.append([i+1, j+1, i+2, j+1])
                    inp[i][j] -= 1
                    inp[i+1][j] += 1
                

print(len(res))
for ar in res:
    print(*ar)

Solution (Python):
tmp=input().split(" ")
h = int(tmp[0])
w = int(tmp[1])

coin_map = [ [ int(s) for s in input().split(" ")] for _ in range(h) ]


n=0
history=[]

def move(x1,y1,x2,y2):
    global n
    n += 1
    history.append([y1+1, x1+1, y2+1, x2+1])
    coin_map[y1][x1] -= 1
    coin_map[y2][x2] += 1

for y in range(h):
    for x in range(w):
        if coin_map[y][x] % 2 == 1:
            if x < w-1:
                move(x,y, x+1,y)
            elif y < h-1:
                move(x,y, x,y+1)

print(n)

for i in range(n):
    print(" ".join(map(lambda n:str(n), history[i])))

Solution (Python):
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

H, W = map(int, input().split())
board = [0]*(H+1)
for i in range(1, H+1):
    board[i] = [0] + list(map(int, input().split()))


ans = []
for y in range(1, H+1):
    if y % 2 == 1:
        for x in range(1, W):
            now = board[y][x]
            if now % 2 != 0:
                ans.append((y, x, y, x+1))
                board[y][x+1] += 1
        if y != H:
            now = board[y][W]
            if now % 2 != 0:
                ans.append((y, W, y + 1, W))
                board[y+1][W] += 1
    else:
        for x in reversed(range(2, W+1)):
            now = board[y][x]
            if now % 2 != 0:
                ans.append((y, x, y, x-1))
                board[y][x-1] += 1
        if y != H:
            now = board[y][1]
            if now % 2 != 0:
                ans.append((y, 1, y+1, 1))
                board[y+1][1] += 1

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

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

Solution (Python):
inpl = lambda: list(map(int,input().split()))

H, W = inpl()
A = []
for _ in range(H):
    A.append(inpl())

def pos(n):
    q, m = divmod(n, W)
    if q % 2:
        m = (W-1) - m
    return q, m

ans = []
f = 0
hn, wn = 0, 0
for n in range(H*W-1):
    h, w = hn, wn
    hn, wn = pos(n+1)
    if (f+A[h][w]) % 2:
        ans.append([h+1,w+1,hn+1,wn+1])
        f = 1
    else:
        f = 0

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

Solution (Python):
H,W = map(int,input().split())
L = []
for i in range(H):
  L.append(list(map(int,input().split())))
i = 0
j = 0
cnt = 0
anslist = []
num = 0
while num < H*W-1:
  if L[i][j]%2 == 0:
    if i%2 == 0 and j == W-1:
      i += 1
    elif i%2 == 0:
      j += 1
    elif i%2 != 0 and j == 0:
      i += 1
    else:
      j -= 1
  else:
    befi,befj = i+1,j+1
    L[i][j] -= 1
    if i%2 == 0 and j == W-1:
      i += 1
    elif i%2 == 0:
      j += 1
    elif i%2 != 0 and j == 0:
      i += 1
    else:
      j -= 1
    L[i][j] += 1
    afti,aftj = i+1,j+1
    anslist.append([befi,befj,afti,aftj])
    cnt += 1
  num += 1
print(cnt)
for i in range(len(anslist)):
  print(anslist[i][0],anslist[i][1],anslist[i][2],anslist[i][3])

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

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

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

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

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

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-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))

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



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

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

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

onestroke = []

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

list = []
N = 0

for i in range(H*W-1):
    if a[onestroke[i][0]][onestroke[i][1]]%2!=0:
        list.append([onestroke[i][0]+1, onestroke[i][1]+1, onestroke[i+1][0]+1, onestroke[i+1][1]+1])
        N += 1
        a[onestroke[i+1][0]][onestroke[i+1][1]] += 1

print(N)
for i in range(N):
    print(list[i][0], list[i][1], list[i][2], list[i][3])

Solution (Python):
def main():
    H, W = [int(i) for i in input().split()]
    grid = [[0]*W for i in range(H)]
    for h in range(H):
        grid[h] = [int(i) % 2 for i in input().split()]
    ans = []
    
    
    for h, row in reversed(list(enumerate(grid))):
        for w, num in enumerate(row):
            if h == 0:
                continue
            if grid[h][w] == 0:
                continue
            move = h
            grid[h][w] = 0
            y = h
            x = w
            for i in range(move):
                ans.append((y+1, x+1, y-1+1, x+1))
                x, y = x, y-1
                if grid[y][x] == 1:
                    break
            grid[y][x] = (grid[y][x]+1)%2
    
    
    for w, num in reversed(list(enumerate(grid[0]))):
        if w == 0:
            continue
        if grid[0][w] == 0:
            continue
        move = w
        grid[0][w] = 0
        y = 0
        x = w
        for i in range(move):
            ans.append((y+1, x+1, y+1, x-1+1))
            y, x = y, x-1
            if grid[y][x] == 1:
                
                break
        
        grid[y][x] = (grid[y][x]+1)%2
    
    print(len(ans))
    for op in ans:
        print("%d %d %d %d" % op)



            
            

if __name__ == "__main__":
    main()

Solution (Python):
H,W=map(int,input().split())
 
M=[[c%2==1 for c in map(int,input().split())] for i in range(H)]
 
LIST=[]
 
for i in range(H):
    for j in range(W):
        if M[i][j]:
            if j < W-1:
                LIST.append((i+1,j+1,i+1,j+2))
                M[i][j+1] ^= True
            elif i < H-1:
                LIST.append((i+1,j+1,i+2,j+1))
                M[i+1][j] ^= True
                
print(len(LIST))
 
for c in LIST:
    print(*c)

Solution (Python):
def d_make_them_even(H, W, A):
    from itertools import product
    grid = [row for row in A]
    ans_tmp = []
    for h, w in product(range(H), range(W)):
        if grid[h][w] % 2 == 1:
            
            for dh, dw in zip((0, 1), (1, 0)):
                if 0 <= h + dh < H and 0 <= w + dw < W:
                    grid[h + dh][w + dw] += 1
                    grid[h][w] -= 1
                    ans_tmp.append('{} {} {} {}'.format(h + 1, w + 1, h + dh + 1, w + dw + 1))
                    break
    return str(len(ans_tmp)) + '\n' + '\n'.join(ans_tmp)

H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
print(d_make_them_even(H, W, A))

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

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

print(len(out))
for sub in out:
    print(" ".join(map(str,sub)))

Solution (Python):
h, w = [int(item) for item in input().split()]

lists = [[0] * w] * h

for i in range(h):
  lists[i] = [int(item) for item in input().split()]

count = 0
operations = ""
for i, l in enumerate(lists):
  for j, a in enumerate(l):
    if j == w-1:
      break
    if a%2 == 1:
      lists[i][j] -= 1
      lists[i][j+1] += 1
      count += 1
      operations += str(i+1,) + " " + str(j+1) + " " + str(i+1) + " " + str(j+2) + "\n"

for i in range(h):
  if i == h-1:
    break
  if lists[i][w-1] % 2 == 1:
    lists[i][j] -= 1
    lists[i+1][j] += 1
    count += 1
    
    operations += str(i+1,) + " " + str(j+1) + " " + str(i+2) + " " + str(j+1) + "\n"

print(count)
print(operations)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import product

def main():
    H, W = LI()
    A = []
    for _ in range(H):
        A.append(LI())
    ans = []
    for y, x in product(range(1, H + 1), range(1, W)):
        j, i = y - 1, x - 1
        if A[j][i] % 2:
            A[j][i + 1] += 1
            ans.append([y, x, y, x + 1])
    x = W
    i = x - 1
    for y in range(1, H):
        j = y - 1
        if A[j][i] % 2:
            A[j + 1][i] += 1
            ans.append([y, x, y + 1, x])
    print(len(ans))
    for arr in ans:
        print(*arr)

    return 0

main()

Solution (Python):

import sys


def solve(H: int, W: int, a: "List[List[int]]"):
    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+1+1])  
                a[i][j] -= 1
                a[i][j+1] += 1
    j = W-1
    for i in range(H-1):
        if a[i][j] % 2 == 1:
            ans.append([i+1, j+1, i+1+1, j+1])  
            a[i][j] -= 1
            a[i+1][j] += 1
    print(len(ans))
    for a in ans:
        print(" ".join(map(str, a)))

    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):
h,w=map(int,input().split())
s=[list(map(int,input().split()))for i in range(h)]
p=True
q=[0,0]
d=[]
for i in range(h):
    for j in range((w-1)*(i%2),(-1 if i%2==1 else w),(-1 if i%2==1 else 1)):
        if p:
            if s[i][j]%2==1:
                q=[i,j]
                p=False
        else:
            d.append([q[0]+1,q[1]+1,i+1,j+1])
            q=[i,j]
            if s[i][j]%2==1:
                p=True
print(len(d))
for i in d:
    print(i[0],i[1],i[2],i[3])

Solution (Python):
h,w=map(int,input().split())
s=[list(map(int,input().split()))for i in range(h)]
p=True
q=[0,0]
d=[]
for i in range(h):
    if i%2==0:
        for j in range(w):
            if p:
                if s[i][j]%2==1:
                    q=[i,j]
                    p=False
            else:
                d.append([q[0]+1,q[1]+1,i+1,j+1])
                q=[i,j]
                if s[i][j]%2==1:
                    p=True
    else:
        for j in range(w-1,-1,-1):
            if p:
                if s[i][j]%2==1:
                    q=[i,j]
                    p=False
            else:
                d.append([q[0]+1,q[1]+1,i+1,j+1])
                q=[i,j]
                if s[i][j]%2==1:
                    p=True
print(len(d))
for i in d:
    print(i[0],i[1],i[2],i[3])

Solution (Python):
H,W = (int(x) for x in input().split())

a_mat = []
for _ in range(H):
    a_mat.append([int(x) for x in input().split()])

out_op = []
for h in range(H):
    for w in range(W):
        if h%2 == 0:
            wd = w
            if w == W-1:
                next_pos = (h+1, wd)
            else:
                next_pos = (h, wd+1)
        else:
            wd = W-1-w
            if w == W-1:
                next_pos = (h+1, wd)
            else:
                next_pos = (h, wd-1)
        if h == H-1 and w == W-1:
            break
        if a_mat[h][wd] % 2 == 1:
            a_mat[next_pos[0]][next_pos[1]] += 1
            out_op.append((h, wd, next_pos[0], next_pos[1]))

print(len(out_op))
for y,x,yn,xn in out_op:
    print(y+1,x+1,yn+1,xn+1)

Solution (Python):
h, w = map(int, input().split())
amap = [list(map(int, input().split())) for _ in range(h)]
n = 0
mv = []
for i, alist in enumerate(amap):
  for j in range(len(alist)):
    if i == len(amap) - 1 and j == len(alist) - 1:
      break
    if i % 2 == 0:
      if amap[i][j] % 2 == 1:
        amap[i][j] -= 1
        if j == len(alist) - 1:
          amap[i+1][j] += 1
          mv.append((i+1, j+1, i+2, j+1))
        else:
          amap[i][j+1] += 1
          mv.append((i+1, j+1, i+1, j+2))
        n += 1
    elif i % 2 == 1:
      if amap[i][-j-1] % 2 == 1:
        amap[i][-j-1] -= 1
        if j == len(alist) - 1:
          amap[i+1][0] += 1
          mv.append((i+1, 1, i+2, 1))
        else:
          amap[i][-j-2] += 1
          mv.append((i+1, len(alist)-j, i+1, len(alist)-j-1))
        n += 1
print(n)
for _mv in mv:
  print(*_mv)

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

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

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

operations = []


def get_text(y1, x1, y2, x2):
    return str(y1 + 1) + " " + str(x1 + 1) + " " + str(y2 + 1) + " " + str(x2 + 1)

for y in range(H):
    if y % 2 == 0:
        for x in range(W):
            if Ai[y][x] % 2 == 0:
                continue
            if x == W - 1:
                if y < H - 1:
                    Ai[y][x] -= 1
                    Ai[y + 1][x] += 1
                    operations.append(get_text(y, x, y + 1, x))
            else:
                Ai[y][x] -= 1
                Ai[y][x + 1] += 1
                operations.append(get_text(y, x, y, x + 1))
    else:
        for x in range(W - 1, -1, -1):
            if Ai[y][x] % 2 == 0:
                continue
            if x == 0:
                if y < H - 1:
                    Ai[y][x] -= 1
                    Ai[y + 1][x] += 1
                    operations.append(get_text(y, x, y + 1, x))
            else:
                Ai[y][x] -= 1
                Ai[y][x - 1] += 1
                operations.append(get_text(y, x, y, x - 1))

print(len(operations))
for o in operations:
    print(o)

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

a_odd = [[False if ele%2==0 else True for ele in row] for row in a]

link = [[None]*w for _ in range(h)]
route = [[i,j] if i%2==0 else [i,w-1-j] for i in range(h) for j in range(w)]

linking = False
cnt = 0
tmp = 0
valid_n = -1
for n, [i,j] in enumerate(route):
    if a_odd[i][j] and not(linking):
        linking = True
    elif a_odd[i][j] and linking:
        linking = False
        link[i][j] = prev
        cnt += tmp+1
        tmp = 0
        valid_n = n
    elif not(a_odd[i][j]) and linking:
        link[i][j] = prev
        tmp += 1
    else:
        pass
    prev = [i,j]

print(cnt)
for n,[i,j] in enumerate(route):
    if link[i][j] and n<=valid_n:
        print(link[i][j][0]+1, link[i][j][1]+1, i+1, j+1)
    else:
        pass

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