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())
grid = [list(map(int, input().split())) for _ in range(H)]
ans = []
flg = False
for i in range(H):
    for k in range(W):
        if i % 2 != 0:
            k = W - 1 - k
        if i % 2 == 0:
            if k == W - 1:
                if i == H - 1:
                    continue
                next_i = i + 2
                next_k = k + 1
            else:
                next_i = i + 1
                next_k = k + 2
        else:
            if k == 0:
                if i == H - 1:
                    continue
                next_i = i + 2
                next_k = k + 1
            else:
                next_i = i + 1
                next_k = k
        if grid[i][k] % 2 == 1:
            if flg:
                flg = False
                continue
            flg = True
            ans.append((i+1,k+1,next_i,next_k))
        elif flg:
            ans.append((i+1,k+1,next_i,next_k))
print(len(ans))
for i in ans:
    print(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)]
ans = []
for i in range(H):
  for j in range(W):
    if i == H-1 and j == W-1:
      continue
    if i == H-1:
      if A[i][j] % 2 == 1:
        A[i][j] -= 1; A[i][j+1] += 1;
        ans.append((i,j,i,j+1))
    elif A[i][j] % 2 == 1:
      A[i][j] -= 1; A[i+1][j] += 1;
      ans.append((i,j,i+1,j))
print(len(ans))
for i1, j1, i2, j2 in ans:
  print(i1+1, j1+1, i2+1, j2+1)

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
cnt = 0
ans = []
for i in range(H):
  for j in range(W):
    if i == H-1 and j == W-1:
      continue
    if i == H-1:
      if A[i][j] % 2 == 1:
        A[i][j] -= 1; A[i][j+1] += 1;
        s = " ".join([str(i+1), str(j+1), str(i+1), str(j+2)])
        ans.append(s)
        cnt += 1
    elif A[i][j] % 2 == 1:
      A[i][j] -= 1; A[i+1][j] += 1;
      s = " ".join([str(i+1), str(j+1), str(i+2), str(j+1)])
      ans.append(s)
      cnt += 1
print(cnt)
print(*ans, sep="\n")

Solution (Python):
import sys

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


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


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

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

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys


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


sys.setrecursionlimit(20000000)


def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    answer = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 0:
                continue
            else:
                if h + 1 <= H - 1 and w + 1 <= W - 1:
                    if A[h + 1][w] % 2 == 1:
                        A[h + 1][w] += 1
                        answer.append([h + 1, w + 1, h + 2, w + 1])
                    else:
                        A[h][w + 1] += 1
                        answer.append([h + 1, w + 1, h + 1, w + 2])
                elif h + 1 <= H - 1:
                    A[h + 1][w] += 1
                    answer.append([h + 1, w + 1, h + 2, w + 1])
                elif w + 1 <= W - 1:
                    A[h][w + 1] += 1
                    answer.append([h + 1, w + 1, h + 1, w + 2])
                else:
                    continue
    N = len(answer)
    print(N)
    for i in range(N):
        print(*answer[i], sep=" ")


if __name__ == "__main__":
    main()

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

import numpy as np


def update_h_w(h, w, H, W):
    
    if h % 2 == 0:
        if w == W - 1:
            h += 1
        else:
            w += 1
    
    else:
        if w == 0:
            h += 1
        else:
            w -= 1
    return h, w


def main():
    H, W = map(int, input().split())
    a = np.zeros((H, W), dtype=int)
    for i in range(H):
        a[i] = list(map(int, input().split()))

    N = 0
    ans = []
    tmp = []
    h, w = 0, 0
    search_pair = False
    while h < H:
        if search_pair:
            tmp.append((h + 1, w + 1))
            if a[h, w] % 2 == 1:
                search_pair = False
                ans.append(tmp)
                N += len(tmp) - 1
                tmp = []
        else:
            if a[h, w] % 2 == 1:
                search_pair = True
                tmp.append((h + 1, w + 1))
        h, w = update_h_w(h, w, H, W)

    print(N)
    for p in ans:
        for i in range(len(p) - 1):
            print(" ".join(map(str, (p[i][0], p[i][1], p[i+1][0], p[i+1][1]))))


if __name__ == "__main__":
    main()

Solution (Python):
H,W=list(map(int,input().split()))
A=[list(map(lambda x: int(x)%2,input().split())) for _ in range(H)]
visit=[[0]*W for _ in range(H)]

pt=[0,0]
disp=False
ans=[]
while True:
    y,x=pt
    visit[y][x]=1
    if A[y][x]==1:
        disp=not disp
    flag=True
    for dy,dx in [[1,0],[0,1],[-1,0],[0,-1]]:
        ny=y+dy
        nx=x+dx
        if 0<=ny<H and 0<=nx<W and visit[ny][nx]==0:
            npt=[ny,nx]
            flag=False
    if flag:
        break

    if disp:
        ans.append('{} {} {} {}'.format(y+1,x+1,npt[0]+1,npt[1]+1))
    
    pt=npt

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

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

ans = []
flag = False
before = []
for i in range(H):
    if i%2==0:
        for j in range(W):
            if (not flag) and a[i][j]%2==1:
                flag = True
                before = [i,j]
            elif flag and a[i][j]%2==1:
                flag = False
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
            elif (not flag) and a[i][j]%2==0:
                pass
            else:
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
                before = [i,j]
    else:
        for j in reversed(range(W)):
            if (not flag) and a[i][j]%2==1:
                flag = True
                before = [i,j]
            elif flag and a[i][j]%2==1:
                flag = False
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
            elif (not flag) and a[i][j]%2==0:
                pass
            else:
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
                before = [i,j]
N = len(ans)
print(N)
for i in range(N):
    print(*ans[i])

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

ans = []
flag = False
before = []
for i in range(H):
    if i%2==0:
        for j in range(W):
            if (not flag) and a[i][j]%2==1:
                flag = True
                before = [i,j]
            elif flag and a[i][j]%2==1:
                flag = False
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
            elif (not flag) and a[i][j]%2==0:
                pass
            else:
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
                before = [i,j]
    else:
        for j in reversed(range(W)):
            if (not flag) and a[i][j]%2==1:
                flag = True
                before = [i,j]
            elif flag and a[i][j]%2==1:
                flag = False
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
            elif (not flag) and a[i][j]%2==0:
                pass
            else:
                ans.append([before[0]+1,before[1]+1,i+1,j+1])
                before = [i,j]
N = len(ans)
print(N)
for i in range(N):
    print(*ans[i])

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

before_A = None
history = []
for h, row in enumerate(As):
    it = enumerate(row)
    if h % 2 == 0:
        it = reversed(list(it))
    for w, A in it:
        if A % 2 == 0:
            if before_A is not None:
                path.append((h, w))

        else:
            if before_A is None:
                before_A = (h, w)
                path = [(h, w)]
            else:
                path.append((h, w))
                history.append(path[:])
                before_A = None

ans = []
for path in history:
    for i in range(len(path) - 1):
        ans.append( (path[i], path[i+1]) )

print(len(ans))
for (a, b), (c, d) in ans:
    print(a+1, b+1, c+1, d+1, sep = ' ')

Solution (Python):
h,w = map(int,input().split())
grid = []
ans = []
for i in range(h):
    grid.append(list(map(int,input().split())))
cur = [0,0]
while True:
    y,x = cur[0],cur[1]
    if y % 2 == 0:
        if x != w-1:
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y][x+1] += 1
                ans.append((y+1,x+1,y+1,x+2))
            cur[1] += 1
        else:
            if y >= h-1:
                break
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y+1][x] += 1
                ans.append((y+1,x+1,y+2,x+1))
            cur[0] += 1
    else:
        if x != 0:
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y][x-1] += 1
                ans.append((y+1,x+1,y+1,x))
            cur[1] -= 1
        else:
            if y >= h-1:
                break
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y+1][x] += 1
                ans.append((y+1,x+1,y+2,x+1))
            cur[0] += 1
print(len(ans))
for i in ans:
    print(i[0],i[1],i[2],i[3])

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    H,W=map(int,readline().split())
    a=[]
    for i in range(H):
        a_i=list(map(int,readline().split()))
        a.append(a_i)

    count=0
    operation=[]
    for y in range(H):
        for x in range(W):
            if a[y][x]%2==1 and x==W-1 and y==H-1:
                pass
            elif a[y][x]%2==1 and x==W-1:
                a[y][x]-=1
                a[y+1][x]+=1
                count+=1
                operation.append([y+1,x+1,y+2,x+1])
            elif a[y][x]%2==1:
                a[y][x]-=1
                a[y][x+1]+=1
                count+=1
                operation.append([y+1,x+1,y+1,x+2])

    print(count)
    for i in range(count):
        print(*operation[i])

if __name__=="__main__":
    main()

Solution (Python):
h,w = map(int,input().split())
a = [[] for _ in range(h)]
for i in range(h):
    a[i] = list(map(int,input().split()))
    for j in range(w):
        a[i][j] %= 2
        
z = []
for i in range(h):
    for j in range(w):
        if i%2 == 0:
            k = j
        else:
            k = (w-1)-j
        z.append((i,k))
        
coin = 0
ans = []
for i in range(h*w-1):
    y,x = z[i]
    yy,xx = z[i+1]
    
    if a[y][x] == 1:
        if coin == 0:
            coin = 1
        else:
            coin = 0
            
    if coin == 1:
        ans.append((y+1,x+1,yy+1,xx+1))
        
print(len(ans))
for i in ans:
    print(*i)

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

flag = False
h, w = 1, 1
ans = []


def it_grid(h, w):
    if h % 2:
        if w == W:
            h += 1
        else:
            w += 1
    else:
        if w == 1:
            h += 1
        else:
            w -= 1
    return h, w


while h <= H:
    new_h, new_w = it_grid(h, w)
    if A[h - 1][w - 1] % 2:
        if not flag and new_h <= H:
            ans.append((h, w, new_h, new_w))
        flag = not flag
    else:
        if flag and new_h <= H:
            ans.append((h, w, new_h, new_w))
    h, w = new_h, new_w

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

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):
    if i % 2 == 0:
        start = 0
        end = W
        direction = 1
    else:
        start = W-1
        end = -1
        direction = -1
    for j in range(start, end, direction):    
        if A[i][j] % 2 == 0:
            continue
        else:
            if i % 2 == 0 and j < W-1:
                ans.append((i, j, i, j+1))
                A[i][j] -= 1
                A[i][j+1] += 1
            elif i % 2 == 0 and j == W-1 and i < H-1:
                ans.append((i, j, i+1, j))
                A[i][j] -= 1
                A[i+1][j] += 1
            elif i % 2 == 1 and j > 0:
                ans.append((i, j, i, j-1))
                A[i][j] -= 1
                A[i][j-1] += 1
            elif i % 2 == 1 and j == 0 and i < H-1:
                ans.append((i, j, i+1, j))
                A[i][j] -= 1
                A[i+1][j] += 1


print(len(ans))
for y,x,y2,x2 in ans:
    print(y+1,x+1,y2+1,x2+1)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, a: "List[List[int]]"):
    ans = []  
    p = 0
    for i in range(H):
        if i % 2 == 0:
            js = range(W)
        else:
            js = reversed(range(W))
        for j in js:
            if a[i][j] % 2 == 1:
                p ^= 1
            nexti = i
            nextj = j + (1 if i % 2 == 0 else -1)
            if nextj == -1:
                nexti += 1
                nextj = 0
            elif nextj == W:
                nexti += 1
                nextj = W - 1
            if p:
                ans.append([i, j, nexti, nextj])
    if p:
        del ans[-1]
    print(len(ans))
    for i, j, nexti, nextj in ans:
        print(i + 1, j + 1, nexti + 1, nextj + 1)


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())
m=[list(map(int,input().split())) for i in range(h)]
pre=0
ans=0
ret=[]
l=[[0,w,1],[w-1,-1,-1]]
for i in range(h):
    a,s,d=l[i%2]
    for j in range(a,s,d):
        if (pre+m[i][j])%2:
            pre=1
            x,y=(i,j+d) if 0<=j+d<=w-1 else (i+1,j) 
            if 0<=x<h and 0<=y<w:
              ans+=1
              ret.append([i+1,j+1,x+1,y+1])
        else:pre=0
print(ans)
for g in range(ans):
    print(*ret[g])

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

ans = []
flg = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 == 1:
                flg += 1
            val = [i+1,j+1,i+1,j+2]
            if val[2] <= h and val[3] <= w and flg % 2 == 1:
                ans.append(val)
            elif val[2] < h and val[3] > w and flg % 2 == 1:
                ans.append([i+1,j+1,i+2,j+1])
    else:
        j = w-1
        while j >= 0:
            if a[i][j] % 2 == 1:
                flg += 1
            val = [i+1,j+1,i+1,j]
            if val[2] <= h and val[3] > 0 and flg % 2 == 1:
                ans.append(val)
            elif val[2] < h and val[3] <= 0 and flg % 2 == 1:
                ans.append([i+1,j+1,i+2,j+1])

            j -= 1
print(len(ans))
for i in range(len(ans)):
    print(' '.join(map(str,ans[i])))

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

Solution (Python):
h,w=map(int,input().split())
a=[]
used=[[False for _ in range(w)] for _ in range(h)]
ans=[]
for i in range(h):
    ai=list(map(int,input().split()))
    for j in range(w):
        if(ai[j]%2!=0):
            if(j<w-1 and ai[j]>0 and ai[j]%2!=0 and not used[i][j]):
                used[i][j]=True
                ai[j]-=1
                ai[j+1]+=1
                ans.append([i+1,j+1,i+1,j+2])
    a.append(ai)

for i in range(h):
    if(i<h-1 and a[i][w-1]>0 and a[i][w-1]%2!=0 and not used[i][w-1]):
        used[i][w-1]=True
        a[i][w-1]-=1
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


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

    route = []
    for h in range(H):
        if h % 2 == 1:
            route.extend([(h, w) for w in range(W)])
        else:
            route.extend([(h, w) for w in reversed(range(W))])

    ans = []
    
    for (i1, j1), (i2, j2) in zip(route, route[1:]):
        if A[i1][j1] % 2 == 1:
            A[i1][j1] -= 1
            A[i2][j2] += 1
            ans.append((i1 + 1, j1 + 1, i2 + 1, j2 + 1))

    print(len(ans))
    print('\n'.join(' '.join(map(str, line)) for line in ans))


resolve()

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


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

    N = 0
    res = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == 0:
                continue
            d = ((-1, 0), (0, -1))
            flag = False
            for dh, dw in d:
                nh = h + dh
                nw = w + dw
                if nh < 0 or H <= nh or nw < 0 or W <= nw:
                    continue
                if A[nh][nw] % 2 != 0:
                    N += 1
                    res.append((h + 1, w + 1, nh + 1, nw + 1))
                    A[h][w] -= 1
                    A[nh][nw] += 1
                    flag = True
                    break
            if flag:
                continue
            d = ((0, 1), (1, 0))
            for dh, dw in d:
                nh = h + dh
                nw = w + dw
                if nh < 0 or H <= nh or nw < 0 or W <= nw:
                    continue
                if A[h][w] % 2 != 0:
                    N += 1
                    res.append((h + 1, w + 1, nh + 1, nw + 1))
                    A[h][w] -= 1
                    A[nh][nw] += 1
                    break

    print(N)
    for r in res:
        print(*r)


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
h,w = map(int,input().split())
a_list=[]
for i in range(h):
  a_list.append(list(map(int,input().split())))
ans_list = [] 
one_load = []
for a in range(h):
  if a % 2 == 0:
    for b in range(w):
      one_load.append([a,b])
  else:
    for b in range(w-1,-1,-1):
      one_load.append([a,b])
keiro = []     
for i in range(len(one_load) - 1):
  if a_list[one_load[i][0]][one_load[i][1]] % 2 == 1:
    a_list[one_load[i+1][0]][one_load[i+1][1]] += 1
    keiro.append([one_load[i][0]+1,one_load[i][1]+1,one_load[i+1][0]+1,one_load[i+1][1]+1])
print(len(keiro))
for k in keiro:
  print(*k)

Solution (Python):
'''
Daiki Suyam
一旦、奇数なら右に移し、その後、右列を下に移す
'''
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
            a[i][j]-=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if a[i][w-1]%2==1:
        
            a[i+1][w-1]+=1
            a[i][w-1]-=1
            ans.append([i+1,w,i+2,w])
l=len(ans)
print(l)
for i in range(l):
    print(" ".join(map(str,ans[i])))

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

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


ans = 0
ansgrid = []


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


      
      else:
        ansgrid.append([i,j,i+1,j])
        ans += 1
        grid[i][j] -= 1
        grid[i+1][j] += 1

        


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

Solution (Python):
i = lambda: map(int, input().split())
c = lambda x: -x*2+1
h, w = i()
l = []
for q in range(h):
    l += list(i())[::c(q%2)]
o = []
for j in range(w*h-1):
    if l[j] % 2:
        a, b = divmod(j, w)
        y, m, n = a+1, a%2, b==w-1
        x = [b+1, w-b][m]
        o += [[y, x, [y, y+1][n], [x+c(m), x][n]]]
        l[j+1] += 1
print(len(o))
for p in o:
    print(*p)

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

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

ans = []
y = 1
x = 1
xstock = 0
ystock = 0
seen = [[False for i in range(W+2)] for j in range(H+2)]
seen[1][1] = True

while True:
  if xstock > 0 and ystock > 0:
    ans.append([ystock,xstock,y,x])
    xstock = x 
    ystock = y
  if l[y][x]%2 == 1:
    if xstock == 0 and ystock == 0:
      xstock = x 
      ystock = y
    elif xstock > 0 and ystock > 0:
      xstock = 0
      ystock = 0
  
  
  if x+1 <= W and seen[y][x+1] == False:
    x = x+1
    y = y
    seen[y][x] = True
    continue
  
  elif x-1 >= 1 and seen[y][x-1] == False:
    x = x-1
    y = y
    seen[y][x] = True
    continue
  
  elif y+1 <= H:
    x = x
    y = y+1
    seen[y][x] = True
    continue
  
  break

N = len(ans)
print(N)
for i in range(N):
  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-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            a[i][j]-=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h):
    if a[i][w-1]%2==1:
        if i!=h-1:
            a[i+1][w-1]+=1
            a[i][w-1]-=1
            ans.append([i+1,w,i+2,w])
l=len(ans)
print(l)
for i in range(l):
    print(" ".join(map(str,ans[i])))

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
a = [list(map(int, readline().split())) for _ in range(h)]
cnt = 0
bf = []
af = []
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1:
            cnt += 1
            bf.append([i + 1, j + 1])
            if j == w - 1:
                if i == h - 1:
                    cnt -= 1
                    break
                a[i + 1][j] += 1
                af.append([i + 2, j + 1])
            else:
                a[i][j + 1] += 1
                af.append([i + 1, j + 2])
print(cnt)
for xy1, xy2 in zip(bf, af):
    print(*(xy1 + xy2))

Solution (Python):
import sys


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


def main():
    h, w = map(int, read().split())
    a = [[int(i) for i in read().split()] for _ in range(h)]
    b = []
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if a[i - 1][j - 1] % 2 == 0:
                continue
            if j < w:
                
                a[i - 1][j] += 1
                b.append((i, j, i, j + 1))
            elif i < h:
                
                a[i][j - 1] += 1
                b.append((i, j, i + 1, j))
    print(len(b))
    for bi in b:
        print(*bi)


if __name__ == '__main__':
    main()

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

out = []


def move(x1, y1, x2, y2):
    if 0 <= x2 < H and 0 <= y2 < W:
        coins[x1][y1] -= 1
        coins[x2][y2] += 1
        out.append((x1 + 1, y1 + 1, x2 + 1, y2 + 1))


for i in range(0, H, 2):
    for j in range(W):
        if coins[i][j] % 2:
            if j < W - 1:
                move(i, j, i, j + 1)
            else:
                move(i, j, i + 1, j)
    for j in range(W - 1, -1, -1):
        if i < H - 1 and coins[i + 1][j] % 2:
            if j > 0:
                move(i + 1, j, i + 1, j - 1)
            else:
                move(i + 1, j, i + 2, j)

print(len(out))
for c in out:
    print(*c)

Solution (Python):
import sys

H, W, *A = map(int, sys.stdin.read().split())

ans = []
n = 0
ans_append = ans.append
for i in range(H*W-1):
    if i % W == W-1:
        continue
    if A[i] % 2:
        A[i+1] += 1
        n += 1
        ans_append(map(str, (i//W+1, i%W+1, (i+1)//W+1, (i+1)%W+1)))
for i in range(W-1, W*H-1, W):
    if A[i] % 2:
        A[i+W] += 1
        n += 1
        ans_append(map(str, (i//W+1, i%W+1, i//W+2, i%W+1)))

print(n)
print('\n'.join(' '.join(row) for row in ans))

Solution (Python):
h,w=map(int,input().split())
A=[]
for i in range(h):
    A.append(list(map(int,input().split())))
    
S=[]
for i in range(h):
    for j in range(w-1):
        if A[i][j]%2!=0:
            A[i][j]-=1
            A[i][j+1]+=1
            S.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if A[i][-1]%2!=0:
        A[i][-1]-=1
        A[i+1][-1]+=1
        S.append([i+1,w,i+2,w])

print(len(S))
for s in S:
    print(*s)

Solution (Python):
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
d = [[0]*w for _ in range(h)]
def nxt(i,j):
  if i%2 == 0 and j == w-1:
    return i+1,j
  elif i%2 == 1 and j == 0:
    return i+1,j
  elif i%2 == 0:
    return i,j+1
  else:
    return i,j-1
i,j = 0,0
cnt = 0
ans = []
while True:
  k,l = nxt(i,j)
  if k == h:
    break
  if a[i][j] % 2 == 1:
    cnt += 1
    a[k][l] += 1
    ans.append([i+1,j+1,k+1,l+1])
  i,j = k,l
print(cnt)
for l in ans:
  print(*l)

Solution (Python):
h,w = map(int,input().split())
A = []
for i in range(h):
    A.append(list(map(int,input().split())))
visit = [[0]*w for i in range(h)]
d = [(1,0),(-1,0),(0,1),(0,-1)]
cnt=0
yx = []
for i in range(h):
    for j in range(w):
        visit[i][j]=1
        if A[i][j] %2==1:
            for dy,dx in d:
                if 0<=i+dy<h and 0<=j+dx<w:
                    if visit[i+dy][j+dx] ==0:
                        A[i][j] -=1
                        A[i+dy][j+dx] +=1
                        cnt+=1
                        yx.append((i+1,j+1,i+dy+1,j+dx+1))
                        break
print(cnt)
for i in range(cnt):
    print(*yx[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-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])