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

Solution (Python):
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
H, W = map(int, input().split())
ahw = [list(map(int, input().split())) for _ in range(H)]

cnt = 0
query = []
for i in range(H):
    for j in range(W):
        if i==H-1 and j==W-1:
            continue

        if ahw[i][j]%2 and j!=W-1:
            query.append([i+1, j+1, i+1, j+2])
            ahw[i][j+1] += 1
            cnt += 1
        elif ahw[i][j]%2 and j==W-1:
            query.append([i+1, j+1, i+2, j+1])
            ahw[i+1][j] += 1
            cnt += 1

print(cnt)
for q in query:
    print(*q)

Solution (Python):
h,w=map(int,input().split())
A=[[0]*w for i in range(h+1)]
for i in range(h):
  A[i]=list(map(int,input().split()))
a=0
b=0
for i in range(h):
  if i%2==0:
    for j in range(w):
      if i==h-1 and j==w-1:
        continue
      b=b+A[i][j]
      if b%2==1:
        a=a+1
  else:
    for j in range(w-1,-1,-1):
      if i==h-1 and j==0:
        continue
      b=b+A[i][j]
      if b%2==1:
        a=a+1
print(a)
for i in range(h):
  if i%2==0:
    for j in range(w):
      if i+j==h+w-2:
        continue
      elif A[i][j]%2==0:
        continue
      else:
        if j!=w-1:
          I=i
          J=j+1
          A[i][j+1]+=1
          print(i+1,j+1,I+1,J+1)
        else:
          I=i+1
          J=w-1
          A[i+1][w-1]+=1
          print(i+1,j+1,I+1,J+1)
  else:
    for j in range(w-1,-1,-1):
      if i==h-1 and j==0:
        continue
      elif A[i][j]%2==0:
        continue
      else:
        if j!=0:
          I=i
          J=j-1
          A[i][j-1]+=1
          print(i+1,j+1,I+1,J+1)
        else:
          I=i+1
          J=0
          A[i+1][0]+=1
          print(i+1,j+1,I+1,J+1)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())

lst1 = [list(map(int,readline().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w-1):
        if lst1[i][j] %2 == 1:
            ans.append([i,j,i,j+1])
            lst1[i][j+1] += 1

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

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

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


def main():
    H, W = [int(x) for x in input().split()]
    a = [[int(x) for x in input().split()] for _ in range(H)]
    ans = []
    for i in range(H):
        for j in range(W):
            if a[i][j] & 1:
                if j == W - 1 and i == H - 1:
                    continue
                if j == W - 1:
                    ans.append((i + 1, j + 1, i + 2, j + 1))
                    a[i + 1][j] += 1
                else:
                    ans.append((i + 1, j + 1, i + 1, j + 2))
                    a[i][j + 1] += 1

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



if __name__ == '__main__':
    main()

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

ans = []
cnt = 0


def prt(i, j, k, l):
    global cnt
    cnt += 1
    ans.append((i + 1, j + 1, k + 1, l + 1))


for i in range(H):
    if i % 2 == 0:
        s, e, step = 0, W - 1, 1
    else:
        s, e, step = W - 1, 0, -1

    for j in range(s, e, step):
        if A[i][j] % 2:
            A[i][j + step] += 1
            prt(i, j, i, j + step)

    if i < H - 1:
        if A[i][e] % 2:
            A[i + 1][e] += 1
            prt(i, e, i + 1, e)
print(cnt)
for a in ans:
    print(*a)

Solution (Python):
def move(moves):
  b = []
  for (y1,x1),(y2,x2) in zip(moves[:-1],moves[1:]):
    b.append((y1,x1,y2,x2))
  return b

h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
now = 0
moves = []
ans = []
for y,coins in enumerate(a,1):
  if y % 2:
    for x,coin in enumerate(coins,1):
      if now:
        moves.append((y,x))
        if coin % 2:
          b = move(moves)
          ans += b
          moves = []
          now = 0
      else:
        if coin % 2:
          moves.append((y,x))
          now = 1
  else:
    for x,coin in enumerate(coins[::-1]):
      x = w - x
      if now:
        moves.append((y,x))
        if coin % 2:
          b = move(moves)
          ans += b
          moves = []
          now = 0
      else:
        if coin % 2:
          moves.append((y,x))
          now = 1
print(len(ans))
for i in ans:
  print(*i)

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
c = []
hold = False
for y in range(h):
    for x in list(range(w))[::-1+(y % 2 == 0)*2]:
        
        if hold:
            c.append((back[0], back[1], y + 1, x + 1))
            if a[y][x] % 2 == 1:
                hold = False
                continue
        if not hold and a[y][x] % 2 == 1:
            hold = True
        back = (y + 1, x + 1)
print(len(c))
for i in range(len(c)):
    print(*c[i])

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()))
    
n=0
ans=[]

for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j+2])
            a[i][j+1]+=1
            
for i in range(H-1):
    if a[i][-1]%2==1:
        n+=1
        ans.append([i+1,W,i+2,W])
        a[i+1][-1]+=1
        
print(n)
for i in range(len(ans)):
    print(' '.join(map(str, ans[i])))

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()))
    
n=0
ans=[]

for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j+2])
            a[i][j+1]+=1
            
for i in range(H-1):
    if a[i][-1]%2==1:
        n+=1
        ans.append([i+1,W,i+2,W])
        a[i+1][-1]+=1
        
print(n)
for i in range(len(ans)):
    print(' '.join(map(str, ans[i])))

Solution (Python):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
cnt=0
for i in range(h):
  for j in range(w):
    if a[i][j]%2:
      cnt+=1
if cnt%2:
  cnt-=1
if cnt==0:
  print(0)
  exit()
ans=[[] for i in range(cnt//2)]
l=0
for i in range(h):
  for j in range(w):
    if cnt==0:
      break
    if i%2:
      if a[i][w-j-1]%2:
        cnt-=1
        if cnt%2==0:
          ans[l].append([i+1,w-j])
          l+=1
      if cnt%2:
        ans[l].append([i+1,w-j])
    else:
      if a[i][j]%2:
        cnt-=1
        if cnt%2==0:
          ans[l].append([i+1,j+1])
          l+=1
      if cnt%2:
        ans[l].append([i+1,j+1])
t=0
for i in range(len(ans)):
  t+=len(ans[i])-1
print(t)
for i in range(len(ans)):
  for j in range(len(ans[i])-1):
    k=ans[i][j]+ans[i][j+1]
    print(*k)

Solution (Python):

h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
odd=0
for i in range(h):
    for j in range(w):
        if a[i][j]%2==1:
            odd+=1
num=0
x,y=0,0
ans=[]
for i in range(h*w):
    if a[x][y]%2==1:num+=1
    nx,ny=x,y
    if x%2==0:
        if ny==w-1:
            nx+=1
        else:
            ny+=1 
    else:
        if ny==0:
            nx+=1
        else:
            ny-=1
    
    if num%2==1:
        if num<odd:
            ans.append([x+1,y+1,nx+1,ny+1])
    x,y=nx,ny
print(len(ans))
for aa in ans:
    print(*aa)

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

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

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

ans = []
for i in range(H):
  for j in range(W-1):
    if A[i][j] % 2 == 1:
      A[i][j+1] += 1
      ans += [[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 += [[i+1, W, i+2, W]]

print(len(ans))
for a in ans:
  print(' '.join(map(str, a)))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def hitofude(H, W):
    for row in range(H):
        for col in range(W):
            if row % 2 == 1:
                new_col = W - 1 - col
            else:
                new_col = col
            yield (row, new_col)


def main():
    H, W = LI()
    A = []
    for _ in range(H):
        a = LI()
        A.append(a)
    cur = list(hitofude(H, W))[:-1]
    nex = list(hitofude(H, W))[1:]
    ans = []
    for (cur_r, cur_c), (nex_r, nex_c) in zip(cur, nex):
        if A[cur_r][cur_c] % 2 == 0:
            pass
        else:
            A[cur_r][cur_c] -= 1
            A[nex_r][nex_c] += 1
            ans.append((cur_r + 1, cur_c + 1, nex_r + 1, nex_c + 1))
    print(len(ans))
    for a in ans:
        print(*a)

main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def hitofude(H, W):
    for row in range(H):
        for col in range(W):
            if row % 2 == 1:
                new_col = W - 1 - col
            else:
                new_col = col
            yield (row, new_col)


def main():
    H, W = LI()
    A = []
    for _ in range(H):
        a = LI()
        A.append(a)
    cur = list(hitofude(H, W))[:-1]
    nex = list(hitofude(H, W))[1:]
    ans = []
    for (cur_r, cur_c), (nex_r, nex_c) in zip(cur, nex):
        if A[cur_r][cur_c] % 2 == 0:
            pass
        else:
            A[cur_r][cur_c] -= 1
            A[nex_r][nex_c] += 1
            ans.append((cur_r + 1, cur_c + 1, nex_r + 1, nex_c + 1))
    print(len(ans))
    for a in ans:
        print(*a)

main()

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
check = [[False] * W for _ in range(H)]
now_flag = True     
past_flag = True
ans = 0
ans_list = []
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            past_flag = now_flag
            now_flag = True if A[h][w] % 2 == 0 else False
            if not past_flag:      
                now_flag = False if now_flag else True     
                ans += 1
                if h != 0 and w == 0:
                    ans_list.append([h, w+1, h+1, w+1])
                else:
                    ans_list.append([h+1, w, h+1, w+1])
    if h % 2 == 1:
        for w in range(W-1, -1, -1):
            past_flag = now_flag
            now_flag = True if A[h][w] % 2 == 0 else False
            if not past_flag:
                now_flag = False if now_flag else True
                ans += 1
                if h != 0 and w == W-1:
                    ans_list.append([h, w+1, h+1, w+1])
                else:
                    ans_list.append([h+1, w+2, h+1, w+1])

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

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

N = 0
ans = []

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

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

print(N)
for a in ans:
    print(' '.join(map(str, a)))

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) 
def inpm(): return map(int,input().split()) 
def inpl(): return list(map(int, input().split())) 
def inpls(): return list(input().split())  
def inplm(n): return list(int(input()) for _ in range(n)) 
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def rotation_find(n,m,g): 
    did = [[False for _ in range(m+2)] for _ in range(n+2)]
    for i in range(n+2):
        did[i][0]=True
        did[i][m+1]=True
    for i in range(m+2):
        did[0][i]=True
        did[n+1][i]=True
    x = 1
    y = 1
    key = 1
    ans = []
    while True:
        did[x][y] = True
        key1 = 0
        if g[x-1][y-1]%2 != 0:
            key1 = 1
        a,b = x,y
        if key==1:
            x+=1
        elif key==2:
            y+=1
        elif key==3:
            x-=1
        elif key==4:
            y-=1
        if key==1 and did[x][y]:
            x-=1
            y+=1
            key=2
        elif key==2 and did[x][y]:
            y-=1
            x-=1
            key=3
        elif key==3 and did[x][y]:
            x+=1
            y-=1
            key=4
        elif key==4 and did[x][y]:
            x+=1
            y+=1
            key=1
        if did[x][y]:
            break
        if key1:
            g[a-1][b-1] -= 1
            g[x-1][y-1] += 1
            ans.append((a,b,x,y))
    return ans

def main():
    h,w = inpm()
    a = inpll(h)
    ans = rotation_find(h,w,a)
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
 
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 h in range(H-1):
    for w in range(W):
        if A[h][w] == 0:
            continue
        if A[h][w] % 2 == 0:
            continue
        A[h][w] -= 1
        A[h+1][w] += 1
        cnt += 1
        history.append([h, w, h+1, w])

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

print(cnt)
for fy, fx, ty, tx in history:
    print(fy+1, fx+1, ty+1, tx+1)

Solution (Python):
def solve():
    H, W = map(int, input().split())
    grid = [[] for _ in range(H)]
    for i in range(H):
        grid[i] = list(map(int, input().split()))
    
    ans = []
    for i in range(H):
        for j in range(W - 1):
            if grid[i][j] % 2 == 1:
                grid[i][j + 1] += 1
                ans += [(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):
        if grid[i][W - 1] % 2 == 1:
            grid[i + 1][W - 1] += 1
            ans += [(i + 1, W, i + 2, W)]
    
    N = len(ans)
    print(N)
    for ans_i in ans:
        print(' '.join(map(str, ans_i)))


if __name__ == '__main__':
    solve()

Solution (Python):
def solve():
    H, W = map(int, input().split())
    grid = [[] for _ in range(H)]
    for i in range(H):
        grid[i] = list(map(int, input().split()))
    
    ans = []
    for i in range(H):
        for j in range(W - 1):
            if grid[i][j] % 2 == 1:
                grid[i][j + 1] += 1
                ans += [[i + 1, j + 1, i + 1, j + 2]]
    for i in range(H - 1):
        if grid[i][W - 1] % 2 == 1:
            grid[i + 1][W - 1] += 1
            ans += [[i + 1, W, i + 2, W]]
    
    N = len(ans)
    print(N)
    for ans_i in ans:
        print(*ans_i)


if __name__ == '__main__':
    solve()

Solution (Python):
def solve():
    H, W = map(int, input().split())
    grid = [[] for _ in range(H)]
    for i in range(H):
        grid[i] = list(map(int, input().split()))
    
    ans = []
    for i in range(H):
        for j in range(W - 1):
            if grid[i][j] % 2 == 1:
                grid[i][j + 1] += 1
                ans += [[i + 1, j + 1, i + 1, j + 2]]
    for i in range(H - 1):
        if grid[i][W - 1] % 2 == 1:
            grid[i + 1][W - 1] += 1
            ans += [[i + 1, W, i + 2, W]]
    
    N = len(ans)
    print(N)
    for ans_i in ans:
        print(' '.join(map(str, ans_i)))


if __name__ == '__main__':
    solve()

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

ans = []
sw_rev = 0
for i in range(H):
    if sw_rev == 0:
        for j in range(W):
            if mat[i][j] % 2 != 0:
                if j == W-1:
                    if i == H-1:
                        continue
                    mat[i+1][j] += 1
                    ans.append((i, j, i+1, j))
                else:
                    mat[i][j+1] += 1
                    ans.append((i, j, i, j+1))
        sw_rev = 1
    else:
        for j in range(W)[::-1]:
            if mat[i][j] % 2 != 0:
                if j == 0:
                    if i == H-1:
                        continue
                    mat[i+1][j] += 1
                    ans.append((i, j, i+1, j))
                else:
                    mat[i][j-1] += 1
                    ans.append((i, j, i, j-1))
        sw_rev = 0
print(len(ans))
for x1, y1, x2, y2 in ans:
    print(x1+1, y1+1, x2+1, y2+1)

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

ans = []
left = True
flag = True
for i in range(H):
    if left:
        for j in range(W):
            if grid[i][j] % 2 == 1:
                if j == W-1:
                    if i == H-1:
                        flag = False
                    else:
                        grid[i][j] -= 1
                        grid[i+1][-1] += 1
                        ans.append([i, j, i+1, W-1])
                else:
                    grid[i][j] -= 1
                    grid[i][j+1] += 1
                    ans.append([i, j, i, j+1])
        left = False
    else:
        for j in reversed(range(W)):
            if grid[i][j] % 2 == 1:
                if j == 0:
                    if i == H-1:
                        flag = False
                    else:
                        grid[i][j] -= 1
                        grid[i+1][0] += 1
                        ans.append([i, j, i+1, 0])
                else:
                    grid[i][j] -= 1
                    grid[i][j-1] += 1
                    ans.append([i, j, i, j-1])
        left = True
    if not flag:
        break

print(len(ans))
for a in ans:
    a = list(map(lambda x: x+1, a))
    a = list(map(str, a))
    print(" ".join(a))

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    ans=[]
    f2=False
    for i in range(H):
        f=False
        a=list(map(int,input().split()))
        for j,x in enumerate(a):
            if j==W-1 and i!=H-1 and (x+f+f2)%2:
                ans.append((i+1,j+1,i+2,j+1))
                f=True
            elif j!=W-1 and (x+f)%2:
                ans.append((i+1,j+1,i+1,j+2))
                f=True
            else:
                f=False
        if f:
            f2=True
        else:
            f2=False
    print(len(ans))
    for z in ans:
        print(*z)

if __name__ == '__main__':
    main()

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-1):
    for j in range(W):
        if a[i][j] % 2:
            a[i][j] -= 1
            a[i+1][j] += 1
            ans.append((i+1, j+1, i+2, j+1))

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

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

Solution (Python):
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
B=[]
flag=False
for y in range(H):
  if y%2==0:
    w=range(W)
  else:
    w=reversed(range(W))
  for x in w:
    if flag:
      B.append([by+1,bx+1,y+1,x+1])
    if A[y][x]%2==1:
      flag=not flag
    by=y
    bx=x
print(len(B))
for a,b,c,d in B:
  print(a,b,c,d)

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


lst=[]
flag=0
for h in range(H):
    for w in range(W) if h%2==0 else range(W-1,-1,-1):
        if A[h][w]%2:
            if not flag:
                flag=1
            else:
                flag=0
        if flag:
            if h%2==0:
                if w<W-1:
                    lst.append([h,w,h,w+1])
                elif h<H-1:
                    lst.append([h,w,h+1,w])
            else:
                if w>0:
                    lst.append([h,w,h,w-1])
                elif h<H-1:
                    lst.append([h,w,h+1,w])
lst=[[str(i+1) for i in M] for M in lst]

print(len(lst))
for i in lst:
    print(" ".join(i))

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

ans=[]


for i in range(1,H+1):
    row = A[i]
    for j in range(1,W+1):
        odd=row[j]&1
        odd_down=A[i+1][j]&1 if i<H else 0
        odd_right=row[j+1]&1 if j<W else 0
        if odd:
            if odd_down or (j==W and i<H):
                row[j]-=1
                A[i+1][j]+=1
                ans.append((i,j,i+1,j))
            elif j<W:
                row[j]-=1
                row[j+1]+=1
                ans.append((i,j,i,j+1))

print(len(ans))
for a in ans:
    print(' '.join(map(str,a)))

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
C = sum(sum(a&1 for a in aa) for aa in A)
if C&1:
    for i in range(1,H+1):
        for j in range(1,W+1)[::(i&1)*2-1]:
            if A[i-1][j-1]&1:
                A[i-1][j-1]=0
                break
        else:
            continue
        break
R = []
prev = None
for i in range(1,H+1):
    for j in range(1,W+1)[::(i&1)*2-1]:
        if prev is None:
            if A[i-1][j-1] & 1:
                prev = i, j
        else:
            y, x = prev
            R.append((y, x, i, j))
            if A[i-1][j-1] & 1:
                prev = None
            else:
                prev = i, j

print(len(R))
for r in R:
    print(*r)

Solution (Python):
H,W = map(int,input().split())
A = []
for i in range(H):
    A.append(list(map(int,input().split())))
ans = []
for h in range(H):
    for w in range(W):
        if A[h][w]%2 == 0:
            continue
        h1 = h
        w1 = w
        if w == W-1:
            if h != H-1:
                w2 = w
                h2 = h+1
                A[h2][w2] += 1
                
            else:
                break
        else:
            w2 = w+1
            h2 = h
            A[h2][w2] += 1
        ans.append([h1+1,w1+1,h2+1,w2+1])
print(len(ans))
for i in ans:
    print(*i)

Solution (Python):
import sys

h, w = map(int, sys.stdin.readline().split())
grid = [[int(x) for x in sys.stdin.readline().split()] for _ in range(h)]

def main():
    n = 0
    move = []

    for i in range(h):
        for j in range(w-1):
            if grid[i][j] & 1:
                grid[i][j] -= 1
                grid[i][j+1] += 1
                move.append((i+1, j+1, i+1, j+2))
                n += 1
    
    for i in range(h-1):
        if grid[i][-1] & 1:
            grid[i][-1] -= 1
            grid[i+1][-1] += 1
            move.append((i+1, w, i+2, w))
            n += 1
    
    yield [n]
    for m in move:
        yield m
    
if __name__ == '__main__':
    ans = main()
    for i in ans:
        print(*i, sep=' ')

Solution (Python):
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor


"""
need to consider the case that ticket is not enough to lower everything
"""

H = gi()
W = gi()
m = [[0 for x in range(W)] for i in range(H + 5)]

for i in range(H):
    
    for j in range(W):
        o = gi()
        
        m[i][j] = o

move = 0
ops = []
for i in range(1, H):
    for j in range(0, W):
        if m[i - 1][j] % 2:
            m[i - 1][j] -= 1
            m[i][j] += 1
            move += 1
            ops.append((i, j + 1, i + 1, j + 1))

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

print(move)
for op in ops:
    print(op[0], op[1], op[2], op[3])

Solution (Python):
from collections import deque
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [[0 if A[i][j]%2==0 else 1 for j in range(W)] for i in range(H)]
C = [deque([]) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if B[i][j]==1:
            C[i].append(j)
cnt = 0
for i in range(H):
    cnt += sum(B[i])
if cnt%2==1:
    for i in range(H-1,-1,-1):
        if len(C[i])>0:
            C[i].pop()
            break
D = []
flag = 0
i = 0
while i<H:
    while len(C[i])>=2:
        if flag==0:
            j1 = C[i].popleft()
            i1 = i
            j2 = C[i].popleft()
            i = i
            for j in range(j1,j2):
                D.append((i,j,i,j+1))
        else:
            j1 = C[i].pop()
            i1 = i
            j2 = C[i].pop()
            i2 = i
            for j in range(j1,j2,-1):
                D.append((i,j,i,j-1))
    if len(C[i])==0:
        i += 1
    else:
        j = i+1
        while j<H:
            if len(C[j])>0:
                break
        j1 = C[i].pop()
        i1 = i
        if flag==0:
            j2 = C[j].pop()
            i2 = j
            for l in range(j1,W-1):
                D.append((i1,l,i1,l+1))
            for k in range(i1,i2):
                D.append((k,W-1,k+1,W-1))
            for l in range(W-1,j2,-1):
                D.append((i2,l,i2,l-1))
        else:
            j2 = C[j].popleft()
            i2 = j
            for l in range(j1,0,-1):
                D.append((i1,l,i1,l-1))
            for k in range(i1,i2):
                D.append((k,0,k+1,0))
            for l in range(j2):
                D.append((i2,l,i2,l+1))
        flag = 1-flag
        i = j
print(len(D))
for d in D:
    print(d[0]+1,d[1]+1,d[2]+1,d[3]+1)

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

for _ in range(H):
	S = list(map(int, input().split()))
	lst.append(S)
	
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
			res.append([i + 1, j + 1, (i + 1) + 1, 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
		res.append([H, j + 1, H, (j + 1) + 1])
		
print(len(res))

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

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


ANS=[]
count=0
for i in range(H):
  for j in range(W-1):
    if A[i][j]%2==1:
      count+=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][-1]%2==1:
    count+=1
    A[i+1][-1]+=1
    ANS.append(str(i+1)+" "+str(W)+" "+str(i+2)+" "+str(W))


print(count)
for i in ANS:
  print(i)