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())
a = [list(map(int,input().split())) for _ in range(H)]
ans = []
for i in range(H):
    for j in range(W):
        if j == W-1:
            if i == H-1:
                continue
            if a[i][j]%2 == 1:
                a[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
        else:
            if a[i][j]%2 == 1:
                a[i][j+1] += 1
                ans.append([i+1,j+1,i+1,j+2])
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 = []
for i in range(H):
    for j in range(W):
        if j == W-1:
            if i == H-1:
                continue
            if a[i][j]%2 == 1:
                a[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
        else:
            if a[i][j]%2 == 1:
                a[i][j+1] += 1
                ans.append([i+1,j+1,i+1,j+2])
print(len(ans))
for a in ans:
    print(*a)

Solution (Python):
inpl = lambda: list(map(int, input().split()))
H, W = inpl()
def next_sq(sq):
  h, w = sq
  if h % 2 == 0:
    if w == W-1:
      return h+1, w
    else:
      return h, w+1
  else:
    if w == 0:
      return h+1, w
    else:
      return h, w-1

a = [inpl() for _ in range(H)]
n = sum(sum(a[h][w] % 2 for w in range(W)) for h in range(H))
if n < 2:
  print(0)
  exit()
sq = (0, 0)
prev = None
ans = []
for _ in range(H*W):
  h, w = sq
  if prev is not None:
    ans.append((prev[0]+1, prev[1]+1, h+1, w+1))
    if a[h][w] % 2:
      n -= 1
      if n < 2:
        break
      prev = None
    else:
      prev = sq
  elif a[h][w] % 2:
    n -= 1
    prev = sq
  sq = next_sq(sq)

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

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

count = 0
ans = []
for i in range(h - 1):
    for j in range(w):
        if a[i][j] % 2 == 1:
            count += 1
            ans.append('{} {} {} {}'.format(i + 1, j + 1, i + 2, j + 1))
            a[i][j] -= 1
            a[i + 1][j] += 1
for j in range(w - 1):
    if a[h - 1][j] % 2 == 1:
        count += 1
        ans.append('{} {} {} {}'.format(h, j + 1, h, j + 2))
        a[h - 1][j] -= 1
        a[h - 1][j + 1] += 1

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

Solution (Python):
import itertools
h, w = map(int, input().split())
L = [ [ [i, j] for j in range(w) ][::(-1)**i] for i in range(h) ]
L = list(itertools.chain(*L))
A = [ list(map(int, input().split())) for _ in range(h) ]
ans = 0
Q = []
for i in range(h*w-1):
  nh, nw = L[i]
  if A[nh][nw]%2:
    nnh, nnw = L[i+1][0], L[i+1][1]
    A[nnh][nnw] += 1
    Q.append([nh+1, nw+1, nnh+1, nnw+1])
    ans += 1
print(ans)
for i in Q:
  print(*i, sep=" ")

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

for i in range(H):
    for j in range(W):
        if A[i][j]%2==1:
            if i==H-1 and j==W-1:
                continue
            elif 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(len(ans))
for i in ans:
    print(*i)

Solution (Python):


h,w=map(int,input().split())

g=[list('@'*(w+2))]
for i in range(h):
    g+=[list('@')+list(map(int,input().split()))+list('@')]
g+=[list('@'*(w+2))]

dir=[(0,1),(1,0)]

n=0
ans=[]
for i in range(1,h+1):
    for j in range(1,w+1):
        if g[i][j]%2==0:
            continue
        right=g[i][j+1]
        down=g[i+1][j]            
        if right!='@':
            g[i][j]-=1
            g[i][j+1]+=1
            ans.append((i,j,i,j+1))
        elif down!='@':
            g[i][j]-=1
            g[i+1][j]+=1
            ans.append((i,j,i+1,j))
        else:continue
        n+=1
print(n)
[print(*e) for e in ans]

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

al_l = []

for _ in range(h):
    al = list(map(int,input().split()))
    al_l.append(al)
    
ansl = []
get = False
for i in range(h):
    for j in range(w-1):
        if not get:
            if al_l[i][j] % 2 == 1:
                get = True
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
        elif get:
            if al_l[i][j] % 2 == 0:
                get = False
            else:
                al_l[i][j] -= 1
                al_l[i][j+1] += 1
                ansl.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            
get = False  
for i in range(h-1):
    if not get:
        if al_l[i][-1] % 2 == 1:
            get = True
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))
    elif get:
        if al_l[i][-1] % 2 == 0:
            get = False
        else:
            al_l[i][-1] -= 1
            al_l[i+1][-1] += 1
            ansl.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w = inpl()
a = [inpl() for i in range(h)]
res = []
for y in range(h-1):
    for x in range(w):
        if a[y][x] % 2:
            res.append([y+1,x+1,y+2,x+1])
            a[y][x] -= 1
            a[y+1][x] += 1
for x in range(w-1):
    if a[h-1][x] % 2:
        a[h-1][x] -= 1
        a[h-1][x+1] += 1
        res.append([h,x+1,h,x+2])
print(len(res))
for i in res:
    print(*i)

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Ans = []
for y in range(H):
    for x in range(W-1):
        if A[y][x] % 2:
            A[y][x+1] += 1
            Ans.append("{} {} {} {}".format(y+1, x+1, y+1, x+2))
x = W-1
for y in range(H-1):
    if A[y][x] % 2:
        A[y+1][x] += 1
        Ans.append("{} {} {} {}".format(y+1, x+1, y+2, x+1))
N = len(Ans)
print(N)
if N>0:
    print("\n".join(Ans))

Solution (Python):

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

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


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

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    grid=[list(map(int,input().split())) for _ in range(h)]

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

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

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

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


def main():
    H, W = map(int, input().split())
    A = []
    ans = []
    for h in range(H):
        a = list(map(int, input().split()))
        A.append(a)
    for y in range(H):
        for x in range(W):
            if A[y][x] % 2 == 1:
                if x <= W-2:
                    A[y][x] -= 1
                    A[y][x+1] += 1
                    ans.append((y+1, x+1, y+1, x+2))
                elif y <= H-2:
                    A[y][x] -= 1
                    A[y+1][x] += 1
                    ans.append((y+1, x+1, y+2, x+1))
    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()

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


def main():
    H, W = map(int, input().split())
    A = []
    ans = []
    for h in range(H):
        a = list(map(int, input().split()))
        A.append(a)
    for y in range(H):
        for x in range(W):
            if A[y][x] % 2 == 1:
                if x <= W-2:
                    A[y][x] -= 1
                    A[y][x+1] += 1
                    ans.append((y+1, x+1, y+1, x+2))
                elif y <= H-2:
                    A[y][x] -= 1
                    A[y+1][x] += 1
                    ans.append((y+1, x+1, y+2, x+1))
    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    if i %2==0:
        a += list(map(int,input().split()))
    else:
        a += list(reversed(list(map(int,input().split()))))
operations = []
ope_flag = False
idx = 0
ope_temp = ''
cnt = 0
for row in range(h):
    columns = range(w) if row%2==0 else reversed(range(w))
    for col in columns:
        if ope_flag:
            ope_temp += ' {0} {1}'.format(row+1,col+1)
            operations.append(ope_temp)
            ope_temp=''
            ope_flag=False
            a[idx]+= 1
        mod = a[idx]%2
        if mod==1:
            ope_temp = '{0} {1}'.format(row+1,col+1)
            ope_flag= True
        idx += 1
        cnt += mod
print(len(operations))
for i in range(len(operations)):
    print(operations[i])

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

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

Solution (Python):
n,m=map(int,input().split())
mat=[]

for i in range(n):
    mat.append([int(i) for i in input().split()])
move=[]
for i in range(n):
    for j in range(m):
        if mat[i][j]&1: 
            if j+1<m: 
                move.append([i,j,i,j+1])
                mat[i][j]-=1 
                mat[i][j+1]+=1 
            elif i+1<n:
                move.append([i,j,i+1,j])
                mat[i][j]-=1 
                mat[i+1][j]+=1 
print(len(move))

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
import time
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
i=0
j=0
ni=0
nj=1
pro=0
if len(a[0])==1:
    ni=1
    nj=0
tmp=0
cnt=0
li=[]
while(ni<h):
    
    if (a[i][j]+tmp)%2==1:
        li.append(" ".join(map(str, [i+1,j+1,ni+1,nj+1])))
        cnt+=1
        tmp=1
    else:
        tmp=0
    i,j=ni,nj
    if (nj+1==w and pro==0) or (nj+1==1 and pro==1):
        ni+=1
        pro^=1
    else:
        if pro==0:
            nj+=1
        else:
            nj-=1
    
    
print(cnt)
for i in li:
    print(i)

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

N = 0
actions = []
for i in range(H):
    jd = 1 - (i % 2) * 2
    js = list(range(W))[::jd]
    for j in js:
        if A[i][j] % 2 and A[i][j] != 0:
            if j == js[-1]:
                if i != H - 1:
                    ti, tj = i + 1, j
                else:
                    break
            
            else:
                ti, tj = i, j + jd

            A[ti][tj] += 1
            actions.append('{0} {1} {2} {3}'.format(i + 1, j + 1, ti + 1, tj + 1))
            N += 1

print(N)
[print(action) for action in actions]

Solution (Python):


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

ans_move = []

hitofude = []
y,x = 0,0
move_right_flg = 1
while y < H:
    hitofude.append([y,x])
    if move_right_flg == 1 and x < W-1:
        x += 1
    elif move_right_flg == 1 and x == W-1:
        y += 1
        move_right_flg = 0
    elif move_right_flg == 0 and x > 0:
        x -= 1
    else:
        y += 1
        move_right_flg = 1
        
hold_coin_flg = 0
tmp_move = -1
for current_place in hitofude:
    if a[current_place[0]][current_place[1]]%2 == 1 and hold_coin_flg == 0:
        hold_coin_flg = 1
    elif a[current_place[0]][current_place[1]]%2 == 1 and hold_coin_flg == 1:
        hold_coin_flg = 0
        tmp_move[-1].extend([current_place[0]+1, current_place[1]+1])
        ans_move.extend(tmp_move)
    if hold_coin_flg == 1:
        if tmp_move == -1 or len(tmp_move[-1]) == 4:
            tmp_move = [[current_place[0]+1, current_place[1]+1]]
        else:
            tmp_move[-1].extend([current_place[0]+1, current_place[1]+1])
            tmp_move.append([current_place[0]+1, current_place[1]+1])

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

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

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

direction = True
here = 0
answer = []
for i in range(H):
    if direction:
        while here < W:
            if here == W - 1:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = False
                break
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here + 1] += 1
                answer.append([i, here, i, here + 1])
                here += 1
            else:
                here += 1
    else:
        while -1 < here:
            if here == 0:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = True
                break
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here - 1] += 1
                answer.append([i, here, i, here - 1])
                here -= 1
            else:
                here -= 1

print(len(answer))
for i in answer:
    print(' '.join(map(str, [j + 1 for j in i])))

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

cnt = 0
ans = []

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

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

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

Solution (Python):
H,W=map(int,input().split())
a=[0]*H
result=[]
for i in range(H):
  a[i] = list(map(int,input().split()))
  for j in range(W-1):
    if(a[i][j]%2):
      result.append("{} {} {} {}".format(i+1,j+1,i+1,j+2))
      a[i][j+1] += 1
for i in range(H-1):
  if(a[i][-1]%2):
    result.append("{} {} {} {}".format(i+1,W,i+2,W))
    a[i+1][-1] += 1

print(len(result))
for i in range(len(result)):
  print(result[i])

Solution (Python):
H,W = map(int,input().split())
map_arr = []
ans = []
cnt=0
pos=0
for i in range(H):
  map_arr.extend([[i+1,idx+1,num] for idx,num in enumerate(list(map(int,input().split())))][::(-1)**i])
for x,y,num in map_arr[:-1]:
  if num%2==1:
    cnt+=1
    map_arr[pos+1][2] += 1
    ans.append([map_arr[pos][0],map_arr[pos][1],map_arr[pos+1][0],map_arr[pos+1][1]])
  pos+=1

print(cnt)
for x,y,nx,ny in ans:
  print(x,y,nx,ny)

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
h,w=map(int, input().split())
a=[list(map(int, input().split())) for i in range(h)]
ans=[]


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

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

op = []
for y in range(H - 1) :
    for x in range(W) :
        if a[y][x] % 2 != 0 :
            op.append((y + 1, x + 1, y + 2, x + 1))
            a[y+1][x] += 1

for x in range(W - 1) :
    if a[H-1][x] % 2 != 0 :
        op.append((H, x + 1, H, x + 2))
        a[H-1][x+1] += 1
        
print(len(op))
for op_ in op :
    print(*op_)

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

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

def one_line(coins, line_num, ori="lr"):
    ans_list = []
    for i in range(len(coins)-1):
        if coins[i]%2!=0:
            if ori=="lr":
                ans = "{:d} {:d} {:d} {:d}".format(line_num, i+1, line_num, i+2)
            else:
                ans = "{:d} {:d} {:d} {:d}".format(i+1, line_num, i+2, line_num)
            coins[i+1] += 1
            ans_list.append(ans)
    return ans_list, coins[-1]

ans_list = []
right_column = []
for h in range(H):
    ans, r = one_line(coins_list[h], h+1)
    ans_list += ans
    right_column.append(r)

ans, _ = one_line(right_column, W, ori="ud")
ans_list += ans

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

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

actions = []
paths = []
for y in range(H):
    for x in range(W):
        if y%2 == 0:
            paths.append((y, x))
        else:
            paths.append((y, W-x-1))

for i in range(H*W-1):
    y, x = paths[i]
    if A[y][x]%2 == 1:
        actions.append((paths[i][0]+1, paths[i][1]+1, paths[i+1][0]+1, paths[i+1][1]+1))
        ny, nx = paths[i+1]
        A[ny][nx] += 1

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
t=0
n=0
a=[]
for i in range(H//2):
    s=tuple(map(int,input().split()))
    for j in range(W-1):
        if (s[j]+t)%2==1:
            t=1
            a.append((2*i+1,j+1,2*i+1,j+2))
            n+=1
        else:
            t=0
    if (s[-1]+t)%2==1:
        t=1
        a.append((2*i+1,W,2*i+2,W))
        n+=1
    else:
        t=0
    s=tuple(map(int,input().split()))
    for j in range(W-1,0,-1):
        if (s[j]+t)%2==1:
            t=1
            a.append((2*i+2,j+1,2*i+2,j))
            n+=1
        else:
            t=0
    if (s[0]+t)%2==1:
        if i!=H/2-1:
            t=1
            a.append((2*i+2,1,2*i+3,1))
            n+=1
    else:
        t=0
if H%2==1:
    s=tuple(map(int,input().split()))
    for j in range(W-1):
        if (s[j]+t)%2==1:
            t=1
            a.append((H,j+1,H,j+2))
            n+=1
        else:
            t=0
print(n)
for i in a:
    print(*i)

Solution (Python):
h,w=map(int,input().split())
b=[list(map(int,input().split()))for i in range(h)]
c=[]
for i in range(h):
  if i%2:b[i]=b[i][::-1]
for i in range(h):
  for j in range(w):
    if b[i][j]%2==0:continue
    y=yy=i
    x=xx=j
    if j==w-1:yy+=1;xx=0
    else:xx+=1
    if not(yy<h and xx<w):continue
    b[yy][xx]+=1
    if yy%2:xx=w-1-xx
    if y%2:x=w-1-x
    c.append([y+1,x+1,yy+1,xx+1])
print(len(c))
for i in c:print(*i)

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

h,w=map(int,input().split())

B,ans,cnt=[],[],0
Bappend=B.append
ansappend=ans.append
fflag=False

for i in range(h):
    A=list(map(int,input().split()))
    flag=False
    for j in range(w-1):
        if flag:
            if A[j]%2==0:
                ansappend((i+1,j+1,i+1,j+2))
                flag=True
                cnt+=1
            else:
                flag=False
        else:
            if A[j]%2==1:
                ansappend((i+1,j+1,i+1,j+2))
                flag=True
                cnt+=1
    if i!=h-1:
        if flag+fflag==1:
            if A[w-1]%2==0:
                ansappend((i+1,w,i+2,w))
                fflag=True
                cnt+=1
            else:
                fflag=False
        else:
            if A[w-1]%2==0:
                fflag=False
            else:
                ansappend((i+1,w,i+2,w))
                fflag=True
                cnt+=1
                
print(cnt)
for a in ans:
    print(*a)

Solution (Python):
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
a_dict = dict()
for i in range(h):
    a_dict[i] = [int(i) for i in sys.stdin.readline().split()]
start = [0,0]
root = []
flg = True
while True:
    y, x = start
    if flg:
        if x + 1 >= w:
            if y + 1 >= h:
                break
            flg = False
            y += 1
        else:
            x += 1
    else:
        if x - 1 < 0:
            if y + 1 >= h:
                break
            y += 1
            flg = True
        else:
            x -= 1
    _next = [y, x]
    if a_dict[start[0]][start[1]] % 2 == 1:
        root.append([start[0] + 1, start[1] + 1, _next[0] + 1, _next[1] + 1])
        a_dict[start[0]][start[1]] -= 1
        a_dict[y][x] += 1
    start = _next
print(len(root))
for i in root:
    print(" ".join([str(j) for j in i]))

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

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

    else:
        for j in reversed(range(W)):
            f=f!=a[i][j]
            if f:
                if j>0:
                    ans.append((i+1,j+1,i+1,j))
                elif i<H-1:
                    ans.append((i+1,1,i+2,1))

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

Solution (Python):
n,m=map(int,input().split())
a=[]
for i in range(n):
	k=list(map(int,input().split()))
	a.append(k)
q=[]
for i in range(n):
	for j in range(m):
		if a[i][j]%2!=0:
			a[i][j]-=1
			if j!=m-1:
				a[i][j+1]+=1
				q.append([i+1,j+1,i+1,j+1+1])
			else:
				try:
					a[i+1][j]+=1
					q.append([i+1,j+1,i+1+1,j+1])
				except:
					print(len(q))
					for ii in range(len(q)):
						print(*q[ii])
					exit()
print(len(q))
for i in range(len(q)):
	print(*q[i])

Solution (Python):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
data=[]
for i in range(h-1):
    count=0
    lst=a[i]
    for j in range(w-1):
        if lst[j]%2==1:
            count+=1
        if count%2==1:
            data.append([i+1,j+1,i+1,j+2])
    if lst[w-1]%2==1:
        count+=1
    if count%2==1:
        data.append([i+1,w,i+2,w])
        a[i+1][w-1]+=1
count=0
lst=a[h-1]
for j in range(w-1):
    if lst[j]%2==1:
        count+=1
    if count%2==1:
        data.append([h,j+1,h,j+2])
print(len(data))
for v in data:
    print(" ".join(list(map(str,v))))

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

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

for i in range(h-1):
    if a[i][w-1] % 2 == 1:
        a[i+1][w-1] += 1
        res.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))

print(len(res))
print("\n".join(res))

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


def main():
    H, W = map(int, input().split())
    a = []
    for i in range(H):
        ai = list(map(int, input().split()))
        a.append(ai)
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j] % 2 == 1:
                a[i][j] -= 1
                a[i][j+1] += 1
                ans.append((i+1, j+1, i+1, j+2))
    for i in range(H-1):
        if a[i][-1] % 2 == 1:
            a[i][-1] -= 1
            a[i+1][-1] += 1
            ans.append((i+1, W, i+2, W))
    N = len(ans)
    print(N)
    for ansi in ans:
        print(ansi[0], ansi[1], ansi[2], ansi[3])


if __name__ == '__main__': main()

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

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

print(len(res))
for r1,r2,r3,r4 in res:
    print(r1,r2,r3,r4)

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

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

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

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

Solution (Python):
from sys import stdin

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(H)]
ans = []
cnt = 0

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

print(cnt)
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)]

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

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

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

Solution (Python):
H,W=map(int,input().split())
lst=[[0]*W for _ in range(H)]
for i in range(H):
  lst[i]=list(map(int,input().split()))
N=0
tmp=[]
for i in range(H):
  for j in range(W):
    if lst[i][j]%2==0:
      pass
    else:
      if 0<=j<=W-2:
        lst[i][j+1]+=1
        N+=1
        tmp.append([str(i+1),str(j+1),str(i+1),str(j+2)])
      if j==W-1:
        if i+1<=H-1:
          lst[i+1][j]+=1
          N+=1
          tmp.append([str(i+1),str(j+1),str(i+2),str(j+1)])

print(N)
for i in range(len(tmp)):
  print(' '.join(tmp[i]))

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

a=[[int(x)%2 for x in input().split()] for y in range(h)] 
b=[0 for y in range(h)]

l=list()
for y in range(h):
  x=0
  t=False
  while x < w:
    if a[y][x]:
      if t==False:
        if x!=w-1:
          l.append([y+1,x+1,y+1,x+2])
        t=True
      else:
        t=False
    elif t==True:
      if x!=w-1:
        l.append([y+1,x+1,y+1,x+2])
    x += 1
  b[y]=1 if t==True else 0

y=0
t=False
while y < h:
  if b[y]:
    if t==False:
      if y!=h-1:
        l.append([y+1,w,y+2,w])
      t=True
    else:
      t=False
  elif t==True:
    if y!=h-1:
      l.append([y+1,w,y+2,w])
  y+=1

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