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 = [int(_) for _ in input().split(' ')]
a = []
for _ in range(h):
    a.append([int(_) for _ in input().split(' ')])

if h * w > 1:
    m = False
    ops = []
    for j in range(h):
        for k in range(w):
            if j < h - 1 or k < w - 1:
                if j % 2 == 0:
                    i = k
                else:
                    i = w - 1 - k

                if a[j][i] % 2 == 1:
                    m = m ^ True
                if m:
                    if k < w - 1:
                        if j % 2 == 0:
                            op = '{0} {1} {2} {3}'.format(j + 1, i + 1, j + 1, i + 2)
                        else:
                            op = '{0} {1} {2} {3}'.format(j + 1, i + 1, j + 1, i)
                    else:
                        op = '{0} {1} {2} {3}'.format(j + 1, i + 1, j + 2, i + 1)
                    ops.append(op)

    print(len(ops))
    for op in ops:
        print(op)
else:
    print(0)

Solution (Python):
H,W=[int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(H)]
res = []
for h in range(H):
    for w in range(W-1):
        if a[h][w] % 2 is not 0:
            res += ["{0} {1} {2} {3}".format(h+1,w+1,h+1,w+2)]
            a[h][w+1] += 1
for h in range(H-1):
    w = W - 1
    if a[h][w] % 2 is not 0:
        res += ["{0} {1} {2} {3}".format(h+1,w+1,h+2,w+1)]
        a[h+1][w]+=1

print(len(res))
for t in res:
    print(t)

Solution (Python):
def isEven(n):
    return n%2==0
moves = []
h, w = map(int, input().split())
cells = [[-2 for i in range(w+2)]]
evens = 0
totalSum = 0
for i in range(h):
    r = list(map(int, input().split()))
    row = [-2]
    for c in r:
        row.append(c)
        totalSum += c
        if isEven(c):
            evens += 1
    row.append(-2)
    cells.append(row)
cells.append([-2 for i in range(w+2)])

for hc in range(1, h+1):
    for wc in range(1, w+1):
        if not isEven(cells[hc][wc]):
            if not isEven(cells[hc][wc+1]):
                cells[hc][wc] -= 1
                cells[hc][wc+1] += 1
                moves.append([hc, wc, hc, wc+1])
            elif not isEven(cells[hc+1][wc]):
                cells[hc][wc] -= 1
                cells[hc+1][wc] += 1
                moves.append([hc, wc, hc+1, wc])
            else:
                if cells[hc][wc+1] >= 0:
                    cells[hc][wc] -= 1
                    cells[hc][wc+1] += 1
                    moves.append([hc, wc, hc, wc+1])
                elif cells[hc+1][wc] >= 0:
                    cells[hc][wc] -= 1
                    cells[hc+1][wc] += 1
                    moves.append([hc, wc, hc+1, wc])

print(len(moves))
for m in moves:
    print(" ".join(map(str, m)))

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

for i in range(h):
    a.append([int(i) for i in input().split()])
  
for i in range(h):  
    for j in range(w):  
        if a[i][j] % 2 != 0:
            if j != w - 1:
              a[i][j] -= 1
              a[i][j + 1] += 1            
              answer.append([i+1, j+1, i+1, j+2])
            elif i != h - 1:
                  a[i][j] -= 1
                  a[i+1][j] += 1  
                  answer.append([i+1, j+1, i+2, j+1])
    
print(len(answer))
for i in range(len(answer)):
    print(" ".join(map(str, answer[i])))

Solution (Python):


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


ops = []


oddrow = []
for r, row in enumerate(A):
    
    odd = [i for i in range(len(row)) if row[i] % 2 > 0]
    odd.reverse()
    
    while len(odd) > 1:
        f, t = odd[:2]
        for i in range(f, t, -1):
            ops.append((r, i, r, i-1))
        odd = odd[2:]
    
    if len(odd) > 0:
        for i in range(odd[0], 0, -1):
            ops.append((r, i, r, i-1))
        oddrow.append(r)


while len(oddrow) > 1:
    f, t = oddrow[:2]
    for i in range(f, t):
        ops.append((i, 0, i+1, 0))
    oddrow = oddrow[2:]


print(len(ops))
for op in ops:
    print(' '.join([str(x+1) for x in op]))

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

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

O=[]
for i in range(H):
    for j in range(W):
        if A[i][j]%2!=0:
            A[i][j]-=1
            if j!=W-1:
                ai=i
                aj=j+1
            elif i!=H-1:
                ai=i+1
                aj=j
            else:
                break
            A[ai][aj]+=1
            O.append("{} {} {} {}".format(i+1,j+1,ai+1,aj+1))
        
print(len(O))
for i in range(len(O)):
    print(O[i])

Solution (Python):
from sys import stdin, stdout

input = lambda: stdin.readline()


def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in [0] * H]

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

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

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

main()

Solution (Python):
f = lambda: map(int,input().split())
h,w = f()
a = [list(f()) for _ in range(h)]
for i in range(h):
    if i%2 == 0:
        a[i].reverse()

count = 0
ans = []

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

Solution (Python):

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

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

ope = 0
ope_list = []
for i in range(H):
    for j in range(W):
        if aij[i][j] > 0 and aij[i][j] % 2 == 1:
            if j+1 < W : 
                aij[i][j] -= 1
                aij[i][j+1] += 1
                ope += 1
                ope_list.append((i,j,i,j+1))
            elif i+1 < H :
                aij[i][j] -= 1
                aij[i+1][j] += 1
                ope += 1
                ope_list.append((i,j,i+1,j))


print(ope)
for ol in ope_list:
    print(ol[0]+1,ol[1]+1,ol[2]+1,ol[3]+1)

Solution (Python):
H, W = map(int, input().split())
N = 0
coins = []
ans = []

for i in range(H):
  coin = list(map(int, input().split()))
  coins.append(coin)

for i in range(H):
    for j in range(W-1):
      if coins[i][j] % 2 == 1:
        N += 1
        coins[i][j] -= 1
        coins[i][j+1] += 1
        ans.append([i,j,i,j+1])
        
for i in range(H-1):
  if coins[i][W-1] % 2 == 1:
    N += 1
    coins[i][W-1] -= 1
    coins[i+1][W-1] += 1
    ans.append([i, W-1, i+1, W-1])
    
print(N)
for i in range(N):
    print(ans[i][0]+1,ans[i][1]+1, ans[i][2]+1,ans[i][3]+1)

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

N = 0
t = []

for i in range(H-1):
    for j in range(W):
        if a[i][j]% 2 == 1:
            if j < W-1 and a[i][j+1]%2 == 1:
                a[i][j] -= 1
                a[i][j+1] += 1
                N +=1
                t.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            else:
                a[i][j] -= 1
                a[i+1][j] += 1
                N +=1
                t.append(str(i+1)+" "+str(j+1)+" "+str(i+2)+" "+str(j+1))

for j in range(W):
    if a[H-1][j]%2==1 and j < W-1:
        N +=1
        t.append(str(H)+" "+str(j+1)+" "+str(H)+" "+str(j+2))
        a[H-1][j] -= 1
        a[H-1][j+1] += 1

print(N)
for i in range(N):
    print(t[i])

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

ans=0
next_num=0
print_list=[]

for j in range(H):
    
    y=j+1
    getrow = list(map(int,input().split()))
    row = [i%2 for i in getrow]
    if next_num: row[next_num-1]=int(row[next_num-1]==0)
    
    index1=[]
    for i in range(W):
        if row[i]==1: index1.append(i+1)
        
    while True:
        
        if len(index1)==0:
            next_num=0
            break
        
        elif len(index1)==1:
            if y != H:
                next_num=index1[0]
                print_list.append([y,next_num,y+1,next_num])
                ans += 1
            break
            
        else:
            a=index1[0]
            b=index1[1]
            for t in range(a,b):
                print_list.append([y,t,y,t+1])
                ans += 1
            del index1[1]
            del index1[0]
        
print(ans)
for r in print_list:
    print(r[0],r[1],r[2],r[3])

Solution (Python):


from collections import namedtuple

Move = namedtuple('Move', ['fx', 'fy', 'tx', 'ty'])

def make_then_even(cells):
    moves = []
    for i, row in enumerate(cells):
        for j in range(len(row) - 1):
            if row[j] % 2:
                row[j] -= 1
                row[j+1] += 1
                moves.append(Move(i+1, j+1, i+1, j+2))

    w = len(cells[0])
    for i in range(len(cells) - 1):
        if cells[i][-1] % 2:
            cells[i][-1] -= 1
            cells[i+1][-1] += 1
            moves.append(Move(i+1, w, i+2, w))
    return moves

def main():
    h, w = [int(s) for s in input().split()]
    cells = []
    for _ in range(h):
        row = [int(s) for s in input().split()]
        cells.append(row)
    moves = make_then_even(cells)
    print(len(moves))
    for move in moves:
        print(move.fx, move.fy, move.tx, move.ty)

main()

Solution (Python):
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    coin_map = [[0 for i in range(W)] for j in range(H)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            coin_map[i][j] = int(input_raw[j])

    is_done = [[False for i in range(W)] for j in range(H)]
    count= 0
    next_point = (0, 0)
    ope_list = []
    move_list = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    is_next_exist = True
    while is_next_exist == True:
        is_next_exist = False
        y = next_point[0]
        x = next_point[1]
        is_done[y][x] = True
        for move in move_list:
            new_y = y + move[0]
            new_x = x + move[1]
            if y>= 0 and new_y < H and new_x >= 0 and new_x < W and is_done[new_y][new_x] == False:
                next_point = (new_y, new_x)
                is_next_exist = True
                break
        if is_next_exist == False:
            break
        if coin_map[y][x] > 0 and coin_map[y][x] % 2 == 1:
            coin_map[y][x] -= 1
            coin_map[new_y][new_x] += 1
            ope_list.append((y + 1, x + 1, new_y + 1, new_x + 1))
            count += 1
    print len(ope_list)
    for ope in ope_list:
        print ope[0], ope[1], ope[2], ope[3]

if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(list(map(int, input().split())))
cnt = 0
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
            a[i][j + 1] += 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 i in ans:
    print(i[0], i[1], i[2], i[3])

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

for i in range(H):
    a[i] = [int(x) for x in input().split()]

x1 = []
y1 = []
x2 = []
y2 = []


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

        else:
            a[i][j] -= 1
            a[i][j+1] += 1
            x1.append(i)
            y1.append(j)
            x2.append(i)
            y2.append(j+1)

        
        
        
        
        
        
        

        
        
        
        
        
        
        

    if a[i][W-1] % 2 == 0:
        continue

    else:
        a[i][W-1] -= 1
        a[i+1][W-1] += 1
        x1.append(i)
        y1.append(W-1)
        x2.append(i+1)
        y2.append(W-1)

for j in range(W-1):
    if a[H-1][j] % 2 != 0:
        a[H-1][j] -= 1
        a[H-1][j+1] += 1
        x1.append(H-1)
        y1.append(j)
        x2.append(H-1)
        y2.append(j+1)


    

print(len(x1))

y1 = [i+1 for i in y1]
x1 = [i+1 for i in x1]
y2 = [i+1 for i in y2]
x2 = [i+1 for i in x2]


for i in range(len(x1)):
    print(x1[i], y1[i], x2[i], y2[i])

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):
H, W = map(int, input().split())

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


def is_odd(i, j):
    return a[i][j] % 2 == 1


def next_cell(i, j):
    if i % 2 == 1:
        if j < W:
            return i, j + 1
    else:
        if 1 < j:
            return i, j - 1
    if i < H:
        return i + 1, j
    return None, None


def move(i, j):
    ni, nj = next_cell(i, j)
    if ni is None:
        return None
    a[i][j] -= 1
    a[ni][nj] += 1
    return "{} {} {} {}".format(i, j, ni, nj)


ans = []
i, j = 1, 1
while True:
    if is_odd(i, j):
        res = move(i, j)
        if res is not None:
            ans.append(res)
    i, j = next_cell(i, j)
    if i is None:
        break

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

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

a = []

for i in range(H):
    line = [int(i) for i in input().split()]
    a.append(line)
ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] % 2 == 1:
            ans.append(str(i+1) + ' '+ str(j+1)+' '+str(i+1) + ' '+str(j+2))
            a[i][j+1] += 1


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

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

    if i < h-1:
        if a[i][x[-1]]%2 == 1:
            a[i][x[-1]] -= 1
            a[i+1][x[-1]] += 1
            ans.append([i+1, x[-1]+1, i+1+1, x[-1]+1])

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

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

logs = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 0:
            continue
        flag = False
        if j != W - 1:
            if a[i][j+1] % 2 == 1:
                a[i][j+1] += 1
                flag = True
                logs.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
                continue
        if i != H - 1:
            if a[i+1][j] % 2 == 1:
                a[i+1][j] += 1
                flag = False
                logs.append("{} {} {} {}".format(i+1, j+1, i+2, j+1))
                continue
        if not flag:
            if j != W - 1:
                a[i][j+1] += 1
                logs.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
            elif i != H - 1:
                a[i+1][j] += 1
                logs.append("{} {} {} {}".format(i+1, j+1, i+2, j+1))
print(len(logs))
for log in logs:
    print(log)

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

a = [[0 for i in range(W + 1)] for j in range(H + 1)]

for i in range(H):
    atmp = list(map(int, input().split()))
    for j in range(W):
        a[i + 1][j + 1] = atmp[j]

count = 0
oplist = []

for i in range(1, H + 1):
    for j in range(1, W):
        if a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i][j + 1] += 1
            count += 1
            oplist.append(str(i) + ' ' + str(j) + ' '
                          + str(i) + ' ' + str(j + 1))

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

print(count)
for i in range(len(oplist)):
    print(oplist[i])

Solution (Python):
H,W=map(int,input().split())
H-=1
W-=1
p=[]
for i in range(H+1):
  p+=[list(map(int,input().split()))]
s=[]
se=[]
h=0
w=0
f=False
x=[]
while h != H+1:
  if p[h][w] % 2 == 1:
    if f == True:
      x += s
      s=[]
      f =  False
    else:
      f = True
      se = [h,w]
      
  if w != W:
    if f==True:
      s+=[[h+1,w+1,h+1,w+2]]
    w+=1
  else:
    if f==True and h != H:
      f=False
      p[se[0]+1][se[1]]+=1
      x+=[[se[0]+1,se[1]+1,se[0]+2,se[1]+1]]

    w=0
    h+=1
    s=[]

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

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

print(cnt)
for i,j,k,l in ans:
    print(i,j,k,l)

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):
    if i%2 == 0:
        for j in range(0,W,1):
            if a[i][j] % 2 == 1:
                if j == W-1:
                    if i == H-1:
                        break
                    else:
                        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
    else:
        for j in range(W-1,-1,-1):
            if a[i][j] %2 == 1:
                if j == 0:
                    if i == H-1:
                        break
                    else:
                        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)
                    a[i][j-1] += 1
if N == 0:
    print(N)
else:
    print(N)
    print(ans)

Solution (Python):
H, W = list(map(int, input().split()))
A = [[0 for j in range(W)] for i in range(H)]
count = 0
res = []
for i in range(H):
    A[i] = list(map(int, input().split()))
    for j in range(W-1):
        if A[i][j] % 2 != 0:
            A[i][j] -= 1
            A[i][j+1] += 1
            res.append([i+1,j+1,i+1,j+2])
            count += 1
for i in range(H-1):
    if A[i][W-1] % 2 != 0:
        A[i][W-1] -= 1
        A[i+1][W-1] += 1
        res.append([i+1,W,i+2,W])
        count += 1
print(count)
print("\n".join([" ".join(map(str, l)) for l in res]))

Solution (Python):
h, w = map(int, input().split())
ma = []
id = []
for i in range(h):
    ma.append(list(map(int, input().split())))
for i in range(h):
    for j in range(w):
        if ma[i][j] % 2 == 1:
            if i != h - 1 and ma[i + 1][j] % 2 == 1:
                ma[i + 1][j] += 1
                id.append([i+1, j+1, i + 2, j+1])
            elif j != w - 1 and ma[i][j+1] % 2 == 1:
                ma[i][j + 1] += 1
                id.append([i+1, j+1, i+1, j + 2])
            elif i != h - 1:
                ma[i + 1][j] += 1
                id.append([i+1, j+1, i + 2, j+1])
            elif j != w - 1:
                ma[i][j + 1] += 1
                id.append([i+1, j+1, i+1, j + 2])
print(len(id))
for i in range(len(id)):
    print(" ".join(map(str, id[i])))

Solution (Python):
h,w=map(int,input().split())
a=[]
for i in range(h):
    t=list(map(int,input().split()))
    a.append(t)
b=[]
def e(i,j):
    if i+1<h and a[i+1][j]%2==1:
        a[i][j]-=1
        a[i+1][j]+=1
        b.append([i+1,j+1,i+2,j+1])
        
    elif j+1<w and a[i][j+1]%2==1:
        a[i][j]-=1
        a[i][j+1]+=1
        b.append([i+1,j+1,i+1,j+2])
        
    elif i-1>=0 and a[i-1][j]%2==1:
        a[i][j]-=1
        a[i-1][j]+=1
        b.append([i+1,j+1,i,j+1])
        
    elif j-1>=0 and a[i][j-1]%2==1:
        a[i][j]-=1
        a[i][j-1]+=1
        b.append([i+1,j+1,i+1,j])
        
    elif i+1<h:
        a[i][j]-=1
        a[i+1][j]+=1
        b.append([i+1,j+1,i+2,j+1])
        
    elif j+1<w:
        a[i][j]-=1
        a[i][j+1]+=1
        b.append([i+1,j+1,i+1,j+2])
        
for i in range(h):
    for j in range(w):
        if a[i][j]%2==1:
            e(i,j)
print(len(b))
for i in range(len(b)):
    print(b[i][0],end=' ')
    print(b[i][1],end=' ')
    print(b[i][2],end=' ')
    print(b[i][3])

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

ans = []
dx = -1
w = 0

for h in range(H):
    dx *= -1
    for j in range(W):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            a = [h+1, w+1]
            if w + dx < 0 or w + dx >= W:
                if h + 1 == H:
                    break
                A[h+1][w] += 1
                a += [h+2, w+1]
            else:
                w += dx
                A[h][w] += 1
                a += [h+1, w+1]
            ans.append(a)
            
        elif 0 <= w + dx < W:
            w += dx
            
            
        

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

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

ans =[]

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

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

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

H,W=spaceinput()

a=[]
for i in range(H):
    a.append(spaceinput())


ress=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2!=0:
            a[i][j+1]+=1
            a[i][j]-=1
            res=' '.join(map(str,[i+1,j+1]))
            res+=" "
            res+=" ".join(map(str,[i+1,j+2]))
            ress.append(res)

for i in range(H-1):
    if a[i][-1]%2!=0:
        a[i+1][-1]+=1
        a[i][-1]-=1
        res=' '.join(map(str,[i+1,W]))
        res+=" "
        res+=" ".join(map(str,[i+2,W]))
        ress.append(res)

print(len(ress))
for sres in ress:
    print(sres)

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

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

ans_n = 0
ans_xy = []

for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1:
            if j < w-1:
                a[i][j] = 0
                a[i][j+1] += 1
                ans_n += 1
                ans_xy.append([i + 1, j + 1, i + 1, j + 2])

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

print(ans_n)
for k in range(ans_n):
    print(*ans_xy[k])

Solution (Python):

n,x = map(int, input().split())

c = 0
ans = []
H = []

for i in range(n):
    w = list(map(int, input().split()))
    for j in range(x-1):
        if w[j]%2>0:
            c+=1
            tmp = [str(i+1), str(j+1), str(i+1), str(j+2)]
            ans.append(tmp)
            w[j+1]+=1
    H.append(w[x-1])
    
for i in range(n-1):
    if H[i]%2>0:
        c+=1
        tmp = [str(i+1), str(x), str(i+2), str(x)]
        ans.append(tmp)
        H[i+1]+=1
           
print(c)
        
for i in range(c):
    print(' '.join(ans[i]))

Solution (Python):
H, W = map(int, input().split())
A = [[int(_) for _ in input().split()] for _ in range(H)]
N = 0
move = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 1 and j <= W-2:
            A[i][j+1] += 1
            N += 1
            move.append([i+1, j+1, i+1, j+2])
        elif A[i][j]%2 == 1 and j == W-1 and i!=H-1:
            A[i+1][j] += 1
            N += 1
            move.append([i+1, j+1, i+2, j+1])

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

Solution (Python):
def main():
    h, w = [int(s) for s in input().split()]
    a = []

    for _ in range(h):
        a.append([int(s) for s in input().split()])

    r = []
    for i1, j1, i2, j2 in route(h, w):
        if a[i1][j1] % 2 != 0:
            a[i1][j1] -= 1
            a[i2][j2] += 1
            r.append((i1, j1, i2, j2))

    print(len(r))
    for i1, j1, i2, j2 in r:
        print(i1 + 1, j1 + 1, i2 + 1, j2 + 1)


def route(h, w):
    i = 0
    j = 0

    for _ in range(h * w - 1):
        if i % 2 == 0:
            if j != w - 1:
                
                yield (i, j, i, j + 1)
                j += 1
            else:
                
                yield (i, j, i + 1, j)
                i += 1
        else:
            if j != 0:
                
                yield (i, j, i, j - 1)
                j -= 1
            else:
                
                yield (i, j, i + 1, j)
                i += 1



main()

Solution (Python):
H, W = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(H)]
visited = [[True]*(W+2)] + [[True]+[False]*W+[True] for _ in range(H)] + [[True]*(W+2)]

dirs = [
  (1, 0),
  (0, 1),
  (-1, 0),
  (0, -1)
]
direction = 0
x, y = 1, 1
carry = 0
ans = []
while not visited[y][x]:
  visited[y][x] = True
  m[y-1][x-1] += carry
  if carry:
    ans[-1] += [y, x]

  carry = m[y-1][x-1] % 2
  if carry:
    ans.append([y, x])
    m[y-1][x-1] -= 1 

  
  nx, ny = x + dirs[direction][0], y + dirs[direction][1]
  if visited[ny][nx]:
    direction = (direction + 1) % 4
  x += dirs[direction][0]
  y += dirs[direction][1]

if len(ans) > 0 and len(ans[-1]) < 4:
  y, x = ans.pop()
  m[y-1][x-1] += 1 

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

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

a = []
b = []

for i in range(h):
    t = list(map(int, input().split()))
    a.append(t)

q = 0
for i in range(h):
    f = i%2
    if f == 0:
        for j in range(w):
            if a[i][j] %2 == 1:
                if q == 0:
                    q = 1
                    if j != w-1:
                        b.append([i+1, j+1, i+1, j+2])
                    elif i != h-1:
                        b.append([i+1, j+1, i+2, j+1])
                else:
                    q = 0
            else:
                if q == 1:
                    if j != w-1:
                        b.append([i+1, j+1, i+1, j+2])
                    elif i != h-1:
                        b.append([i+1, j+1, i+2, j+1])
    else:
        for j in range(w):
            k = w-j-1
            if a[i][k] %2 == 1:
                if q == 0:
                    q = 1
                    if k != 0:
                        b.append([i+1, k+1, i+1, k])
                    elif i != h-1:
                        b.append([i+1, k+1, i+2, k+1])
                else:
                    q = 0
            else:
                if q == 1:
                    if k != 0:
                        b.append([i+1, k+1, i+1, k])
                    elif i != h-1:
                        b.append([i+1, k+1, i+2, k+1])
                    
print(len(b))
for i in range(len(b)):
    print(b[i][0], b[i][1], b[i][2], b[i][3])

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

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

N = 0
R = []

for h in range(H):
    for w in range(W):
        if A[h][w] % 2 == 1:
            if w != W-1:
                N += 1
                A[h][w+1] += 1
                R.append("%s %s %s %s" % (h+1, w+1, h+1, w+1+1))
            else:
                if h != H-1:
                    N += 1
                    A[h+1][w] += 1
                    R.append("%s %s %s %s" % (h+1, w+1, h+1+1, w+1))

print(N)
for r in R:
    print(r)