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 = []
for i in range(h):
    tmp = list(map(int, input().split()))
    a.append(tmp)

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

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

c = 0
ans = []
ans_c = 0
for i in range(1, H+1):
    for j in range(1, W+1):

        h, w = i, j

        if h % 2 == 0:
            w = W-j+1

        if j == W:
            nh = h+1
            nw = w
        else:
            nh = h
            if h % 2 == 1:
                nw = w+1
            else:
                nw = w-1

        if (a[h-1][w-1]+c) % 2 == 0:
            c = 0
        elif (a[h-1][w-1]+c) % 2 == 1:
            c = 1
            if i != H or j != W:
                ans_c += 1
                ans.append((h, w, nh, nw))

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
H, W = map(int, input().split())
a = [input().split() for l in range(H)]
ansK=[]

ans = int(0)
count = int(0)

for i in range(W):
    for j in range(H):
        if j!=H-1:
            if i!=W-1:
                if int(a[j][i])%2==1:
                    a[j][i+1] = int(a[j][i+1])+1
                    a[j][i]   = int(a[j][i])  -1
                    ansK.append([j+1,i+1,j+1,i+2])
                    count += 1
            elif i ==W-1:
                if int(a[j][i])%2==1:
                    a[j+1][i] = int(a[j+1][i])+1
                    a[j][i]   = int(a[j][i])-1
                    ansK.append([j+1,i+1,j+2,i+1])
                    count += 1
        else:
            if i != W - 1:
                if int(a[j][i])%2==1:
                    a[j][i+1] = int(a[j][i+1])+1
                    a[j][i]   = int(a[j][i])-1
                    ansK.append([j+1,i+1,j+1,i+2])
                    count += 1

ans = count
print(ans)
[print(' '.join(map(str, i))) for i in ansK]

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

ans = []
ans_list = []

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

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

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                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]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                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]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

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


b = [[t for t in x] for x in a]
moves = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if b[i - 1][j - 1] % 2 == 1:
            if j < W:
                b[i - 1][j] += 1
                moves.append((i, j, i, j + 1))
            elif i < H:
                b[i][j - 1] += 1
                moves.append((i, j, i + 1, j))
ans = (
    '{}\n{}'.format(
        len(moves),
        '\n'.join(
            ' '.join([str(y1), str(x1), str(y2), str(x2)])
            for (y1, x1, y2, x2) in moves
        )
    ) if moves else
    '0'
)

print(ans)

Solution (Python):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
N = 0
Q = []
for w in range(W):
  for h in range(H-1):
    if A[h][w]%2 == 1:
      A[h][w] -= 1
      A[h+1][w] += 1
      Q.append([h+1,w+1,h+2,w+1])
      N += 1
for w in range(W-1):
  if A[H-1][w]%2 == 1:
    A[H-1][w] -= 1
    A[H-1][w+1] += 1
    Q.append([H,w+1,H,w+2])
    N += 1
print(N)
for i in range(N):
  print(" ".join(map(str,Q[i])))

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

B = []
for h in range(H):
    for w in range(W):
        if A[h][w] % 2 == 1:
            if w == W-1:
                if h != H-1:
                    B.append((h, w, h+1, w))
                    A[h+1][w] += 1
            else:
                B.append((h, w, h, w+1))
                A[h][w+1] += 1
print(len(B))
for b in B:
    print(' '.join([str(q+1) for q in b]))

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 != 0:
            ans.append([i+1, j+1, i+1, j+2])
            a[i][j+1] += 1
            a[i][j] -= 1

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

print(len(ans))
for _ans in ans:
    print(str(_ans[0]) + ' ' + str(_ans[1]) + ' ' + str(_ans[2]) + ' ' + str(_ans[3]))

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = set()
    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):

import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    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 i in range(H)]
N = 0
ans = []
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
      ans.append([y+1,x+1,y+2,x+1])
      N += 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
    ans.append([H,x+1,H,x+2])
    N += 1
print(N)
for i in ans:
  print(" ".join(map(str,i)))

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                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]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                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]:
            A[i][W - 1] ^= 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):

import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  
        for j in range(W - 1):
            if A[i][j]:
                A[i][j] ^= 1
                A[i][j + 1] ^= 1
                ans += [(i + 1, j + 1, i + 1, j + 2)]

    for i in range(H - 1):  
        if A[i][W - 1]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += [(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(*i)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline


def main():
    H, W = tuple(map(int, input().rstrip().split()))
    A = list(
        list(map(lambda x: int(x) % 2, input().rstrip().split())) for _ in range(H)
    )
    ans = []
    
    for i in range(H):
        for j in range(W - 1):
            if A[i][j]:
                A[i][j] ^= 1
                A[i][j + 1] ^= 1
                ans += [(i + 1, j + 1, i + 1, j + 2)]
    
    for i in range(H - 1):
        if A[i][W - 1]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += [(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(*i)


if __name__ == "__main__":
    main()

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


def next(h, w):
    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)


ans = []
for i in range(H):
    for j in range(W):
        if i == H - 1 and j == W - 1:
            break
        if i % 2 == 0:
            h, w = i, j
        else:
            h, w = i, W - 1 - j
        if a[h][w] % 2 == 1:
            hn, wn = next(h, w)
            a[h][w] -= 1
            a[hn][wn] += 1
            ans.append("{} {} {} {}".format(h + 1, w + 1, hn + 1, wn + 1))
    else:
        continue
    break
print(len(ans))
for ai in ans:
    print(ai)

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

def main():
	h, w = map(int, input().strip().split())
	a = [[] for _ in range(h)]
	for i in range(h):
		a[i] = list(map(int, input().strip().split()))
	ans = []
	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
				ans.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
			ans.append((h, j+1, h, j+2))
	n = len(ans)
	print(n)
	for i in range(n):
		print("{} {} {} {}".format(ans[i][0], ans[i][1], ans[i][2], ans[i][3]))
if __name__ == '__main__':
	main()

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

n = 0
memo = []
for i in range(h):
    for j in range(w):
        if i==h-1 and j==w-1:
            continue

        if a[i][j]%2==1:
            n += 1
            a[i][j] -= 1
            if j == w-1:
                a[i+1][j] += 1
                memo.append([i+1, j+1, (i+1)+1, j+1])
            else:
                a[i][j+1] += 1
                memo.append([i+1, j+1, i+1, (j+1)+1])

print(n)
for k in memo:
    print(" ".join(list(map(str, k))))

Solution (Python):
def main():
    h,w=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(h)]
    ans=[]
    cnt=0
    for i in range(h):
        for j in range(w-1):
            if l[i][j]%2==1:
                l[i][j]-=1
                l[i][j+1]+=1
                cnt+=1
                ans.append([i+1,j+1,i+1,j+2])
    for i in range(h-1):
        if l[i][w-1]%2==1:
            l[i][w-1]-=1
            l[i+1][w-1]+=1
            cnt+=1
            ans.append([i+1,w,i+2,w])
    print(cnt)
    for i in ans:
        print(*i)
        
if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
words = lambda t : list(map(t, input().split()))
h,w = words(int)
mat = []
for _ in range(h):
    mat.append(words(int))
ans = []

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

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

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

ans = []
idx_list = [(i, j) if i % 2 == 0 else (i, W - j - 1) 
            for i in range(H) for j in range(W)]
        
for i, (x, y) in enumerate(idx_list[:-1]):
    if A[x][y] % 2 == 1:
        A[idx_list[i + 1][0]][idx_list[i + 1][1]] += 1
        ans.append([x, y, idx_list[i + 1][0], idx_list[i + 1][1]])
        
print(len(ans))
for v in ans:
    print(*[c + 1 for c in v])

Solution (Python):
def main():
    h, w = map(int, input().split())
    a = [list(map(lambda aa: aa % 2 == 0, map(int, input().split())))
         for _ in range(h)]

    right = [0] * h
    moves = []
    
    for i, row in enumerate(a):
        isCarrying = False
        for j in range(w-1):
            if isCarrying ^ row[j]:
                isCarrying = False
            else:
                isCarrying = True
                moves.append((i+1, j+1, i+1, j+2))
            right[i] = isCarrying ^ row[w-1]
    
    isCarrying = False
    for i in range(h-1):
        if isCarrying ^ right[i]:
            isCarrying = False
        else:
            isCarrying = True
            moves.append((i+1, w, i+2, w))

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


main()

Solution (Python):
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append(list(map(int, input().split())))
move = []
b = [1, -1]
for i in range(h):
    for j in range(w):
        if j == w - 1:
            if i == h - 1:
                pass
            else:
                if a[i][j * b[i % 2] + (w - 1) * (i % 2)] % 2 == 1:
                    move.append([i + 1, j * b[i % 2] + (w - 1) * (i % 2) + 1, i + 2, j * b[i % 2] + (w - 1) * (i % 2) + 1])
                    a[i + 1][j * b[i % 2] + (w - 1) * (i % 2)] += 1
        else:
            if a[i][j * b[i % 2] + (w - 1) * (i % 2)] % 2 == 1:
                move.append([i + 1, j * b[i % 2] + (w - 1) * (i % 2) + 1, i + 1, (j + 1) * b[i % 2] + (w - 1) * (i % 2) + 1])
                a[i][(j + 1) * b[i % 2] + (w - 1) * (i % 2)] += 1
print(len(move))
for i in move:
    print(i[0], i[1], i[2], i[3])

Solution (Python):
H,W = map(int,input().split())
a = list(list(map(int,input().split()))for i in range(H))
ans=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            ans.append([i+1,j+1,i+1,j+2])
            a[i][j+1] += 1
for i in range(H-1):
    if a[i][W-1]%2 == 1:
        ans.append([i+1,W,i+2,W])
        a[i+1][W-1] += 1
print(len(ans))
for a,b,c,d in ans:
    print(a,b,c,d)

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

a = [list(map(lambda x: int(x) % 2, input().split())) for _ in range(h)]

road = []
for i in range(h):
    for j in list(range(w))[::(i % 2) * -2 + 1]:
        road.append((i + 1, j + 1))

answer = []
for f, t in zip(road[:-1], road[1:]):
    if a[f[0] - 1][f[1] - 1] % 2:
        answer.append(f + t)
        a[t[0] - 1][t[1] - 1] += 1

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

Solution (Python):
h,w = map(int,input().split())
ahw = [[int(i) for i in input().split()] for j in range(h)]
hold = 0
ans = []
pos = [0,0]

for i in range(h):
  if i%2:
    for j in range(w):
      if hold:
        ans.append((pos[0],pos[1],i+1,j+1))
      if ahw[i][j]%2 and hold == 0:
        hold = 1
      elif ahw[i][j]%2 and hold:
        hold = 0
      if hold:
        pos[0] = i+1
        pos[1] = j+1
  else:
    for j in range(w-1,-1,-1):
      if hold:
        ans.append((pos[0],pos[1],i+1,j+1))
      if ahw[i][j]%2 and hold == 0:
        hold = 1
      elif ahw[i][j]%2 and hold:
        hold = 0
      if hold:
        pos[0] = i+1
        pos[1] = j+1
print(len(ans))
for i in ans:
  print(' '.join(map(str,i)))

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from math import *
from heapq import *

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


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

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

N = 0
ans = list()
last_col = list()
for i in range(H):
    A_i = list(map(int, input().split()))
    for j in range(W - 1):
        if A_i[j] % 2 != 0:
            N += 1
            ans.append(((i + 1, j + 1), (i + 1, j + 2)))
            A_i[j] -= 1
            A_i[j + 1] += 1
    last_col.append(A_i[-1])
for i in range(H - 1):
    if last_col[i] % 2 != 0:
        N += 1
        ans.append(((i + 1, W), (i + 2, W)))
        last_col[i] -= 1
        last_col[i + 1] += 1
print(N)
for (y1, x1), (y1_, x1_) in ans:
    print(y1, x1, y1_, x1_)

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

Solution (Python):
import numpy as np
h, w = map(int, input().split())
a = np.zeros((h + 1) * (w + 1)).reshape(h + 1, w + 1)
for y in range(1, h + 1):
    t = list(map(int, input().split()))
    for x in range(1, w + 1):
        a[y, x] = t[x - 1] % 2
ans = []
for y in range(1, h + 1):
    for x in range(1, w + 1):
        if (a[y, x - 1]):
            a[y, x] = (a[y, x] + a[y, x - 1]) % 2
            ans.append((y, x - 1, y, x))
for y in range(1, h + 1):
    x = w
    if (a[y - 1, x]):
        a[y, x] = (a[y, x] + a[y - 1, x]) % 2
        ans.append((y - 1, x, y, x))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Solution (Python):
H,W = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
B = []
for h in range(H):
    for w in range(W):
        if A[h][w]%2==1:
            if w+1<W:
                B.append([h+1,w+1,h+1,w+2])
                A[h][w+1]+=1
            elif h+1!=H:
                B.append([h+1,w+1,h+2,w+1])
                A[h+1][w]+=1
print(len(B))
for b in B:
    print(*b)

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

def main():
    H, W = map(int, input().split())
    bo = [list(map(int, input().split())) for i in range(H)]
    route = []
    for i in range(H):
        if i&1 == 0:
            for j in range(W):
                route.append((i, j))
        else:
            for j in range(W-1, -1, -1):
                route.append((i, j))
    
    len_ = len(route)
    ans = []
    for i in range(len_):
        y, x = route[i]
        if bo[y][x]&1 == 1 and i != len_ - 1:
            ny, nx = route[i+1]
            bo[y][x] -= 1
            bo[ny][nx] += 1
            ans.append((y+1, x+1, ny+1, nx+1))

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

if __name__ == "__main__":
    main()

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re




def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 



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

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

print(len(ans))

for a in ans:
    print(" ".join([str(i) for i in a]))

Solution (Python):



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

cnt = 0
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] == 0 or a[i][j] % 2 == 0:
                continue
            if 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 j == w-1:
                if i+1 < h:
                    a[i+1][j] += 1
                    a[i][j] -= 1
                    cnt += 1
                    ans.append([i+1,j+1,i+2,j+1])
    else:
        for j in range(w)[::-1]:
            if a[i][j] == 0 or a[i][j] % 2 == 0:
                continue
            if j != 0:
                a[i][j-1] += 1
                a[i][j] -= 1
                cnt += 1
                ans.append([i+1,j+1,i+1,j])
            elif j == 0:
                if i+1 < h:
                    a[i+1][j] += 1
                    a[i][j] -= 1
                    cnt += 1
                    ans.append([i+1,j+1,i+2,j+1])
print(cnt)
for y_ , x_ , y,x in ans:
    print(y_ , x_ , y, x)

Solution (Python):
h,w = map(int,input().split())
a = [[] for _ in range(h)]
for i in range(h):
    a[i] = [int(_) for _ in input().split()]
cnt = 0
res = []
for i in range(h):
    for j in range(w):
        if i != h-1 and a[i][j] % 2 == 1:
            cnt += 1
            res.append([i+1,j+1,i+2,j+1])
            a[i+1][j] += 1
for j in range(w-1):
    if a[h-1][j] % 2 == 1:
        cnt += 1
        res.append([h,j+1,h,j+2])
        a[h-1][j+1] += 1
print(cnt)
for i in range(len(res)):
    for j in range(4):
        print(res[i][j],end='')
        if j < 3:
            print(' ',end='')
        if j == 3:
            print()

Solution (Python):
H, W = map(int, input().split())
A = [[0 for w in range(W)] for h in range(H)]
for h in range(H):
    A[h] = list(map(int, input().split()))
    
ans = []
for h in range(H-1):
    for w in range(W):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            A[h+1][w] += 1
            ans.append([h+1, w+1, h+2, w+1])
            
for w in range(W-1):
    if A[H-1][w] % 2 == 1:
        A[H-1][w] -= 1
        A[H-1][w+1] += 1
        ans.append([H, w+1, H, w+2])
    
print(len(ans))
for a in ans:
    print(a[0], a[1], a[2], a[3])

Solution (Python):


" 解説見てしまったのでしばらくねかせる "
from collections import namedtuple

Pos = namedtuple('Pos', ('x', 'y'))

def move(pf, pt):
    return (pf.y+1, pf.x+1, pt.y+1, pt.x+1)

def order(H, W):
    ret = []
    for y in range(H):
        if y % 2 == 0:
            for x in range(W):
                ret.append(Pos(x,y))
        else:
            for x in range(W-1, -1, -1):
                ret.append(Pos(x,y))
    return ret

def main():
    H, W = list(map(int, input().split()))
    field = []
    for _ in range(H):
        la = list(map(int, input().split()))
        field.append(la)
    commands = []
    lp = order(H, W)
    for i in range(len(lp)-1):
        pf = lp[i]
        coins = field[pf.y][pf.x]
        if coins % 2 == 0:
            continue
        pt = lp[i+1]
        field[pt.y][pt.x] += 1
        commands.append(move(pf, pt))
    print(len(commands))
    for c in commands:
        print(" ".join(map(str, c)))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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

odd_points = []
odd_mat = [[False] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j]%2 == 1:
            odd_mat[i][j] = True
            odd_points.append([i,j])

odd_points = np.array(odd_points)            
if len(odd_points)%2 == 1:
    L = len(odd_points) - 1
else:
    L = len(odd_points)
    




cnt = 0
Wi = W
ans = []
M = 0
for i in range(H):
    opi = 0
    if i%2 == 0:
        Wloop = range(Wi)
        opj = 1 
    else:
        Wloop = reversed(range(Wi))
        opj = -1
        
    if i == H-1:
        if i%2 == 0:
            Wloop = range(Wi-1)
            opj = 1 
        else:
            Wloop = reversed(range(1,Wi))
            opj = -1
        
        
    for j in Wloop:
        
        if j==0 and opj == -1:
            opj = 0
            opi = +1
        elif j==W-1 and opj == 1:
            opj = 0
            opi = +1
        
        if odd_mat[i][j]:
            cnt += 1
        if cnt%2 == 1:
            ans.append([i+1,j+1,i+1+opi,j+1+opj])
            M += 1
        opi = 0
W += 1        
print(M)    
for i in range(M):
    print(' '.join(map(str,ans[i])))

Solution (Python):
H, W = [int(x) for x in input().split()]
a_list = [[int(x) for x in input().split()] for _ in range(H)]
cnt = 0
ope = []
for x in range(W):
    for y in range(H-1):
        if (a_list[y][x] % 2):
            a_list[y][x] -= 1
            a_list[y+1][x] += 1
            cnt += 1
            ope.append([y+1, x+1, y+2, x+1])
y = H-1
for x in range(W-1):
    if (a_list[y][x] % 2):
        a_list[y][x] -= 1
        a_list[y][x+1] += 1
        cnt += 1
        ope.append([y+1, x+1, y+1, x+2])
print(cnt)
lst = [" ".join(map(str, o)) for o in ope]
for ans in lst:
    print(ans)