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())
used = [[False]*W for i in range(H)]
used[0][0]=True
stuck = [(0,0)]
state = [[0]*W for i in range(H)]
way = []
ans = []
for i in range(H):
  inf = input().split()
  for j in range(W):
    state[i][j] = int(inf[j])
for i in range(H):
  ls = [(j,i) for j in range(W)]
  if i%2==0:
    ls.reverse()
  way += ls
ps = way[0]

for T in way[1:]:
  x, y = ps
  nx, ny = T
  if state[y][x]%2==1:
    ans += [(y+1,x+1,ny+1,nx+1)]
    state[y][x] -= 1
    state[ny][nx] += 1
  ps = T
print(len(ans))
for a in ans:
  print(*a)

Solution (Python):
h,w = map(int,input().split())
A = [list(map(int,input().split())) for i in range(h)]
c = [1,1]
O = []
n = 0
for i in range(h*w-1):
  if A[c[0]-1][c[1]-1] % 2 == 0:
    if c[0]%2 != 0 and c[1] < w:
      c[1] += 1
    elif c[0]%2 == 0 and c[1] > 1:
      c[1] -= 1
    else:
      c[0] += 1
  else:
    if c[0]%2 != 0 and c[1] < w:
      O += [[c[0],c[1],c[0],c[1]+1]]
      c[1] += 1
    elif c[0]%2 == 0 and c[1] > 1:
      O += [[c[0],c[1],c[0],c[1]-1]]
      c[1] -= 1
    else:
      O += [[c[0],c[1],c[0]+1,c[1]]]
      c[0] += 1
    A[c[0]-1][c[1]-1] += 1
    n += 1
print(n)
for o in O:
  print(*o)

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

cnt = 0
ans = []
for y in range(h):
    if y % 2 == 0:
        for x in range(w):
            if y == h-1 and x == w-1:
                break
            if x == w-1 and mat[y][x] % 2 == 1:
                mat[y][x] -= 1
                mat[y+1][x] += 1
                cnt += 1
                ans.append([y+1, x+1, y+2, x+1])
            elif mat[y][x] % 2 == 1:
                mat[y][x] -= 1
                mat[y][x+1] += 1
                cnt += 1
                ans.append([y+1, x+1, y+1, x+2])
    else:
        for x in reversed(range(w)):
            if y == h-1 and x == 0:
                break
            if x == 0 and mat[y][x] % 2 == 1:
                mat[y][x] -= 1
                mat[y+1][x] += 1
                cnt += 1
                ans.append([y+1, x+1, y+2, x+1])
            elif mat[y][x] % 2 == 1:
                mat[y][x] -= 1
                mat[y][x-1] += 1
                cnt += 1
                ans.append([y+1, x+1, y+1, x])

print(cnt)
for a in ans:
    print(' '.join(str(tmp) for tmp in a))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    if (a * b) % 2:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    w = SR(n)
    d = []
    for i in w:
        d.append("".join(i))
    if len(set(d)) != n:
        print("No")
        return
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            return
    print("Yes")
    return


def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    n, x = LI()
    xn = LI()+[x]
    xn.sort()
    ans = xn[1] - xn[0]
    for i in range(1, n):
        ans = gcd(ans, xn[i + 1] - xn[i])
    print(ans)
    return


def D():
    h, w = LI()
    d = []
    for y in range(h):
        a = LI()
        tmp = []
        for x in range(w):
            if a[x] & 1:
                tmp.append((y,x))
        for t in tmp[::-1 if y & 1 else 1]:
            d.append(t)
    ans = []
    for i in range(0, len(d) - 1, 2):
        y, x = d[i]
        next_y, next_x = d[i + 1]
        for ny in range(y, next_y + 1):
            for nx in range(x, -1 if ny & 1 else w, -1 if ny & 1 else 1):
                if y == ny and x == nx:
                    continue
                ans.append((y+1, x+1, ny+1, nx+1))
                if ny == next_y and nx == next_x:
                    break
                y = ny
                x = nx
    print(len(ans))
    for a in ans:
        print(*a)
    return


if __name__ == '__main__':
    D()

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

temp = 0
ans = []
for i in range(h):
    for j in range(w):
        if (i != h - 1) | (j != w - 1):
            if i % 2 == 1:
                j = w - j - 1
            if (table[i][j] + temp) % 2 == 1:
                temp = 1
                if i % 2 == 0:
                    if 0 <= j < w - 1:
                        ans.append([i + 1, j + 1,  i + 1, j + 2])
                    else:
                        ans.append([i + 1, j + 1,  i + 2, j + 1])
                else:
                    if 0 < j <= w - 1:
                        ans.append([i + 1, j + 1, i + 1, j])
                    else:
                        ans.append([i + 1, j + 1, i + 2, j + 1])
            else:
                temp = 0
print(len(ans))
for i in ans:
    print(*i)

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

res = []
started = False
steps = []
for i in range(h):
    odd = i % 2
    for j in range(w):
        if odd:
            j = w - j - 1
        if started:
            steps.append((i, j))
        if ls[i][j]:
            if not started:
                steps = [(i, j)]
                started = True
            else:
                for s, t in zip(steps, steps[1:]):
                    res.append((s[0], s[1], t[0], t[1]))
                started = False

print(len(res))
for row in res:
    row = map(lambda x: x + 1, row)
    print(*row)

Solution (Python):
H,W = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()]for _ in range(H)]
flag= 0
ans = []
for i in range(H):
  if i%2==0:
    for j in range(W):
      if A[i][j]%2==1 and flag!=1:
        flag=1
        A[i][j] -=1
      elif A[i][j]%2==1 and flag==1:
        A[i][j]+=1
        flag=0
      if flag==1:
        if j<W-1:
          ans.append([i+1,j+1,i+1,j+2])
        else:
          if i+2<=H:
            ans.append([i+1,j+1,i+2,j+1])
  elif i%2==1:
    for j in range(W-1,-1,-1):
      if A[i][j]%2==1 and flag!=1:
        flag=1
        A[i][j] -=1
      elif A[i][j]%2==1 and flag==1:
        A[i][j]+=1
        flag=0
      if flag==1:
        if j>0:
          ans.append([i+1,j+1,i+1,j])
        else:
          if i+2<=H:
            ans.append([i+1,j+1,i+2,j+1])
print(len(ans))
for a,b,c,d in ans:
  print(a,b,c,d)

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


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



moves = []


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


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


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

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  l=[LI() for _ in range(h)]

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

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

main()

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

    ope = []

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

    print(len(ope))
    for o in ope:
        print(*o) 

main()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


h, w = LI()
L = LIR(h)
ans = []
for y in range(h):
    flag = False
    for x in range(w-1):
        if L[y][x] % 2:
            flag ^= True
        if flag:
            ans += [[y+1, x+1, y+1, x+2]]
    L[y][w-1] += flag


flag = False
for y in range(h-1):
    if L[y][w-1] % 2:
        flag ^= True
    if flag:
        ans += [[y+1, w, y+2, w]]



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

Solution (Python):
H, W = map(int, input().split())
A = []
for i in range(H):
  As = list(map(int, input().split()))
  A.append(As)
L = []
for i in range(H):
  for j in range(W-1):
    if A[i][j]%2 == 1:
      A[i][j] -= 1
      A[i][j+1] += 1
      L.append((i, j, i, j+1))
for i in range(H-1):
  if A[i][-1]%2 == 1:
    A[i][-1] -= 1
    A[i+1][-1] += 1
    L.append((i, W-1, i+1, W-1))

print(len(L))
for i, j, x, y in L:
  i, j, x, y = i+1, j+1, x+1, y+1
  print(i, j, x, y)

Solution (Python):

def main():
    H, W, *A = map(int, open(0).read().split())
    A, ans = [list(a) for a in zip(*[iter(A)] * W)], []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j] & 1:
                A[i][j + 1] += 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):  
        if A[i][W - 1] & 1:
            A[i + 1][W - 1] += 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    H, W, *A = map(int, open(0).read().split())
    A = [[i & 1 for i in a] for a in zip(*[iter(A)] * W)]
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                A[i][j + 1] ^= 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):  
        if A[i][W - 1]:
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    H, W, *A = map(int, open(0).read().split())
    A = [[i & 1 for i in a] for a in zip(*[iter(A)] * W)]
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                A[i][j + 1] ^= 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):  
        if A[i][W - 1]:
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    H, W, *A = map(int, open(0).read().split())
    A = [[i % 2 for i in a] for a in zip(*[iter(A)] * W)]
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                A[i][j + 1] ^= 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):  
        if A[i][W - 1]:
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Solution (Python):

H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
res = []
d = []
for i in range(H):
  for j in range(W)[: : (-1) ** i]:
    d.append([i, j])
for i in range(len(d) - 1):
  y = d[i][0]
  x = d[i][1]
  if a[y][x] % 2:
    a[d[i + 1][0]][d[i + 1][1]] += 1
    a[y][x] -= 1
    res.append([y + 1, x + 1, d[i + 1][0] + 1, d[i + 1][1] + 1])
print(len(res))
for r in res:
  print(*r)

Solution (Python):

h,w = map(int,input().split())
raw = []
n = 0
ans = []
for j in range(h):
  tmp = list(map(lambda x: int(x)%2,input().split()))
  for i in range(w-1):
    tmp[i+1] ^= tmp[i]
    n += tmp[i]
    if tmp[i] == 1:
      ans.append([j+1,i+1,j+1,i+2])
  raw.append(tmp[-1])
for j in range(h-1):
  raw[j+1] ^= raw[j]
  n += raw[j]
  if raw[j] == 1:
    ans.append([j+1,w,j+2,w])
print(n)
for k in range(n):
  print(' '.join(list(map(str,ans[k]))))

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


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

print(N)
for i in ans:
  print(" ".join(map(str,i)))

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



H,W = II()
a = [III() for _ in range(H)]

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

print(num)
for i in move:
    print(*i, sep=' ')

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

n = h * w
answers = []
for i in range(n-1):
    if field[i] % 2 == 1:
        field[i+1] += 1
        y = i // w + 1
        x = i % w + 1
        ny = (i+1) // w + 1
        nx = (i+1) % w + 1
        if y % 2 == 0:
            x = w - x + 1
        if ny % 2 == 0:
            nx = w - nx + 1
        answers.append([y, x, ny, nx])

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

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

l = []
for y in range(H):
    l += [(x, y) for x in list(range(W))[::-1 if y%2 else 1]]

p = []
for i, (x, y) in enumerate(l[:-1]):
    if A[y][x] % 2 == 0:
        continue
    nx, ny = l[i+1]
    p.append((x+1, y+1, nx+1, ny+1))
    A[y][x] -= 1
    A[ny][nx] += 1

print(len(p))
[print(*p_i[::-1]) for p_i in p]

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


ans = []
for h in range(H):
    for w in range(W - 1):
        
        if A[h][w] % 2 == 0:
            continue

        
        A[h][w] -= 1
        A[h][w + 1] += 1

        ans.append([h, w, h, w + 1])


for h in range(H - 1):
    
    if A[h][W - 1] % 2 == 0:
        continue

    
    A[h][W - 1] -= 1
    A[h + 1][W - 1] += 1

    ans.append([h, W - 1, h + 1, W - 1])


print(len(ans))
for ph, pw, nh, nw in ans:
    print(ph + 1, pw + 1, nh + 1, nw + 1)

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

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

for i in range(H):
    if i%2==1:
        a[i].reverse()

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

Solution (Python):
H,W = map(int,input().split())
Data = []
for _ in range(H):
    List = list(map(int,input().split()))
    Data.append(List)
Ans = []
for i in range(H-1):
    for j in range(W):
        if Data[i][j] % 2 != 0:
            Data[i][j] -= 1
            Data[i+1][j] += 1
            Ans.append([i,j,i+1,j])
for j in range(W-1):
    if Data[H-1][j] % 2 != 0:
        Data[H-1][j] -= 1
        Data[H-1][j+1] += 1
        Ans.append([H-1,j,H-1,j+1])

print(len(Ans))
for ans in Ans:
    print( "{} {} {} {}".format(ans[0]+1,ans[1]+1,ans[2]+1,ans[3]+1))

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

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

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

print(len(op))
for y1, x1, y2, x2 in op:
    print(y1+1, x1+1, y2+1, x2+1)

Solution (Python):
h,w = map(int,input().split())
a = [0]

for _ in range(1,h+1):
    a.append([0]+list(map(int,input().split())))



y = []
x = []
yy = []
xx = []
left = 0
count = 0

for i in range(1,h+1):
    if i % 2 == 1:
        for j in range(1,w+1):
            if left == 0 and a[i][j] % 2 == 1:
                left = 1
                y.append(i)
                x.append(j)
            elif left == 1 and a[i][j] % 2 == 0:
                yy.append(i)
                xx.append(j)
                y.append(i)
                x.append(j)
                count += 1
            elif left == 1 and a[i][j] % 2 == 1:
                left = 0
                yy.append(i)
                xx.append(j)
                count += 1
    else:
        for j in range(0,w):
            if left == 0 and a[i][w-j] % 2 == 1:
                left = 1
                y.append(i)
                x.append(w-j)
            elif left == 1 and a[i][w-j] % 2 == 0:
                yy.append(i)
                xx.append(w-j)
                y.append(i)
                x.append(w-j)
                count += 1
            elif left == 1 and a[i][w-j] % 2 == 1:
                left = 0
                yy.append(i)
                xx.append(w-j)
                count += 1

print(count)
for k in range(count):
    print(" ".join(map(str,[y[k],x[k],yy[k],xx[k]])))

Solution (Python):
H,W=[int(s) for s in input().split()]
ls=[[int(s) for s in input().split()] for i in range(H)]
ans=[]

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

for i in range(H-1):
  if ls[i][W-1]%2==1:
    ans.append([i+1, W, i+2, W])
    ls[i+1][W-1]+=1
    
print(len(ans))
for e in ans:
  print(*e)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    H,W = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(H)]
    
    for i in range(H):
        for j in range(W):
            if A[i][j] %2 == 0:
                A[i][j] = 0
            else:
                A[i][j] = 1
    ans = 0
    Ans = []
    for i in range(H):
        for j in range(W):
            if i %2 == 0:
                k = j
            else:
                k = W-1-j
            if A[i][k] == 1:
                A[i][k] = 0
                if i%2==0:
                    if k != W-1:
                        A[i][k+1] += 1
                        A[i][k+1] %= 2
                        Ans.append([i+1,k+1,i+1,k+2])
                        ans += 1
                    else:
                        if i != H-1:
                            A[i+1][k] += 1
                            A[i+1][k] %= 2
                            Ans.append([i+1,k+1,i+2,k+1])
                            ans += 1
                else:
                    if k != 0:
                        A[i][k-1] += 1
                        A[i][k-1] %= 2
                        Ans.append([i+1,k+1,i+1,k])
                        ans += 1
                    else:
                        if i != H-1:
                            A[i+1][k] += 1
                            A[i+1][k] %= 2
                            Ans.append([i+1,k+1,i+2,k+1])
                            ans += 1
                            
    print(ans)
    for i in Ans:
        print(*i)
                
    
    
    
main()

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

count = 0
move = []
for w_i in range(w-1):
    for h_i in range(h):
        if a[h_i][w_i] % 2:
            a[h_i][w_i] -= 1
            a[h_i][w_i+1] += 1
            count += 1
            move.append([h_i+1, w_i+1, h_i+1, w_i+2])

for h_i in range(h-1):
    if a[h_i][w-1] % 2:
        a[h_i][w-1] -= 1
        a[h_i+1][w-1] += 1
        count += 1
        move.append([h_i+1, w, h_i+2, w])

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

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

    isHold = False
    cur = [0, 0]
    ops = []
    for i in range(H):
        if i % 2 == 0: start, end, dir = 0, W, 1
        else: start, end, dir = W-1, -1, -1
        for j in range(start, end, dir):
            if A[i][j] % 2 == 0:
                if isHold:
                    ops.append([cur[0]+1, cur[1]+1, i+1, j+1])
                    cur = [i, j]
            else:
                if not isHold:
                    isHold = True
                    cur = [i, j]
                else:
                    ops.append([cur[0]+1, cur[1]+1, i+1, j+1])
                    cur = [i, j]
                    isHold = False
    print(len(ops))
    if len(ops) > 0:
        for op in ops:
            print(" ".join(map(str, op)))

if __name__ == '__main__':
    main()

Solution (Python):
h, w = map(int, input().split())
a = []
for i in range(h):
  a.append(list(map(lambda x:int(x)%2,input().split())))
  
ans = []
for i in range(h):
  if i%2==0:
    for j in range(w):
      if a[i][j]==1:
        if j==w-1 and i==h-1:
          pass
        elif j==w-1:
          ans.append(' '.join(map(str,[i+1,j+1,i+2,j+1])))
          a[i+1][j]=(a[i+1][j]+1)%2
        else:
          ans.append(' '.join(map(str,[i+1,j+1,i+1,j+2])))
          a[i][j+1]=(a[i][j+1]+1)%2
  else:
    for j in range(w-1, -1, -1):
      if a[i][j]==1:
        if j==0 and i==h-1:
          pass
        elif j==0:
          ans.append(' '.join(map(str,[i+1,j+1,i+2,j+1])))
          a[i+1][j]=(a[i+1][j]+1)%2
        else:
          ans.append(' '.join(map(str,[i+1,j+1,i+1,j])))
          a[i][j-1]=(a[i][j-1]+1)%2
          
print(len(ans))
for i in range(len(ans)):
  print(ans[i])

Solution (Python):

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

a = []

N = 0
ans = []

for i in range(H):

    A = list(map(int,input().split()))

    a.append(A)

for i in range(H-1):

    for j in range(W):

        if a[i][j] % 2 == 1:

            a[i+1][j] += 1

            ans.append([i+1,j+1,i+2,j+1])

            N += 1

for j in range(W-1):

    if a[-1][j] % 2 == 1:

        a[-1][j+1] += 1

        ans.append([H,j+1,H,j+2])

        N += 1

print (N)

for i in ans:

    print (" ".join(map(str,i)))

Solution (Python):
H,W=map(int,input().split());B=[];l=[]
for y in range(H):
  A=list(map(int,input().split()));x=0
  for x in range(1,W):
    if A[x-1]%2:l.append((y+1,x,y+1,x+1));A[x]+=1
  B.append(A[x])
  if y and B[-2]%2:l.append((y,W,y+1,W));B[y]+=1
print(len(l))
for a in l:print(*a)

Solution (Python):
H, W = map(int, input().split())
lastcol = []
anslist = []
for y in range(H) :
    A = list(map(int, input().split()))
    for x, a in enumerate(A) :
        if x == W-1 :
            lastcol.append(a)
        elif a%2 :
            anslist.append((y+1, x+1, y+1, x+2))
            A[x+1] += 1
for y, a in enumerate(lastcol) :
    if y == H-1 :
        pass
    elif a%2 :
        anslist.append((y+1, W, y+2, W))
        lastcol[y+1] += 1

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

Solution (Python):
height, width = map(int, input().split())
F = [list(map(int, input().split())) for n in range(height)]

A = []
count = 0


def next_box(h_, w_, wid):
    if w_+1 == wid:
        return h_ + 1, w_

    return h_, w_ + 1


for h in range(height):
    for w in range(width):
        
        if h+1 == height and w+1 == width:
            break
        
        elif F[h][w] % 2 == 0:
            pass
        
        else:
            n_h, n_w = next_box(h, w, width)
            F[h][w] -= 1
            F[n_h][n_w] += 1

            A.append([h+1, w+1, n_h+1, n_w+1])
            count += 1


print(count)
for a in A:
    print(*a, sep=' ')

Solution (Python):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
c=0
ans=[]
for i in range(h):
    for j in range(w):
        if i==h-1 and j==w-1:
            break
        if a[i][j]%2!=0:
            c+=1
            if j==w-1:
                a[i+1][j]+=1
                a[i][j]-=1
                ans.append([i+1,j+1,i+2,j+1])
            else:
                a[i][j+1]+=1
                a[i][j]-=1
                ans.append([i+1,j+1,i+1,j+2])
print(c)
for i in range(c):
    print(*ans[i])

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
path = []
for i in range(H * W):
    h = i // W
    w = i % W if h % 2 == 0 else (W - i % W - 1)
    path.append((h, w))

ans = []
for i in range(H * W - 1):
    p, n = path[i], path[i + 1]
    if A[p[0]][p[1]] % 2 == 1:
        A[p[0]][p[1]] -= 1
        A[n[0]][n[1]] += 1
        ans.append("{} {} {} {}".format(
            p[0] + 1, p[1] + 1, n[0] + 1, n[1] + 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)]
path = []
for i in range(H * W):
    h = i // W
    w = i % W if h % 2 == 0 else (W - i % W - 1)
    path.append((h, w))

ans = []
for i in range(H * W - 1):
    p, n = path[i], path[i + 1]
    if A[p[0]][p[1]] % 2 == 1:
        A[p[0]][p[1]] -= 1
        A[n[0]][n[1]] += 1
        ans.append("{} {} {} {}".format(
            p[0] + 1, p[1] + 1, n[0] + 1, n[1] + 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 i in range(H)]
n = 0
memo = []

for x in range(W):
  for y in range(H-1):
    if A[y][x]%2 == 1:
      A[y][x] -= 1
      A[y+1][x] += 1
      n += 1
      memo.append([y+1,x+1,y+2,x+1])
for x in range(W-1):
  if A[H-1][x]%2 == 1:
    A[H-1][x] -= 1
    A[H-1][x+1] += 1
    memo.append([H,x+1,H,x+2])
    n += 1
print(n)
for i in range(n):
  print(" ".join(map(str,memo[i])))

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

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

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