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 scipy.spatial import distance


def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    op = []
    c = 0

    for y in range(h):
        if y % 2 == 0:
            for x in range(w):
                if (c == 1):
                    a[y][x] += 1
                    c = 0

                if a[y][x] % 2 == 1:
                    c = 1
                    x, y = x + 1, y + 1
                    if (x == w):
                        if y != h:
                            op.append([y, x, y + 1, x])
                        else:
                            break
                    else:
                        op.append([y, x, y, x + 1])
                    x, y = x - 1, y - 1

        else:
            for x in reversed(range(w)):
                if (c == 1):
                    a[y][x] += 1
                    c = 0

                if a[y][x] % 2 == 1:
                    c = 1
                    x, y = x + 1, y + 1
                    if (x == 1):
                        if y != h:
                            op.append([y, x, y + 1, x])
                        else:
                            break
                    else:
                        op.append([y, x, y, x - 1])
                    x, y = x - 1, y - 1

    print(len(op))
    for o in op:
        print(' '.join(map(str, o)))


main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    ans = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 1:
                if w != W-1:
                    A[h][w] -= 1
                    A[h][w+1] += 1
                    ans.append((h+1, w+1, h+1, w+2))
                elif h != H-1:
                    A[h][w] -= 1
                    A[h+1][w] += 1
                    ans.append((h+1, w+1, h+2, w+1))

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


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline

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

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

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

Solution (Python):


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


step = []
for i in range(h):
  for j in range(w):
    if i % 2 == 0:
      step.append((i, j))
    else:
      step.append((i, w - j - 1))  
    
ans = []
for (a, b), (c, d) in zip(step, step[1:]):
  if A[a][b] % 2 == 1:
    A[c][d] += 1
    ans.append([a + 1, b + 1, c + 1, d + 1])

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)]
ans = []
flag = False

for i in range(H):
    if i%2==0:
        for j in range(W):
            if flag:
                ans.append((pi, pj, i, j))
            
            if a[i][j]%2==1:
                flag = ~flag
            
            pi, pj = i, j
    else:
        for j in range(W-1, -1, -1):
            if flag:
                ans.append((pi, pj, i, j))
                
            if a[i][j]%2==1:
                flag = ~flag
            
            pi, pj = i, j

print(len(ans))

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

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

a = [[int(t)for t in input().split()]for _ in [0]*h]

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

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    H, W = map(int, input().split())
    grid = [list(map(int, input().split())) for _ in range(H)]
    cnt = 0
    ans_list = []
    for y in range(H):
        for x in range(W):
            if grid[y][x] % 2 == 0:
                continue
            if  x + 1 < W:
                cnt += 1
                ans_list.append((y+1, x+1, y+1, x+2))
                grid[y][x+1] += 1
                grid[y][x] -= 1
                continue
            elif y + 1 < H:
                cnt += 1
                ans_list.append((y+1, x+1, y+2, x+1))
                grid[y+1][x] += 1
                grid[y][x] -= 1
                continue

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque
from collections import Counter
from collections import OrderedDict

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

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

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

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

H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
ans = []
flag = False

for i in range(H):
    if i%2==0:
        for j in range(W):
            if a[i][j]%2==1:
                if flag:
                    ans.append((pi, pj, i, j))
                    flag = False
                else:
                    flag = True
            else:
                if flag:
                    ans.append((pi, pj, i, j))
                    
            pi, pj = i, j
    else:
        for j in range(W-1, -1, -1):
            if a[i][j]%2==1:
                if flag:
                    ans.append((pi, pj, i, j))
                    flag = False
                else:
                    flag = True
            else:
                if flag:
                    ans.append((pi, pj, i, j))
            
            pi, pj = i, j

print(len(ans))

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

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

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

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    ans = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 1:
                if w != W-1:
                    A[h][w] -= 1
                    A[h][w+1] += 1
                    ans.append((h+1, w+1, h+1, w+2))
                elif h != H-1:
                    A[h][w] -= 1
                    A[h+1][w] += 1
                    ans.append((h+1, w+1, h+2, w+1))
                else:
                    if h != 0 and A[h-1][w] % 2 == 1:
                        A[h-1][w] += 1
                        A[h][w] -= 1
                        ans.append((h+1, w+1, h, w+1))
                    elif w != 0 and A[h][w-1] % 2 == 1:
                        A[h][w-1] += 1
                        A[h][w] -= 1
                        ans.append((h+1, w+1, h+1, w))

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


if __name__ == '__main__':
    main()

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

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

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

print(num)
for i in range(num):
    ansi = ans[i]
    print(ansi[0], ansi[1], ansi[2], ansi[3])

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


if __name__ == '__main__':
    solve()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [[int(a) for a in input().split()] for _ in range(H)]
    Ans = []
    for n in range(H * W - 1):
        h, w = n // W, n % W
        if A[h][w] % 2 == 1:
            if w < W - 1:
                Ans.append((h+1, w+1, h+1, w+2))
                A[h][w] -= 1
                A[h][w+1] += 1
            else:
                Ans.append((h+1, w+1, h+2, w+1))
                A[h][w] -= 1
                A[h+1][w] += 1
    print(len(Ans))
    for move in Ans:
        print(" ".join(map(str, move)))
   
    return 0

if __name__ == "__main__":
    solve()

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

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

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

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

tmp = 0

ans = []

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

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


print(len(ans))
for a in ans:
    a[0] += 1
    a[1] += 1
    a[2] += 1
    a[3] += 1
    print(*a)

Solution (Python):
import sys

input = sys.stdin.readline


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


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

    ans = []
    h, w, = 0, 0
    next_h, next_w = 0, 0
    for _ in range(H * W - 1):
        next_h, next_w = calc_next_hw(H, W, h, w)
        if a[h][w] % 2 == 1:
            a[h][w] -= 1
            a[next_h][next_w] += 1
            ans.append((h + 1, w + 1, next_h + 1, next_w + 1))
        h, w = next_h, next_w

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
  h,w=map(int,input().split())
  a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
  ans=[]
  for i in range(h):
    for j in range(w):
      if j<w-1 and a[i][j]==1:
        a[i][j]-=1
        a[i][j+1]+=1
        a[i][j+1]%=2
        ans.append([i,j,i,j+1])
      elif i<h-1 and a[i][j]==1:
        a[i][j]-=1
        a[i+1][j]+=1
        a[i+1][j]%=2
        ans.append([i,j,i+1,j])
  print(len(ans))
  for x1,y1,x2,y2 in ans:
    print(x1+1,y1+1,x2+1,y2+1)
if __name__=='__main__':
  main()

Solution (Python):
import itertools
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
s = []
for i, j in itertools.product(range(h), range(w - 1)):
  if a[i][j] % 2 == 1:
    s.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][w - 1] % 2 == 1:
    s.append((i + 1, w, i + 2, w))
    a[i][w - 1] -= 1
    a[i + 1][w - 1] += 1
print(len(s))
for l in s:
  print(*l)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
A = [lr() for _ in range(H)]
answer = []
for i in range(H):
    for j in range(W-1):
        if A[i][j]&1:
            answer.append((i+1, j+1, i+1, j+2))
            A[i][j+1] += 1

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

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

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
A = [lr() for _ in range(H)]
answer = []
for i in range(H):
    for j in range(W-1):
        if A[i][j]&1:
            answer.append((i+1, j+1, i+1, j+2))
            A[i][j+1] += 1

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

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

Solution (Python):
h,w=map(int,input().split())
aa=[list(map(int, input().split())) for _ in range(h)]
odd=[]
for y in range(h):
    temp=[]
    for x in range(w):
        if aa[y][x]%2==1:
            temp.append((y,x))
    if y%2==0:
        temp.sort()
    else:
        temp.sort(reverse=True)
    odd+=temp

result=[]
i=0
while i<(len(odd)//2)*2:
    
    start=odd[i]
    sx,sy=start[1],start[0]

    goal=odd[i+1]
    gx,gy=goal[1],goal[0]

    

    
    if sy%2==0:
        if gx<sx:
            flag="yx"
        else:
            flag="xy"
    else:
        if gx<sx:
            flag="xy"
        else:
            flag="yx"
    
    while sx!=gx or sy!=gy:
        
        if flag=="xy":
            if sx<gx:
                result.append((sy+1,sx+1,sy+1,sx+1+1))
                sx+=1
            elif sx>gx:
                result.append((sy+1,sx+1,sy+1,sx-1+1))
                sx-=1
            elif sy<gy:
                result.append((sy+1,sx+1,sy+1+1,sx+1))
                sy+=1
            else:
                result.append("error1")
        elif flag=="yx":
            if sy<gy:
                result.append((sy+1,sx+1,sy+1+1,sx+1))
                sy+=1
            elif sx<gx:
                result.append((sy+1,sx+1,sy+1,sx+1+1))
                sx+=1
            elif sx>gx:
                result.append((sy+1,sx+1,sy+1,sx-1+1))
                sx-=1
            else:
                result.append("error2")
    i+=2

print(len(result))
for item in result:
    print(" ".join(map(str,item)))

Solution (Python):


import sys


def main():
    def input(): return sys.stdin.readline().rstrip()
    def mi():    return map(int, input().split())
    def lmi():   return list(map(int, input().split()))

    def move(from_i, from_j, to_i, to_j, ans):
        y, x = from_i, from_j
        while not (y == to_i and x == to_j):
            
            if (y % 2 == 0 and x == w - 1) or (y % 2 == 1 and x == 0):
                
                ans.append("{} {} {} {}".format(y+1, x+1, y+2, x+1))
                y += 1
            elif y % 2 == 0:
                
                ans.append("{} {} {} {}".format(y+1, x+1, y+1, x+2))
                x += 1
            else:
                
                ans.append("{} {} {} {}".format(y+1, x+1, y+1, x))
                x -= 1
    
    h, w = mi()
    L = [lmi() for _ in range(h)]
    coin_odd = []
    for i in range(h):
        if i % 2 == 0:
            for j in range(w):
                if L[i][j] % 2 == 1:
                    coin_odd.append((i, j))
        else:
            for j in range(w-1, -1, -1):
                if L[i][j] % 2 == 1:
                    coin_odd.append((i, j))              

    ans = []
    
    
    coin_odd.reverse()
    
    while len(coin_odd) >= 2:
        from_i, from_j = coin_odd.pop()
        to_i, to_j = coin_odd.pop()
        move(from_i, from_j, to_i, to_j, ans)
        L[from_i][from_j] -= 1
        L[to_i][to_j] += 1

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


if __name__ == "__main__":
    main()

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

for i in range(H):
    for j in range(W):
        done[i][j] = 1
        if a[i][j] % 2 == 1:
            for i_d, j_d in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
                if (0 <= i + i_d < H and 0 <= j + j_d < W
                and done[i + i_d][j + j_d] == 0):
                    cnt += 1
                    move.append([i + 1, j + 1, i + i_d + 1, j + j_d + 1])
                    a[i + i_d][j + j_d] += 1
                    break

print(cnt)
for m in move:
    print(" ".join(map(str, m)))

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

B=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                B.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            elif i+1<h:
                B.append([i,j,i+1,j])
                A[i+1][j] +=1

print(len(B))
for i in B:
    print(*list(map(lambda x:x+1,i)))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

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


if __name__ == '__main__':
    resolve()

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

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

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


if __name__ == '__main__':
    main()

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

cnt = 0
history = []
for i in range(h):
    range_j = range(w) if i%2 == 0 else range(w)[::-1]
    for j in range_j:
        if i == h-1 and j == range_j[-1]:    
            break

        if a[i][j] % 2 == 0:
            continue
        
        next_cell = None
        if i%2 == 0:    
            if j+1 >= w:    
                next_cell = (i+1, j)
                a[i][j] -= 1
                a[i+1][j] += 1
            else:
                next_cell = (i, j+1)
                a[i][j] -= 1
                a[i][j+1] += 1
        else:           
            if j-1 < 0: 
                next_cell = (i+1, j)
                a[i][j] -= 1
                a[i+1][j] += 1
            else:
                next_cell = (i, j-1)
                a[i][j] -= 1
                a[i][j-1] += 1
        history.append(map(str, [i+1, j+1, next_cell[0]+1, next_cell[1]+1]))
        cnt += 1

print(cnt)
for h in history:
    print(" ".join(h))

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
n = 0
ans = []
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 0:
            continue
        if i < h - 1:
            n += 1
            ans.append([i + 1, j + 1, i + 2, j + 1])
            a[i][j] -= 1
            a[i + 1][j] += 1
        elif j < w - 1:
            n += 1
            ans.append([i + 1, j + 1, i + 1, j + 2])
            a[i][j] -= 1
            a[i][j + 1] += 1
                

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 _ in range(h)]

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            elif 0<=i+1<h:
                C.append([i,j,i+1,j])
                A[i+1][j] +=1

print(len(C))
for i in C:
    print(*list(map(lambda x:x+1,i)))

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

operations=[]
N=0
for y in range(H):
    for x in range(W):
        if a[y][x]%2==0:
            continue
        else:
            flag=0
            for i,j in ([0,1],[0,-1],[1,0],[-1,0]):
                new_y,new_x=y+i,x+j
                if new_y<0 or new_y>=H or new_x<0 or new_x>=W:
                    continue
                elif a[new_y][new_x]%2!=0:
                    N+=1
                    a[y][x]-=1
                    a[new_y][new_x]+=1
                    operations.append([y+1,x+1,new_y+1,new_x+1])
                    flag=1
                    break
            if flag==0:
                if y!=H-1:
                    N+=1
                    a[y][x]-=1
                    a[y+1][x]+=1
                    operations.append([y+1,x+1,y+2,x+1])
                elif y==H-1 and x!=W-1:
                    N+=1
                    a[y][x]-=1
                    a[y][x+1]+=1
                    operations.append([y+1,x+1,y+1,x+2])

print(N)
for i in range(N):
    print(*operations[i])