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=[]
place=[]

count=0

for i in range(H):
  a.append(list(map(int,input().split())))
 
  if i>=1:
    for j in range(W):
      if a[i-1][j]%2==1:
        count+=1
        a[i][j]+=1
        place.append([i,j+1,i+1,j+1])
  
  if i==H-1:
    for j in range(W):
      if j>=1 and a[i][j-1]%2==1:
        count+=1
        a[i][j]+=1
        place.append([i+1,j,i+1,j+1])

print(count)

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


'''
count=0
answer=0
anslist=[]

while(count!=(doubleN//2)):
  
  if place[2*count][0]==place[2*count+1][0] and place[2*count][1]==place[2*count+1][1]:
    count+=1
    continue;
  
  answer+=1 
  if place[2*count][0]==place[2*count+1][0]:
    if place[2*count][1]<place[2*count+1][1]:
      anslist.append([place[2*count][0],place[2*count][1],place[2*count][0],place[2*count][1]+1])
      place[2*count][1]+=1
      continue;
    else:
      anslist.append([place[2*count][0],place[2*count][1],place[2*count][0],place[2*count][1]-1])
      place[2*count][1]-=1
      continue;
      
  else:
    anslist.append([place[2*count][0],place[2*count][1],place[2*count][0]+1,place[2*count][1]])
    place[2*count][0]+=1
    continue;


print(answer)

for i in range(len(anslist)):
  print(anslist[i][0],anslist[i][1],anslist[i][2],anslist[i][3])
  
for i in range(len(place)//2):
  print(place[2*i][0],place[2*i][1],place[2*i+1][0],place[2*i+1][1])
'''

Solution (Python):
h, w = map(int, input().split())
T = [[] for i in range(h)]
for i in range(h):
    a = list(map(lambda s: int(s) % 2, input().split()))
    T[i] = a

move = []
i, j = 0, 0
flag = False
if T[i][j] == 1:
    flag = True
while True:
    prex, prey = i, j
    if i % 2 == 0:
        j += 1
        if j == w:
            j -= 1
            i += 1
            if i == h:
                break
    else:
        j -= 1
        if j == -1:
            j += 1
            i += 1
            if i == h:
                break
    if flag:
        move.append((prex, prey, i, j))
    if flag and T[i][j] == 1:
        flag = False
    elif T[i][j] == 1:
        flag = True

print(len(move))
for i in range(len(move)):
    a, b, c, d = move[i][0], move[i][1], move[i][2], move[i][3]
    print(a + 1, b + 1, c + 1, d + 1)

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

Solution (Python):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    B = []
    for i in range(H):
        for j in range(W):
            if A[i][j] % 2:
                if i < H - 1:
                    B.append(map(str, [i + 1, j + 1, i + 2, j + 1]))
                    A[i][j] -= 1
                    A[i + 1][j] += 1
                    continue
                elif j < W - 1:
                    B.append(map(str, [i + 1, j + 1, i + 1, j + 2]))
                    A[i][j] -= 1
                    A[i][j + 1] += 1
    
    print(len(B))
    for b in B:
        print(" ".join(b))

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    B = []
    for i in range(H):
        for j in range(W):
            if A[i][j] % 2:
                if i < H - 1:
                    B.append(map(str, [i + 1, j + 1, i + 2, j + 1]))
                    A[i][j] -= 1
                    A[i + 1][j] += 1
                    continue
                elif j < W - 1:
                    B.append(map(str, [i + 1, j + 1, i + 1, j + 2]))
                    A[i][j] -= 1
                    A[i][j + 1] += 1
    
    print(len(B))
    for b in B:
        print(" ".join(b))

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    B = []
    for i in range(H):
        for j in range(W):
            if A[i][j] % 2:
                if i < H - 1:
                    B.append(i + 1)
                    B.append(j + 1)
                    B.append(i + 2)
                    B.append(j + 1)
                    A[i][j] -= 1
                    A[i + 1][j] += 1
                    continue
                elif j < W - 1:
                    B.append(i + 1)
                    B.append(j + 1)
                    B.append(i + 1)
                    B.append(j + 2)
                    A[i][j] -= 1
                    A[i][j + 1] += 1
    
    print(int(len(B) / 4))
    for i in range(0, len(B), 4):
        for j in range(i, i + 4):
            if j != i :
                print("", B[j], end = "")
            else:
                print(B[j], end = "")
        print()


if __name__ == "__main__":
    main()

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

def path(x, y, xx, yy):
    res = []
    while x!=xx or y!=yy:
        res.append((x+1, y+1))
        if x%2==0:
            if y==W-1:
                x += 1
            else:
                y += 1
        else:
            if y==0:
                x += 1
            else:
                y -= 1
    res.append((xx+1, yy+1))
    return res

N = 0
hold = None
ans = []
for h in range(H):
    searchW = range(W) if h%2 == 0 else range(W-1, -1, -1)
    for w in searchW:
        if A[h][w]%2:
            if hold:
                p = path(hold[0], hold[1], h, w)
                for x, y in zip(p, p[1:]):
                    ans.append("{} {} {} {}".format(x[0], x[1], y[0], y[1]))
                hold = None
                N += len(p)-1
            else:
                hold = (h, w)

print(N)
for a in ans:
    print(a)

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

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

h,w = li()
grid = [li() for _ in range(h)]
ans_list = []

for hi in range(h):
    for wj in range(w):
        grid[hi][wj] %= 2

for hi in range(h):
    if hi%2 == 1:
        grid[hi] = grid[hi][::-1]
        

        
for hi in range(h):
    for wj in range(w):
        if grid[hi][wj] == 1:
            if wj < w-1:
                grid[hi][wj+1] = (grid[hi][wj+1]+1) % 2
                if hi%2 == 0:
                    ans_list.append((hi+1, wj+1, hi+1, wj+2))
                else:
                    ans_list.append((hi+1,w-wj, hi+1, w-wj-1))
                
            elif wj == w-1:
                if hi == h-1:
                    break
                
                grid[hi+1][0] = (grid[hi+1][0]+1) % 2
                if hi%2 == 0:
                    ans_list.append((hi+1, w, hi+2, w))
                else:
                    ans_list.append((hi+1,1, hi+2, 1))

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

Solution (Python):
n=list(map(int,input().split()))
a=[]
for m in range(n[0]):
    a.append(list(map(int,input().split())))
    
count=0
output=[]
for i in range(n[0]-1):
    for j in range(n[1]):
        if a[i][j]%2==1:
            count += 1
            output.append("{0} {1} {2} {3}".format(i+1,j+1,i+2,j+1))
            a[i][j] -= 1
            a[i+1][j] += 1

for j in range(n[1]-1):
    if a[n[0]-1][j]%2==1:
        count += 1
        output.append("{0} {1} {2} {3}".format(n[0],j+1,n[0],j+2))
        a[n[0]-1][j] -= 1
        a[n[0]-1][j+1] += 1 

print(count)
for t in range(len(output)):
    print(output[t])

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


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

for hi in range(h):
    for wj in range(w):
        grid[hi][wj] %= 2

ans_list = []

for hi in range(h):
    for wj in range(w-1):
        if grid[hi][wj] == 1:
            grid[hi][wj] = 0
            grid[hi][wj+1] = (grid[hi][wj+1]+1) % 2
            ans_list.append((hi+1, wj+1, hi+1, wj+2))



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



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

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

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

h,w = li()
grid = [li() for _ in range(h)]

for hi in range(h):
    for wj in range(w):
        grid[hi][wj] %= 2

ans_list = []

for hi in range(h):
    for wj in range(w-1):
        if grid[hi][wj] == 1:
            grid[hi][wj] = 0
            grid[hi][wj+1] = (grid[hi][wj+1]+1) % 2
            ans_list.append((hi+1, wj+1, hi+1, wj+2))





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



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

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



for i in range(h):
  visited.append([])
  for j in range(w):
    visited[i].append(0)
    
    if visited[i][j]==0:
      if a[i][j]%2==1:
        
        if j+1 < w:
          a[i][j]-=1
          a[i][j+1]+=1
          ans.append("%d %d %d %d" %(i+1,j+1,i+1,j+2))
          visited[i][j]=1
          
        elif i+1 < h:
          a[i][j]-=1
          a[i+1][j]+=1
          ans.append("%d %d %d %d" %(i+1,j+1,i+2,j+1))
          visited[i][j]=1
          



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

Solution (Python):
import sys
sys.setrecursionlimit(int(1e7))
n, m = map(int, input().split())
a = [[int(v) % 2 for v in input().split()] for _ in range(n)]
moves = []
for i in range(n):
    for j in range(m):
        if i == n - 1 and j == m - 1:
            break

        if a[i][j] == 1:
            if j == m - 1:
                moves.append((i + 1, j + 1, i + 2, j + 1))
                a[i + 1][j] ^= 1
            else:
                moves.append((i + 1, j + 1, i + 1, j + 2))
                a[i][j + 1] ^= 1

print(len(moves))
for move in moves:
    print(*move)

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

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

results = []

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
      results.append((y+1,x+1,y+1,x+2))

  if y != H-1 and A[y][W-1] % 2 == 1:
    A[y][W-1] -= 1
    A[y+1][W-1] += 1
    results.append((y+1, W, y+2, W))

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

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

cnt = 0
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 != 0 and j != w - 1:
                a[i][j + 1] += 1
                a[i][j] -= 1
                cnt += 1
                ans.append([i+1, j+1, i+1, j+2])
            elif a[i][j] % 2 != 0 and j == w - 1:
                if i==h-1:
                    break
                else:
                    a[i + 1][j] += 1
                    a[i][j] -= 1
                    cnt += 1
                    ans.append([i+1,j+1,i+2,j+1])
            else:
                pass
    else:
        for j in range(w):
            if a[i][w - 1 - j] % 2 != 0 and w - 1 - j != 0:
                a[i][w - 1 - j - 1] += 1
                a[i][w - 1 - j] -= 1
                cnt += 1
                ans.append([i+1, w-j,i+1,w-1-j])
            elif a[i][w - 1 - j] % 2 != 0 and w - 1 - j == 0:
                if i==h-1:
                    break
                else:
                    a[i + 1][w - 1 - j] += 1
                    a[i][w - 1 - j] -= 1
                    cnt += 1
                    ans.append([i+1, w - j, i + 2, w - j])
            else:
                pass
print(cnt)
for i in ans:
    print(' '.join(map(str, i)))

Solution (Python):

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


acts = []
for step in range(H * W - 1):
    i = step // W
    j = (step) % W
    
    if a[i][j] % 2:
        if i == H - 1:
            a[i][j] -= 1
            a[i][j + 1] += 1
            acts.append((i, j, i, j + 1))
        else:
            a[i][j] -= 1
            a[i + 1][j] += 1
            acts.append((i, j, i + 1, j))
    else:
        continue







print(len(acts))
for act in acts:
    for i, item in enumerate(act):
        if i > 0: print(" ", sep="", end="")
        print(item + 1, sep="", end="")
    print("", sep="", end="\n")

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

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):
    S = A[i]
    T = A[i+1]
    for j in range(W):
        if S[j] % 2:
            ans.append("%d %d %d %d" % (i+1, j+1, i+2, j+1))
            S[j] -= 1; T[j] += 1
S = A[-1]
for j in range(W-1):
    if S[j] % 2:
        ans.append("%d %d %d %d" % (H, j+1, H, j+2))
        S[j] -= 1; S[j+1] += 1
print(len(ans))
print(*ans, sep='\n')

Solution (Python):
H, W = map(int, input().split())
A = [0]
idx_list = []
for i in range(H):
    L = list(map(int, input().split()))
    M = []
    for j in range(W):
        M.append([i+1, j+1])
    if i%2 != 0:
        L.reverse()
        M.reverse()
    idx_list.extend(M)
    for j in range(W):
        A.append((A[-1]+L[j])%2)
A = A[1:-1]
N = sum(A)
print(N)
if N != 0:
    a = A.index(1)
    iter = 0

    while iter<N:
        if A[a] == 1:
            print(idx_list[a][0], idx_list[a][1], idx_list[a+1][0], idx_list[a+1][1])
            iter += 1
        a += 1

Solution (Python):


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

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


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

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

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

Solution (Python):
H, W = [int(c) for c in input().split()]
a = [[int(c) for c in input().split()] for _ in range(H)]
temp = False
result = []

for h in range(H):
    for w in range(W):
        if h % 2 != 0:
            w = W - w -1

        if not temp:
            if a[h][w] % 2 != 0:
                ans = "{0} {1} ".format(h+1, w+1)
                temp = True
            else:
                continue
        else:
            if a[h][w] % 2 != 0:
                ans += "{0} {1}".format(h+1, w+1)
                temp = False
                result.append(ans)
            else:
                ans += "{0} {1}".format(h+1, w+1)
                result.append(ans)
                ans = "{0} {1} ".format(h+1, w+1)

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

Solution (Python):


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


class Cell:
    def __init__(self, h, w, val):
        self.h = h
        self.w = w
        self.val = val


Cells = []
for i in range(H):
    tmp = list(map(int, input().split()))
    for j in range(W):
        Cells.append(Cell(i+1, j+1, tmp[j]))

ans = []
for i in range(len(Cells)-1):
    
    if Cells[i].val % 2 == 1:
        if Cells[i].w != W:
            Cells[i].val -= 1
            Cells[i+1].val += 1
            ans.append(str(Cells[i].h) + ' ' + str(Cells[i].w) + ' ' + str(Cells[i+1].h) + ' ' + str(Cells[i+1].w))
        
        else:
            Cells[i].val -= 1
            Cells[i+W].val += 1
            ans.append(str(Cells[i].h) + ' ' + str(Cells[i].w) + ' ' + str(Cells[i+W].h) + ' ' + str(Cells[i+W].w))


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

Solution (Python):
H, W = map(int, 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):
        jj = j if i % 2 == 0 else W - 1 - j
        k = 1 if i % 2 == 0 else -1
        if a[i][jj] % 2 == 1:
            if 0 <= jj+k <= W-1:
                ans.append((i+1, jj+1, i+1, jj+k+1))
                a[i][jj+k] += 1
            else:
                if i+1 == H:
                    break
                ans.append((i+1, jj+1, i+1+1, jj+1))
                a[i+1][jj] += 1
print(len(ans))
for i in ans:
    for j in range(4):
        print(i[j], end="")
        if j != 3:
            print("", end=" ")
        else:
            print("")

Solution (Python):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for h in range(H)]
    cnt = 0
    out = []
    for h in range(H):
        for w in range(W):
            if A[h][w]%2 == 1:
                cnt += 1
                if w < W-1:
                    A[h][w+1] += 1
                    out.append(list(map(str, [h+1, w+1, h+1, w+2])))
                elif h < H-1:
                    A[h+1][w] += 1
                    out.append(list(map(str, [h+1, w+1, h+2, w+1])))
                else:
                    cnt -= 1
    print(cnt)
    for posi in out:
        print(" ".join(posi))


if __name__ == '__main__':
    main()

Solution (Python):


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

ans = []
for i in range(H):
    for j in range(W):
        
        if HW[i][j] % 2 != 0:
            if i != 0:
                if HW[i-1][j] % 2 != 0:
                    HW[i-1][j] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i-1+1) + ' ' + str(j+1))
                    continue
            if j != 0:
                if HW[i][j-1] % 2 != 0:
                    HW[i][j-1] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1) + ' ' + str(j-1+1))
                    continue
            if i != H-1:
                if HW[i+1][j] % 2 != 0:
                    HW[i+1][j] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1+1) + ' ' + str(j+1))
                    continue
            
            if j != W-1:
                HW[i][j+1] += 1
                HW[i][j] -= 1
                ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1) + ' ' + str(j+1+1))
            
            else:
                if i != H-1:
                    HW[i+1][j] += 1
                    HW[i][j] -= 1
                    ans.append(str(i+1) + ' ' + str(j+1) + ' ' + str(i+1+1) + ' ' + str(j+1))


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

Solution (Python):


h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]
direction = 1
x, y = 0, 0


def forward(a, b):
    if direction > 0:
        if b != w-1:
            return [a, b+1, False]
        else:
            return [a+1, b, True]
    elif direction < 0:
        if b != 0:
            return [a, b-1, False]
        else:
            return [a+1, b, True]


count = 0
ans = []

while x < h and y < w:
    if A[x][y] % 2 == 0:
        x, y, turn = forward(x, y)
        if turn:
            direction *= -1
    else:
        if forward(x, y)[0] < h and forward(x, y)[1] < w:
            ans.append([x+1, y+1, forward(x, y)[0]+1, forward(x, y)[1]+1])
            count += 1
            x, y, turn = forward(x, y)
            A[x][y] += 1
            if turn:
                direction *= -1
        else:
            break

print(count)
for line in ans:
    print(' '.join(map(str, line)))

Solution (Python):
HW = list(map(int, input().split()))
H = HW[0]
W = HW[1]
a = []
ans = []

for i in range(H):
  a.append(list(map(int, input().split())))
  
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, j, i, j+1))

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

print(len(ans))
for (y1, x1, y2, x2) in ans:
  print("%d %d %d %d" % (y1+1, x1+1, y2+1, x2+1))

Solution (Python):
H, W = map(int, input().split())
N = 0
a_map = []
for i in range(H):
    a = list(map(int, input().split()))
    a_map.append(a)
result = []
for i in range(H):
    for j in range(W):
        if a_map[i][j]%2==1:
            if j < W - 1:
                N += 1
                result.append([i + 1, j + 1, i + 1, j + 2])
                a_map[i][j + 1] += 1;
                a_map[i][j] -= 1;
            elif i < H - 1:
                N += 1;
                result.append([i + 1, j + 1, i + 2, j + 1])
                a_map[i][j] -= 1;
                a_map[i + 1][j] += 1;
print(N)
for a in result:
    print(a[0], a[1], a[2], a[3])

Solution (Python):
h, w = map(int, input().split())
a = [''] * h
b = [''] * (h * w)
cnt=0
for i in range(h):
	a[i] = list(map(int,input().split()))
for j in range(h):
	for k in range(w-1):
		if a[j][k]%2==1:
			a[j][k] -= 1
			a[j][k+1] += 1
			b[cnt]=str(j+1)+' '+str(k+1)+' '+str(j+1)+' '+str(k+2)
			cnt += 1
for l in range(h-1):
	if a[l][w-1]%2==1:
		a[l][w-1] -= 1
		a[l+1][w-1] += 1
		b[cnt]=str(l+1)+' '+str(w)+' '+str(l+2)+' '+str(w)
		cnt += 1
print(cnt)
for m in range(cnt):
	print(b[m])

Solution (Python):
H,W = map(int,input().split())
a = [[int(i) for i in input().split()] for _ in range(H)]
N = 0
ans = ""
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 1:
            if j == W-1:
                if i != H-1:
                    N += 1
                    ans += "{} {} {} {}\n".format(i+1,j+1,i+2,j+1)
                    a[i+1][j] += 1
            else:
                N += 1
                ans += "{} {} {} {}\n".format(i+1,j+1,i+1,j+2)
                a[i][j+1] += 1
if N == 0:
    print(N)
else:
    print(N)
    print(ans)

Solution (Python):
HW = list(map(int, input().split()))
H = HW[0]
W = HW[1]
a = []
ans = []

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

print(len(ans))
for (y1, x1, y2, x2) in ans:
  print("%d %d %d %d" % (y1+1, x1+1, y2+1, x2+1))

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

a = []
n = 0
ans = []

for h in range(H):
    a.append(list(map(int, input().split())))
    for w in range(W):
        a[h][w] %= 2

for h in range(H):
    for w in range(W - 1, 0, -1):
        if a[h][w] != 0:
            n += 1
            ans.append("{} {} {} {}".format(h + 1, w + 1, h + 1, w))
            a[h][w - 1] = (a[h][w - 1] + a[h][w]) % 2

for h in range(H - 1, 0, -1):
    if a[h][0] != 0:
        n += 1
        ans.append("{} {} {} {}".format(h + 1, 1, h, 1))
        a[h - 1][0] = (a[h - 1][0] + a[h][0]) % 2

print(n)
print("\n".join(ans))

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

S=[]

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

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


print len(S)
for y1,x1,y2,x2 in S:
	print y1,x1,y2,x2

Solution (Python):
def myfun(c):
	return c[0];

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

arr = [];
ans = [];

for i in range(h):

	temp = list(map(int,input().split()))
	arr.append(temp)

count=0;
for i in range(h):
	for j in range(w):

		if arr[i][j]%2==1:
			if j < w-1:
				count+=1
				ans.append( [i+1,j+1,i+1,j+2])
				arr[i][j+1]+=1;
				arr[i][j]-=1;
			elif i < h-1:
				count+=1;
				ans.append( [i+1,j+1,i+2,j+1])
				arr[i][j]-=1;
				arr[i+1][j]+=1;

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

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    a.append(list(map(int,input().split())))
chk = []
for i in range(h):
    if i % 2 == 0:
        tmp = [(i,j) for j in range(w)]
    else:
        tmp = [(i,w-j-1) for j in range(w)]
    chk += tmp
log = []
for i in range(len(chk)-1):
    c = chk[i]
    nc = chk[i+1]
    if a[c[0]][c[1]] % 2 == 1:
        a[c[0]][c[1]] -= 1
        a[nc[0]][nc[1]] += 1
        log.append(" ".join(map(str,[c[0]+1,c[1]+1,nc[0]+1,nc[1]+1])))
print(len(log))
for l in log:
    print(l)

Solution (Python):
a = int(input().split()[0])
alle = []
counter = 0
output = []
for i in range(a):
	p = input().split()
	p = [int(j)%2 for j in p]
	for j in range(len(p) - 1):
		if p[j] % 2 == 1:
			output.append([i + 1, j + 1, i + 1, j + 2])
			counter += 1
			p[j + 1] += 1
	alle.append(p[-1])
	
for i in range(a - 1):
	if alle[i] % 2 == 1:
		output.append([i + 1, len(p),  i + 2, len(p)])
		counter += 1
		alle[i + 1]  += 1
		
print (counter)
for i in output:
	print (i[0],i[1],i[2],i[3])

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

ans = []
for y in range(h - 1):
    for x in range(w):
        if a[y][x] % 2 == 1:
            a[y + 1][x] += 1
            X = x + 1
            Y = y + 1
            ans.append([Y, X, Y + 1, X])
y = h - 1
for x in range(w - 1):
    if a[y][x] % 2 == 1:
        a[y][x + 1] += 1
        X = x + 1
        Y = y + 1
        ans.append([Y, X, Y, X + 1])

cnt = len(ans)
print(cnt)
for op in ans:
    print(' '.join(map(str, op)))

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

for y in range(h):
  for x in range(w):
    if x<w-1 and l[y][x]%2:
      l[y][x]-=1
      l[y][x+1]+=1
      m.extend([[y+1,x+1,y+1,x+2]])

for x in range(w):
  for y in range(h):
    if y<h-1 and l[y][x]%2:
      l[y][x]-=1
      l[y+1][x]+=1
      m.extend([[y+1,x+1,y+2,x+1]])

print(len(m))
for i in m:
  print(*i,sep=" ")

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


H, W = inpl()
mass = []
for i in range(H):
    mass.append(inpl())

count = 0
ans = []
for i in range(H):
    for j in range(W):
        if mass[i][j] & 1:
            if j < W - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
                mass[i][j] -= 1
                mass[i][j + 1] += 1
            elif i < H - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 2, j + 1])
                mass[i][j] -= 1
                mass[i + 1][j] += 1

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

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

H, W = inpl()
mass = []
coin = 0
for i in range(H):
    tmp = inpl()
    coin += sum(tmp)
    mass.append(tmp)

odd = []
for h in range(H):
    for w in range(W):
        if mass[h][w] % 2 == 1:
            odd.append([h, w])

count = 0
ans = []
odd.sort()
for i in range(H):
    for j in range(W):
        if mass[i][j] & 1:
            if j < W - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
                mass[i][j] -= 1
                mass[i][j + 1] += 1
            elif i < H - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 2, j + 1])
                mass[i][j] -= 1
                mass[i + 1][j] += 1

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