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)]

res = []
for i in range(h):
    if i % 2 == 0:
        
        for j in range(w):
            if i == h - 1 and j == w - 1:
                break
            if a[i][j] % 2 == 1:
                if j != w - 1:
                    res.append([i + 1, j + 1, i + 1, j + 1 + 1])
                    a[i][j + 1] += 1
                else:
                    res.append([i + 1, j + 1, i + 1 + 1, j + 1])
                    a[i + 1][j] += 1
                a[i][j] -= 1
            pass
    else:
        
        for j in range(w - 1, -1, -1):
            if i == h - 1 and j == 0:
                break
            if a[i][j] % 2 == 1:
                if j != 0:
                    res.append([i + 1, j + 1, i + 1, j - 1 + 1])
                    a[i][j - 1] += 1
                else:
                    res.append([i + 1, j + 1, i + 1 + 1, j + 1])
                    a[i + 1][j] += 1
                a[i][j] -= 1
            pass

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

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

ops = []
for r in range(H):
    pair_list = []
    pair_left = None
    for c in range(W):
        if A[r][c]==1:
            if pair_left!=None: pair_list.append((pair_left, c))
            pair_left = None if pair_left!=None else c

    if pair_left!=None and r!=H-1:
        ops.append((r+1, pair_left+1, r+2, pair_left+1))
        A[r+1][pair_left] += 1
        A[r+1][pair_left] %= 2
      	
    for pair_left, pair_right in pair_list:
        for c_ in range(pair_left, pair_right):
            ops.append((r+1, c_+1, r+1, c_+2))

print(len(ops))
for op in ops:
    print(*op)

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

if H == 1 and W == 1 :
    print(0)
else :
    coins = [[0 for _ in range(W)] for _ in range(H)]
    minCoin = [-1, -1, 10]

    for h in range(H) :
        A = list(map(int, input().split()))
        for w in range(W) :
            coins[h][w] = A[w]
            if A[w] < minCoin[2] :
                minCoin = [h, w, A[w]]

    ans = []

    
    for h in range(0, minCoin[0]) :
        for w in range(W) :
            if coins[h][w] % 2 == 1 :
                coins[h + 1][w] += 1
                ans.append([h, w, h+1, w])

    for h in range(H-1, minCoin[0], -1) :
        for w in range(W) :
            if coins[h][w] % 2 == 1 :
                coins[h - 1][w] += 1
                ans.append([h, w, h-1, w])

    for w in range(0, minCoin[1]) :
        if coins[minCoin[0]][w] % 2 == 1 :
            coins[minCoin[0]][w + 1] += 1
            ans.append([minCoin[0], w, minCoin[0], w+1])
    for w in range(W-1, minCoin[1], -1) :
        if coins[minCoin[0]][w] % 2 == 1 :
            coins[minCoin[0]][w - 1] += 1
            ans.append([minCoin[0], w, minCoin[0], w-1])

    if coins[minCoin[0]][minCoin[1]] % 2 == 1 :
        lastMoves = []
        if minCoin[0] > 0 :
            lastMoves.append([minCoin[0]-1, minCoin[1], coins[minCoin[0]-1][minCoin[1]]])
        if minCoin[0] < H - 1 :
            lastMoves.append([minCoin[0]+1, minCoin[1], coins[minCoin[0]+1][minCoin[1]]])
        if minCoin[1] > 0 :
            lastMoves.append([minCoin[0], minCoin[1]-1, coins[minCoin[0]][minCoin[1]-1]])
        if minCoin[1] < W - 1 :
            lastMoves.append([minCoin[0], minCoin[0]+1, coins[minCoin[0]][minCoin[1]+1]])
        lastMoves.sort(key=lambda A : A[2])
        toCoin = lastMoves[0]
        if toCoin[2] < coins[minCoin[0]][minCoin[1]] - 1 :
            ans.append([minCoin[0], minCoin[1]] + toCoin[0:2])

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

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

grid = [0] * H
for h in range(H):
    grid[h] = [int(_) for _ in input().split()]

cnt = 0
ans_lis = []
for h in range(H):
    for w in range(W):
        if grid[h][w] % 2:
            if h == H - 1:
                if w == W - 1:
                    break
                else:
                    cnt += 1
                    grid[h][w + 1] += 1
                    grid[h][w] -= 1
                    ans_lis.append((h + 1, w + 1, h + 1, w + 2))
            else:
                cnt += 1
                grid[h + 1][w] += 1
                grid[h][w] -= 1
                ans_lis.append((h + 1, w + 1, h + 2, w + 1))

print(cnt)
for item in ans_lis:
    print(' '.join(list(map(str, item))))

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

cnt = 0
X = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2:
            cnt += 1
            a[i][j] -= 1
            if j == W-1:
                if i == H-1:
                    cnt -= 1
                    break
                a[i+1][j] += 1
                X.append([i+1, j+1, i+2, j+1])
            else:
                a[i][j+1] += 1
                X.append([i+1, j+1, i+1, j+2])

print(cnt)    
for i in range(cnt):
    print(*X[i])

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

cnt = 0
X = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2:
            cnt += 1
            a[i][j] -= 1
            if j == W-1:
                if i == H-1:
                    cnt -= 1
                    break
                a[i+1][j] += 1
                X.append([i+1, j+1, i+2, j+1])
            else:
                a[i][j+1] += 1
                X.append([i+1, j+1, i+1, j+2])

print(cnt)    
for i in range(cnt):
    print(*X[i])

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

cnt = 0
X = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2:
            cnt += 1
            a[i][j] -= 1
            if j == W-1:
                if i == H-1:
                    cnt -= 1
                    break
                a[i+1][j] += 1
                X.append([i+1, j+1, i+2, j+1])
            else:
                a[i][j+1] += 1
                X.append([i+1, j+1, i+1, j+2])

print(cnt)    
for i in range(cnt):
    print(*X[i])

Solution (Python):



import sys

input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    a = [[int(e) for e in l.split()] for l in sys.stdin]

    n = 0
    out = []
    m = {}

    for i in range(H):
        for j in range(W):
            if a[i][j] % 2 == 0:
                continue

            
            if j+1 < W and a[i][j+1] % 2 == 1:
                a[i][j+1] += 1
                a[i][j] -= 1
                out.append(get_pos(i, j, i, j+1))
                n += 1
                m[(i+1)*500+(j+1)] = True
            
            elif i+1 < H and a[i+1][j] % 2== 1:
                a[i+1][j] += 1
                a[i][j] -= 1
                out.append(get_pos(i, j, i+1, j))
                n += 1
                m[(i+1)*500+(j+1)] = True
            
            elif i+1 < H:
                a[i+1][j] += 1
                a[i][j] -= 1
                out.append(get_pos(i, j, i+1, j))
                n += 1
                m[(i+1)*500+(j+1)] = True
            
            elif j+1 < W:
                a[i][j+1] += 1
                a[i][j] -= 1
                out.append(get_pos(i, j, i, j+1))
                n += 1
                m[(i+1)*500+(j+1)] = True

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

    
    
    
    

def get_pos(i, j, i2, j2):
    return "{} {} {} {}".format(i+1, j+1, i2+1, j2+1)

main()

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

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

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

for r in range(H - 1):
    if a[r][W - 1] % 2 == 1:
        a[r + 1][W - 1] += 1
        ans.append((r, W - 1, r + 1, W - 1))
print(len(ans))
for aa in ans:
    print(*map(lambda x: x + 1, aa))

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

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

ans_array = []

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

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

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

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

for i in range(h):
    for j in range(w):
        if i==0 and j==0:
            continue
        if j==w-1:
            if i!=h-1:
                if a[i][j]%2==1:
                    ans.append([i+1,j+1,i+2,j+1])
                    a[i+1][j]+=1
        else:
            if a[i][j]%2==1:
                ans.append([i+1,j+1,i+1,j+2])
                a[i][j+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=[]
s=0
for i in range(h):
    p=[int(j) for j in input().split()]
    a.append(p)
    s+=sum(p)
ans=[]
if s%2==0:
    if a[0][0]%2==1:
        if w!=1:
            ans.append([1,1,1,2])
            a[0][1]+=1
        elif h!=1:
            ans.append([1,1,2,1])
            a[1][0]+=1
else:
    if a[0][0]%2==0:
        if w!=1:
            ans.append([1,1,1,2])
            a[0][1]+=1
        elif h!=1:
            ans.append([1,1,2,1])
            a[1][0]+=1

for i in range(h):
    for j in range(w):
        if i==0 and j==0:
            continue
        if j==w-1:
            if i!=h-1:
                if a[i][j]%2==1:
                    ans.append([i+1,j+1,i+2,j+1])
                    a[i+1][j]+=1
        else:
            if a[i][j]%2==1:
                ans.append([i+1,j+1,i+1,j+2])
                a[i][j+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(int, input().split())) for _ in range(H)]

def count_coin(p):
	return A[p[0]][p[1]]

result = []
def move_coin(f, t):
	global result
	A[f[0]][f[1]] -= 1
	A[t[0]][t[1]] += 1
	result += ["{:d} {:d} {:d} {:d}".format(f[0] + 1, f[1] + 1, t[0] + 1, t[1] + 1)]

for y in range(H):
	for x in range(W):
		if 0 == count_coin((y, x)) % 2:
			continue
		if x == W - 1:
			if y == H - 1:
				
				break
			else:
				
				move_coin((y, x), (y + 1, x))
		else:
			
			move_coin((y, x), (y, x + 1))

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

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

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

def check(i, j):
    if dp[i][j] % 2 == 0:
        return True
    else:
        return False

flag = True 
h = 0 
w = 0 
ans = [] 
count = 0 
for i in range(H*W): 
    
    
    if check(h, w): 
        if flag == True and w == W - 1:
            flag = not flag
            h += 1
        elif flag == False and w == 0:
            flag = not flag
            h += 1
        elif flag == True:
            w += 1
        elif flag == False:
            w -= 1
        continue
    else: 
        if i == (H*W-1): 
        
            continue
        else:
            count += 1
            if flag: 
                if w == W - 1: 
                    
                    dp[h][w] -= 1
                    dp[h + 1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag 
                    h += 1 
                else: 
                    dp[h][w] -= 1
                    dp[h][w + 1] += 1
                    ans += [[h+1, w+1, h+1, w+2]]
                    w += 1
            else: 
                if w == 0: 
                    
                    dp[h][w] -= 1
                    dp[h+1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag
                    h += 1
                else: 
                    dp[h][w] -= 1
                    dp[h][w - 1] += 1
                    ans += [[h+1, w+1, h+1, w]]
                    w -= 1






print (count) 
for i in ans: 
    print (i[0], i[1], i[2], i[3])

Solution (Python):
import numpy as np
H, W = map(int, input().split())

lst = [list(map(int, input().split())) for _ in range(H)]
dp = np.array(lst)


def check(i, j):
    if dp[i][j] % 2 == 0:
        return True
    else:
        return False

flag = True 
h = 0 
w = 0 
ans = [] 
count = 0 
for i in range(H*W): 
    
    
    if check(h, w): 
        if flag == True and w == W - 1:
            flag = not flag
            h += 1
        elif flag == False and w == 0:
            flag = not flag
            h += 1
        elif flag == True:
            w += 1
        elif flag == False:
            w -= 1
        continue
    else: 
        if i == (H*W-1): 
        
            continue
        else:
            count += 1
            if flag: 
                if w == W - 1: 
                    
                    dp[h][w] -= 1
                    dp[h + 1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag 
                    h += 1 
                else: 
                    dp[h][w] -= 1
                    dp[h][w + 1] += 1
                    ans += [[h+1, w+1, h+1, w+2]]
                    w += 1
            else: 
                if w == 0: 
                    
                    dp[h][w] -= 1
                    dp[h+1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag
                    h += 1
                else: 
                    dp[h][w] -= 1
                    dp[h][w - 1] += 1
                    ans += [[h+1, w+1, h+1, w]]
                    w -= 1






print (count) 
for i in ans: 
    print (i[0], i[1], i[2], i[3])

Solution (Python):
H,W = [int(x) for x in input().split()]
li = []
op = []
def get_wh(index):
    h = index//W
    if(h%2==0):
        w = index%W +1
    else:
        w = W - index%W
    return h+1,w

for i in range(H):
    if(i%2 == 0):
        li+=[int(x)%2 for x in input().split()]
    else:
        li+=[int(x)%2 for x in input().split()][::-1]

for index in range(len(li[:-1])):
    if(li[index]==1):
        li[index]=0
        li[index+1]=1-li[index+1]
        op.append(get_wh(index)+get_wh(index+1))

print(len(op))
for i in op:
    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)]

arr = []
for i in range(H-1):
    for j in range(W):
        if A[i][j]%2!=0:
            A[i+1][j]+=1
            arr.append([i+1, j+1, i+2, j+1])
            
for k in range(W-1):
    if A[H-1][k]%2!=0:
        A[H-1][k+1]+=1
        arr.append([H, k+1, H, k+2])
        
N = len(arr)

print(N)

for i in range(N): 
    print(arr[i][0], arr[i][1], arr[i][2], arr[i][3])

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

s = []
for i in range(H):
  for j in range(W-1):
    if M[i][j] & 1:
      s.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
      M[i][j+1] += 1
for i in range(H-1):
  if M[i][W-1] & 1:
    s.append("{} {} {} {}".format(i+1, W, i+2, W))
    M[i+1][W-1] += 1
print(len(s))
print("\n".join(s))

Solution (Python):


H,W = map(int, input().split())
relation = []
for i in range(H):              
    if i % 2 == 0:
        relation.extend((i, j) for j in range(W))
    else:
        relation.extend((i, j) for j in range(W - 1, -1, -1))
field = [list(map(int, input().split())) for _ in range(H)]
 
buf = []
for (i1, j1), (i2, j2) in zip(relation, relation[1:]):
    if field[i1][j1] % 2 == 1:
        field[i1][j1] -= 1
        field[i2][j2] += 1
        buf.append((i1 + 1, j1 + 1, i2 + 1, j2 + 1))
 
print(len(buf))
print('\n'.join(' '.join(map(str, line)) for line in buf))

Solution (Python):
def movement(inpair1,inpair2):
    outlist = [(inpair1)]
    if inpair1[1] < inpair2[1]:
        for i in range(inpair1[1]+1,inpair2[1]+1):
            outlist.append((inpair1[0],i))
            t = i
    elif inpair1[1] > inpair2[1]:
        for i in range(inpair1[1]-1,inpair2[1]-1,-1):
            outlist.append((inpair1[0],i))
            t = i
    else:
        t = inpair1[1]
    for j in range(inpair1[0]+1,inpair2[0]+1):
        outlist.append((j,t))
    outlist = [ ( outlist[i][0], outlist[i][1], outlist[i+1][0], outlist[i+1][1] ) for i in range(len(outlist)-1)]

    return outlist


h, w = [ int(v) for v in input().split() ]
odd_list = []
odd_list_2 = []
odd_list_3 = []
for i in range(h):
    line = [ int(v)%2 for v in input().split() ]
    if line.count(1) >= 1:
        temp_list = []
        for j in range(w):
            
            if line[j] % 2 == 1:
                temp_list.append((i,j))
        odd_list_2.append(temp_list)
        odd_list.append([[i,0],[i,w-1]])


for i in range(len(odd_list)):
    if i % 2 == 1:
        odd_list[i] = list(reversed(odd_list[i]))
        odd_list_2[i] = list(reversed(odd_list_2[i]))
    odd_list_3 += odd_list_2[i]
odd_list_3.append((h,w))


total_move_list = []
for i in range(len(odd_list)):
    total_move_list += movement(odd_list[i][0],odd_list[i][1])
    if i != len(odd_list) - 1:
        total_move_list += movement(odd_list[i][1],odd_list[i+1][0])
    

rec = -1
z = 0
x, y = odd_list_3[0]
anslist = []
for i in total_move_list:
    if i[0] == x and i[1] == y:
        rec *= -1
        z += 1
        x, y = odd_list_3[z]
    if rec == 1:
        anslist.append(i)


print(len(anslist))
for i in anslist:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

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

for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 0:
            continue
        else:
            if j != W - 1:
                a[i][j] -= 1
                a[i][j + 1] += 1
                move.append((i + 1, j + 1, i + 1, j + 2))
                cnt += 1
            else:
                if i != H - 1:
                    a[i][j] -= 1
                    a[i + 1][j] += 1
                    move.append((i + 1, j + 1, i + 2, j + 1))
                    cnt += 1

print(cnt)
for i in move:
    print(*i)

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

Solution (Python):
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
move=[]
cnt=0
for i in range(n):
  for j in range(m):
    if arr[i][j]%2==0:
      continue
    else:
      if j!=m-1:
        arr[i][j]-=1
        arr[i][j+1]+=1
        move.append([i+1,j+1,i+1,j+1+1])
        cnt+=1
      else:
        if i!=n-1:
          arr[i][j]-=1
          arr[i+1][j]+=1
          move.append([i+1,j+1,i+1+1,j+1])
          cnt+=1
print(cnt)
for i1,j1,i2,j2 in move:
  print(i1,j1,i2,j2)

Solution (Python):
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
x, y = 0, 0
count = 1
ops = []
while True:
    if count == H * W:
        break
    if x % 2 == 0:
        if y == W - 1:
            nx, ny = x + 1, y
        else:
            nx, ny = x, y + 1
    else:
        if y == 0:
            nx, ny = x + 1, y
        else:
            nx, ny = x, y - 1
    if a[x][y] % 2 == 1:
        a[x][y] -= 1
        a[nx][ny] += 1
        ops.append((x + 1, y + 1, nx + 1, ny + 1)) 
    x, y = nx, ny
    count += 1
print(len(ops))
for op in ops:
    print(*op)

Solution (Python):



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

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

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

    n = len(operations)
    print(n)

    for i in range(n):
        y, x, y_dash, x_dash = operations[i]
        print(y, x, y_dash, x_dash)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    operations = list()
    row = 0
    prev_x, prev_y = 0, 0
    odd_count = 0

    while row < h:
        if row % 2 == 0:
            for col in range(w):
                if a[row][col] % 2 == 1:
                    if odd_count == 0:
                        prev_x, prev_y = col + 1, row + 1
                        odd_count = 1
                    else:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
                        odd_count = 0
                else:
                    if odd_count == 1:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
        else:
            for col in range(w - 1, -1, -1):
                if a[row][col] % 2 == 1:
                    if odd_count == 0:
                        prev_x, prev_y = col + 1, row + 1
                        odd_count = 1
                    else:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
                        odd_count = 0
                else:
                    if odd_count == 1:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y

        row += 1

    n = len(operations)
    print(n)

    for i in range(n):
        y, x, y_dash, x_dash = operations[i]
        print(y, x, y_dash, x_dash)


if __name__ == '__main__':
    main()

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

list_=[]
cnt=0
for i in range(H):
    if i%2==0:
        for j in range(W):
            if j!=W-1:
                if a[i][j]%2==1:
                    a[i][j]-=1
                    a[i][j+1]+=1
                    list_.append([i+1,j+1,i+1,j+2])
            else:
                if a[i][j]%2==1 and i!=H-1:
                    a[i][j]-=1
                    a[i+1][j]+=1
                    list_.append([i+1,j+1,i+2,j+1])
    else:
        for j in range(W-1,-1,-1):
            if j!=0:
                if a[i][j]%2==1:
                    a[i][j]-=1
                    a[i][j-1]+=1
                    list_.append([i+1,j+1,i+1,j])
            else:
                if a[i][j]%2==1 and i!=H-1:
                    a[i][j]-=1
                    a[i+1][j]+=1
                    list_.append([i+1,j+1,i+2,j+1])
N=len(list_)
print(N)
for l in list_:
    print(" ".join(map(str,l)))

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

output = []

for i in range(H-1):
    for j in range(W-1):
        if a[i][j]%2==1:
            a[i][j+1] += 1
            output.append([i+1,j+1,i+1,j+2])
    if a[i][W-1]%2==1:
        a[i+1][W-1]+=1
        output.append([i+1,W,i+2,W])
for j in range(W-1):
        if a[H-1][j]%2==1:
            a[H-1][j+1] += 1
            output.append([H,j+1,H,j+2])
            
print(len(output))
for x in output:
    print(*x)

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

n = 0
ans = []
next = 0
for y in range(h):
    line = list(map(int, input().split()))
    if next:
        line[-1] += 1
    for x in range(w - 1):
        if line[x] % 2 == 1:
            line[x + 1] += 1
            n += 1
            ans.append([y + 1, x + 1, y + 1, x + 2])
    if y == h - 1:
        break
    if line[-1] % 2 == 1:
        next = 1
        n += 1
        ans.append([y + 1, w, y + 2, w])
    else:
        next = 0

print(n)
for line in ans:
    print(*line)

Solution (Python):
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    h, w, *a = map(int, s.split())
    a = [[False if __a % 2 == 0 else True for __a in _a] for _a in chunked(a, w)]
    ans = []
    for i in range(h):
        for j in range(w - 1):
            if a[i][j]:
                ans.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                a[i][j + 1] = not a[i][j + 1]
    for i in range(h - 1):
        if a[i][w - 1]:
            ans.append("{} {} {} {}".format(i + 1, w, i + 2, w))
            a[i + 1][w - 1] = not a[i + 1][w - 1]
    return "%d\n" % len(ans) + "\n".join(ans)


n, m = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

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

ans = []
for y in range(H-1):
    for x in range(W):
        if a[y][x]%2 == 1:
            ans.append('{} {} {} {}'.format(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 == 1:
        ans.append('{} {} {} {}'.format(H,x+1,H,x+2))
        a[H-1][x+1] += 1

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

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

ct=0
ans=[]

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

print(ct)
for i in range(ct):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])

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

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

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