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())
lists=[0 for _ in range(h)]
for _ in range(h):
    s=list(map(int,input().split()))
    lists[_]=s

subanswer=0
anslist=[0]*w
uselist=[]
if h>=2:
    for _ in range(w):
        s=[lists[j][_]%2 for j in range(h)]
        for i in range(h-1):
            if s[i]==0 and s[i+1]==0:
                s[i]=0 
                s[i+1]=0
     
            elif s[i]==0 and s[i+1]==1:
                s[i]=0
                s[i+1]=1
     
            elif s[i]==1 and s[i+1]==0:
                s[i]=0
                s[i+1]=1
                uselist.append([i+1,_+1,i+2,_+1])
                subanswer+=1
      
            elif s[i]==1 and s[i+1]==1:
                s[i]=0
                s[i+1]=0
                uselist.append([i+1,_+1,i+2,_+1])
                subanswer+=1

        anslist[_]=s[h-1]
        
else:
    anslist=[lists[0][_]%2 for _ in range(w)]


for i in range(w-1):
    if anslist[i]==0 and anslist[i+1]==0:
        anslist[i]=0 
        anslist[i+1]=0
     
    elif anslist[i]==0 and anslist[i+1]==1:
        anslist[i]=0
          
        anslist[i+1]=1
     
    elif anslist[i]==1 and anslist[i+1]==0:
        anslist[i]=0
        anslist[i+1]=1
        uselist.append([h,i+1,h,i+2])
        subanswer+=1
      
    elif anslist[i]==1 and anslist[i+1]==1:
        anslist[i]=0
        anslist[i+1]=0
        uselist.append([h,i+1,h,i+2])
        subanswer+=1  
  


print(subanswer)  
for some in uselist:
    print(*some)

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

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

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

Solution (Python):
h, w = map(int, input().split())
a_matrix = [list(map(int, input().split())) for _ in range(h)]
ans_list = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a_matrix[i][j] % 2 == 1:
                if j != w-1:
                    a_matrix[i][j+1] += 1
                    ans_list.append([i+1, j+1, i+1, j+2])
                elif j == w-1 and i != h-1:
                    a_matrix[i+1][j] += 1
                    ans_list.append([i+1, j+1, i+2, j+1])
    if i % 2 == 1:
        for j in range(w-1, -1, -1):
            if a_matrix[i][j] % 2 == 1:
                if j != 0:
                    a_matrix[i][j-1] += 1
                    ans_list.append([i+1, j+1, i+1, j])
                elif j == 0 and i != h-1:
                    a_matrix[i+1][j] += 1
                    ans_list.append([i+1, j+1, i+2, j+1])
print(len(ans_list))
for i in range(len(ans_list)):
    print(*ans_list[i])

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






def main():
    h,w=map(int,input().split())
    A=[]
    ans=[]
    n=0
    for i in range(h):
        a=list(map(int,input().split()))
        if i%2==0:
            for j in range(w):
                A.append([i+1,j+1,a[j]])
        else:
            for j in reversed(range(w)):
                A.append([i+1,j+1,a[j]])
    for i in range(h*w-1):
        if A[i][2]%2==1:
            ans.append([A[i][0],A[i][1],A[i+1][0],A[i+1][1]])
            A[i+1][2]+=1
            n+=1
    print(n)
    for l in ans:
        print(*l)

if __name__ == '__main__':
    main()

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






def main():
    h,w=map(int,input().split())
    A=[]
    ans=[]
    n=0
    for i in range(h):
        a=list(map(int,input().split()))
        if i%2==0:
            for j in range(w):
                A.append([i+1,j+1,a[j]])
        else:
            for j in reversed(range(w)):
                A.append([i+1,j+1,a[j]])
    for i in range(h*w-1):
        if A[i][2]%2==1:
            ans.append([A[i][0],A[i][1],A[i+1][0],A[i+1][1]])
            A[i+1][2]+=1
            n+=1
    print(n)
    for l in ans:
        print(*l)

if __name__ == '__main__':
    main()

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

t=0
ans=[]
for i in range(H):
	a=A[i]
	if i%2==0:
		for j in range(W-1):
			if (a[j]+t)%2!=0:
				ans.append([i,j,i,j+1])
				t=1
			else:
				t=0
		
		if (a[-1]+t)%2!=0 and (i+1)<H:
			ans.append([i,W-1,i+1,W-1])
			t=1
		else:
			t=0
	else:
		for j in range(1,W)[::-1]:
			if (a[j]+t)%2!=0:
				ans.append([i,j,i,j-1])
				t=1
			else:
				t=0
		
		if (a[0]+t)%2!=0 and (i+1)<H:
			ans.append([i,0,i+1,0])
			t=1
		else:
			t=0

print(len(ans))
for a in ans:
	for i in range(4):a[i]+=1
	print(*a)

Solution (Python):

def o(x, w):
    if x == 0:
        return w
    else:
        return x

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

b = []
for i in range(h):
    if i%2 == 0:
        tmp = a[i]
    else:
        tmp = a[i][::-1]
    for j in range(w):
        b.append(tmp[j])



l1 = []
l2 = []
for i in range(len(b)-1):
    if b[i]%2 == 1:
        b[i] -=1
        b[i+1] += 1
        if ((i+0)//w) % 2 == 1:
            l1.append(((i)//w) * w - i%w + w - 1)
        else:
            l1.append(i)
        j = i+1
        if ((j+0)//w) % 2 == 1:
            l2.append(((j)//w) * w - j%w + w - 1)
        else:
            l2.append(j)





print(len(l1))
for i in range(len(l1)):
    y1 = l1[i]//w+1
    x1 = l1[i]%w+1
    y2 = l2[i]//w+1
    x2 = l2[i]%w+1
    print(y1, x1, y2, x2)

Solution (Python):
H,W = map(int, input().split())
L = []
for i in range(H):
    L.append([int(a) for a in input().split()])
    
p = 0
cnt = 0
for i in range(H):
    for j in range(W):
        if L[i][j]%2 == 1:
            cnt += 1
            p = [i, j]
ans_list = []
temp = 0
for i in range(H):
    if i%2 == 0:
        for j in range(W):
            if L[i][j]%2 == 0:
                if temp != 0:
                    if j != 0:
                        ans_list.append([i+1, j, i+1, j+1])
                    else:
                        ans_list.append([i, j+1, i+1, j+1])
            else:


                if temp == 0:
                    temp = [i, j]
                else:
                    if j != 0:
                        ans_list.append([i+1, j, i+1, j+1])
                    else:
                        ans_list.append([i, j+1, i+1, j+1])
                    temp = 0
    else:
        for j in range(W):
            j = W-1-j
            if L[i][j]%2 == 0:
                if temp != 0:
                    if j == W-1:
                        ans_list.append([i, j+1, i+1, j+1])
                    else:
                        ans_list.append([i+1, j+2, i+1, j+1])
            else:


                if temp == 0:
                    temp = [i, j]
                else:
                    if j == W-1:
                        ans_list.append([i, j+1, i+1, j+1])
                    else:
                        ans_list.append([i+1, j+2, i+1, j+1])
                    temp = 0
                        

N = len(ans_list)
print(N)
for i in range(N):
    for j in range(4):
        ans_list[i][j] = str(ans_list[i][j])
    print(" ".join(ans_list[i]))

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

a = []

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

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

Solution (Python):
h, w = map(int, input().split())
a = []
m = []
ans = []
for _ in range(h):
    a.append(list(map(int, input().split())))
for j in range(h):
    f = 0
    for i in range(w):
        if not f:
            if a[j][i] % 2:
                f = a[j][i]
        else:
            ans.append([j+1, i, j+1, i+1])
            if a[j][i] % 2:
                f = 0
    m.append(f)

f = 0
for j in range(h):
    if not f:
        if m[j] % 2:
            f = m[j]
    else:
        ans.append([j, w, j+1, w])
        if m[j] % 2:
            f = 0

print(len(ans))
for ansi in ans:
    print(" ".join([str(x) for x in ansi]))

Solution (Python):
ni = lambda: int(input())
nl = lambda: list(map(int, input().split()))
nm = lambda: map(int, input().split())

h, w = nm()

coins = []
log = []

for i in range(h):
    a = nl()
    coins.append(a)


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

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

print(len(log))
for l in log:
    print(' '.join(map(str, [l[0][1], l[0][0], l[1][1], l[1][0]])))

Solution (Python):
h,w=map(int,input().split())
cnt=0
ans=[]
a=[list(map(int,input().split())) for _ in range(h)]
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])
            cnt+=1
for i in range(h-1):
    if a[i][w-1]%2:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
        cnt+=1
print(cnt)
for i in ans:
    print(*i)

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
r, c, dr, dc = 0, 0, 0, 1
ret = []
for i in range(h * w - 1):
    if not (0 <= r + dr < h and 0 <= c + dc < w and a[r + dr][c + dc] >= 0):
        dr, dc = dc, -dr
    if a[r][c] % 2 != 0:
        ret.append((r, c, r + dr, c + dc))
        a[r + dr][c + dc] += 1
    a[r][c] = -1
    r, c = r + dr, c + dc
print(len(ret))
for r1, c1, r2, c2 in ret:
    print(r1 + 1, c1 + 1, r2 + 1, c2 + 1)

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
r, c, d, dr, dc = 0, 0, 0, 0, 1
ret = []
for i in range(h * w - 1):
    if not (0 <= r + dr < h and 0 <= c + dc < w and a[r + dr][c + dc] >= 0):
        d = (d + 1) % 4
    dr, dc = [(0, 1), (1, 0), (0, -1), (-1, 0)][d]
    if a[r][c] % 2 != 0:
        ret.append((r, c, r + dr, c + dc))
        a[r + dr][c + dc] += 1
    a[r][c] = -1
    r, c = r + dr, c + dc
print(len(ret))
for r1, c1, r2, c2 in ret:
    print(r1 + 1, c1 + 1, r2 + 1, c2 + 1)

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][W-1] % 2 == 1:
    A[i][W-1] -= 1
    A[i+1][W-1] += 1
    ans.append([i+1,W,i+2,W])
print(len(ans))
for a in ans:
  print(*a)

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

ans = []  
seeds = []
for i in range(H):  
    for j in range(W):  
        if xs[i][j] % 2 != 0:
            seeds.append((i, j))
used = {}
def f(st, ed):
    res = []
    while(st != ed):
        old = st
        if (st[0] % 2 == 0):
            if st[1] < W - 1:
                st = (st[0], st[1] + 1)
            else:
                st = (st[0]+1, st[1])
        else:
            if st[1] > 0:
                st = (st[0], st[1] - 1)
            else:
                st = (st[0]+1, st[1])
        res.append('%d %d %d %d' % (old[0]+1, old[1]+1, st[0]+1, st[1]+1))
    return res

ans = []

seeds = sorted(seeds, key=lambda x:(x[0] * 9999999 + x[1] * (-1 if x[0]%2 == 1 else 1)))

for i in range(0, len(seeds)-1, 2):
    st = seeds[i]
    ed = seeds[i+1]
    ans += f(st, ed)
print(len(ans))
print('\n'.join(ans))

Solution (Python):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
r, c, d = 0, 0, 3
ret = []
for y in range(h * w - 1):
    if y % w == 0:
        d = (d + 1) % 4
    if y % w == w - 1:
        d = (d + 1) % 4
    dy, dx = [(0, 1), (1, 0), (0, -1), (1, 0)][d]
    if a[r][c] % 2 != 0:
        ret.append((r, c, r + dy, c + dx))
        a[r + dy][c + dx] += 1
    r, c = r + dy, c + dx
print(len(ret))
for r1, c1, r2, c2 in ret:
    print(r1 + 1, c1 + 1, r2 + 1, c2 + 1)

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

Solution (Python):
import numpy as np
H, W = map(int, input().split())
L = []
for i in range(H):
  L.append(list(map(int, input().split())))
C = np.array(L) % 2
A = []
for i in range(H):
  for j2 in range(W):
    if i % 2 == 1:
      j = W-1-j2
    else:
      j = j2
    if C[i][j] == 1:
      C[i][j] = 0
      if i % 2 == 0:
        if j == W-1:
          if i == H-1:break
          C[i+1][j] = not C[i+1][j]
          A.append([i, j, i+1, j])
        else:
          C[i][j+1] = not C[i][j+1]
          A.append([i, j, i, j+1])
      else:
        if j == 0:
          if i == H-1:break
          C[i+1][j] = not C[i+1][j]
          A.append([i, j, i+1, j])
        else:
          C[i][j-1] = not C[i][j-1]
          A.append([i, j, i, j-1])
print (len(A))
for i in range(len(A)):
  print (A[i][0]+1, A[i][1]+1, A[i][2]+1, A[i][3]+1)

Solution (Python):
def getlist():
	return list(map(int, input().split()))


H, W = getlist()
L = []
for i in range(H):
	l = getlist()
	L.append(l)


N = 0
ans = []
for i in range(H):
	for j in range(W):
		if L[i][j] % 2 != 0:
			if j != W - 1:
				ans.append(" ".join(list(map(str, [i + 1, j + 1, i + 1, j + 2]))))
				L[i][j + 1] += 1
				N += 1
			elif i != H - 1:
				ans.append(" ".join(list(map(str, [i + 1, j + 1, i + 2, j + 1]))))
				L[i + 1][j] += 1
				N += 1
			else:
				pass

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

Solution (Python):
from collections import deque

H, W = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
visited = []
odd = False
o_cnt = 0
for i in range(H):
  for j in range(W):
    if grid[i][j]%2 == 1:
      o_cnt += 1

cnt = 0
h = w = 0
if o_cnt%2 == 1:
  o_cnt -= 1
for i in range(H):
  for j in range(W)[::-1 if i%2 == 1 else 1]:
    if cnt == o_cnt:
      break
    if odd:
      if grid[i][j]%2 == 1:
        cnt += 1
        odd = False
      visited.append((h+1, w+1, i+1, j+1))
      h, w = i, j
    elif grid[i][j]%2 == 1:
      cnt += 1
      odd = True
      h, w = i, j
print(len(visited))
for v in visited:
  print(' '.join(map(str, v)))

Solution (Python):

import copy
y,x = list(map(int, input().split()))
Z = [list(map(int, input().split())) for _ in range(y)]

way = 1
a, b = 0, 0
ans = []
count = 0
while a < y and b < x:
    now = Z[a][b]
    a_copy= copy.deepcopy(a)
    b_copy = copy.deepcopy(b)

    if (way == 1 and a < y-1) or (way == -1 and a > 0):
        a += way
    else:
        b += 1
        way = way*(-1)
    if not (a < y and b < x):
        break
    if now % 2 == 1:
        Z[a][b] += 1
        ans.append([a_copy, b_copy, a, b])
        count += 1

print(count)
for i in ans:
    k = [j+1 for j in i]
    print(" ".join(list(map(str, k))))

Solution (Python):
def solve():
	t,*a=open(0)
	h,w=map(int,t.split())
	a=[[int(x)%2 for x in y.split()] for y in a]
	ret=[]
	for i in range(h):
		for j in range(w-1):
			if a[i][j]:
				a[i][j+1]^=1
				ret+=[" ".join(map(str,[i+1,j+1,i+1,j+2]))]
	for i in range(h-1):
		if a[i][-1]:
			a[i+1][-1]^=1
			ret+=[" ".join(map(str,[i+1,w,i+2,w]))]
	print(len(ret),*ret,sep="\n")
	
if __name__=="__main__":
	solve()

Solution (Python):
def solve():
	t,*a=open(0)
	h,w=map(int,t.split())
	a=[[int(x)%2 for x in y.split()] for y in a]
	ret=[]
	for i in range(h):
		for j in range(w-1):
			if a[i][j]:
				a[i][j+1]^=1
				ret+=[i+1,j+1,i+1,j+2]
	for i in range(h-1):
		if a[i][-1]:
			a[i+1][-1]^=1
			ret+=[i+1,w,i+2,w]
	print(len(ret)//4)
	for a,b,c,d in zip(*[iter(ret)]*4):
		print(a,b,c,d)
	
if __name__=="__main__":
	solve()

Solution (Python):
t,*a=open(0)
h,w=map(int,t.split())
a=[list(map(int,x.split())) for x in a]
ret=[]
for i in range(h):
	for j in range(w-1):
		if a[i][j]%2:
			a[i][j+1]+=1
			ret+=[" ".join(map(str,[i+1,j+1,i+1,j+2]))]
for i in range(h-1):
	if a[i][-1]%2:
		a[i+1][-1]+=1
		ret+=[" ".join(map(str,[i+1,w,i+2,w]))]
print(len(ret),*ret,sep="\n")

Solution (Python):
t,*a=open(0)
h,w=map(int,t.split())
a=[list(map(int,x.split())) for x in a]
ret=[]
for i in range(h):
	for j in range(w-1):
		if a[i][j]%2:
			a[i][j+1]+=1
			ret+=[(i+1,j+1,i+1,j+2)]
for i in range(h-1):
	if a[i][-1]%2:
		a[i+1][-1]+=1
		ret+=[(i+1,w,i+2,w)]
print(len(ret))
for a,b,c,d in ret:
	print(a,b,c,d)

Solution (Python):
import numpy as np
H, W = map(int, input().split())
L = []
A = []
for i in range(H):
    a = np.array([j%2 for j in list(map(int, input().split()))])
    aindex = np.where(a==1)
    for j in range(sum(a)//2):
        x1 = aindex[0][2*j]
        x2 = aindex[0][2*j+1]
        for k in range(x1,x2):
            A.append([i+1, k+1, i+1, k+2])
    if sum(a)%2==1:
        L.append(i)
        
        for m in range(aindex[0][-1],W-1):
            A.append([i+1, m+1, i+1, m+2])

for s in range(len(L)//2):
    y1 = L[2*s]
    y2 = L[2*s+1]
    for t in range(y1,y2):
        A.append([t+1, W, t+2, W])
print(len(A))
for a in A:
    print(" ".join(str(b) for b in a))