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


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

    moves = []

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


    print(len(moves))
    for v in moves:
        print('{} {} {} {}'.format(v[0], v[1], v[2], v[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())))

ans=[]

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i<H-1 and ((i%2==0 and n==W-1) or (i%2==1 and n==0)):
                A[i+1][n]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+2,n+1))
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                A[i][n+(-1)**(i%2)]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2)))

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

Solution (Python):
import copy

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

a = [list(map(int,input().split())) for i in range(h)]
b = copy.deepcopy(a)

n=0
for i in range(h):
  for j in range(w-1):
    if b[i][j]%2 ==1 :
      n+=1
      b[i][j] -= 1
      b[i][j+1] += 1

for i in range(h-1):
  if b[i][w-1]%2 == 1:
    n+=1
    b[i][w-1] -= 1
    b[i+1][w-1] += 1

print(n)

for i in range(h):
  for j in range(w-1):
    if a[i][j]%2 ==1 :
      print(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][w-1]%2 == 1:
    print(i+1,w,i+2,w)
    a[i][w-1] -= 1
    a[i+1][w-1] += 1

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

route = []
for i in range(H):
    if i%2==0:
        order = range(W)
    else:
        order = reversed(range(W))
    for j in order:
        route.append([i, j])

man = []
move = False
for i, (y, x) in enumerate(route):
    if move:
        man.append(route[i-1]+route[i])
        if a[y][x] ==1:
            move = False
    elif a[y][x] == 1:
        move = True
print(len(man))
for elem in man:
    print(' '.join(list(map(lambda x: str(x+1), elem))))

Solution (Python):
h, w = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(h)]
B = []
count = 0

for i in range(h):
    for j in range(w-1):
        if A[i][j] % 2 == 1:
            count += 1
            A[i][j+1] += 1
            B.append([i+1, j+1, i+1, j+2])
            
for i in range(h-1):
    if A[i][-1] % 2 == 1:
        count += 1
        A[i+1][-1] += 1
        B.append([i+1, w, i+2, w])
        
print(count)
for b in B:
    print(b[0], b[1], b[2], b[3])

Solution (Python):
r,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(r)]
s=[]
n=0
for i in range(r-1):
    for  j in range(c):
        if l[i][j]%2==1:
            l[i][j]-=1
            l[i+1][j]+=1
            s.append([i+1,j+1,i+2,j+1])
            n+=1
for i in range(c-1):
    if l[r-1][i]%2==1:
        l[r-1][i]-=1
        l[r-1][i+1]+=1
        s.append([r,i+1,r,i+2])
        n+=1
print(n)
for i in range(len(s)):
    for j in range(4):
        if j!=3:
            print(s[i][j],end=' ')
        else:
            print(s[i][j])

Solution (Python):
h, w = map(int, input().split())
A= [[int(i) for i in input().split()] for i in range(h)]
B = []
count = 0

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

for i in range(h - 1):
    if A[i][-1] % 2 == 1:
        A[i + 1][-1] += 1
        B.append([i + 1, w, i + 2, w])
        count += 1
        
print(count)
for i in B: 
    print(i[0], i[1], i[2], i[3])

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

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

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

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

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

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

Solution (Python):
h, w = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(h)]
count = 0
B = []

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

for i in range(h-1):
    if A[i][w-1] % 2 == 1:
        count += 1
        A[i+1][w-1] += 1
        B.append([i+1, w, i+2, w])
        
print(count)
for i in range(count):
    print(B[i][0], B[i][1], B[i][2], B[i][3])

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

ans = []

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


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

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

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

    for i in range(W):
        for j in range(H-1):
            if a[j][i] % 2 == 1:
                a[j][i] -= 1
                a[j+1][i] += 1
                ans += [ str(j+1) + " " + str(i+1) + " " + str(j+2) + " " + str(i+1) ]

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

Solution (Python):
def main():
    ans, a = [], []
    H, W = map(int, input().split())

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

    x, y, dx = 0, 0, 1

    while True:
        nx, ny = x, y
        if x+dx < 0 or W <= x+dx:
            nx = x
            ny = y+1 
            dx *= -1
        else:
            nx = x+dx
            ny = y

        if H <= ny:
            break

        if a[y][x] % 2 == 1:
            a[y][x] -= 1
            a[ny][nx] += 1
            ans += [str(y+1) + " " + str(x+1) + " " + str(ny+1) + " " + str(nx+1)]
        x, y = nx, ny

    print (len(ans))

    for i in ans:
        print (i)

main()

Solution (Python):
h,w = map(int,input().split())
coin = [list(map(int,input().split())) for i in range(h)]
ans = []
c = 0
for i in range(h):
  for j in range(w-1):
    if coin[i][j] % 2:
      coin[i][j+1] += 1
      ans.append([i+1,j+1,i+1,j+2])
      c += 1
 
for k in range(h-1):
  if coin[k][w-1] % 2:
    coin[k+1][w-1] += 1
    ans.append([k+1,w,k+2,w])
    c += 1
    
print(c)
for i in range(c):
  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())))
y = []
x = []
Y = []
X = []
n = 0
for i in range(h):
    for j in range(w):
        if a[i][j]%2 != 0:
            if j<w-1:
                n += 1
                y.append(i)
                x.append(j)
                Y.append(i)
                X.append(j+1)
                a[i][j+1] += 1
            elif i <h-1:
                n += 1
                y.append(i)
                x.append(j)
                Y.append(i+1)
                X.append(j)
                a[i+1][j] += 1
print(n)
for i in range(n):
    print(y[i]+1,x[i]+1,Y[i]+1,X[i]+1)

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

for k in range(h-1):
  if coin[k][w-1] % 2:
    coin[k+1][w-1] += 1
    ans.append([k+1,w,k+2,w])
    c += 1
    
print(c)
for i in range(c):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])

Solution (Python):

H,W = map(int,input().split())
count = 0
ans = []
arr = []
for i in range(H):
    arr.append(list(map(int,input().split())))
for h in range(H):
    for w in range(W-1):
        if arr[h][w]%2 == 1:
            arr[h][w+1] += 1
            count += 1
            ans.append([h+1,w+1,h+1,w+2])

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

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

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

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

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

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

ans = []
for i in range(h):
    for k in range(w-1):
        if grid[i][k]%2 == 1:
            ans.append([i+1,k+1,i+1,k+2])
            grid[i][k] += -1
            grid[i][k+1] += 1
for i in range(h-1):
    if grid[i][-1]%2 == 1:
        ans.append([i+1,w,i+2,w])
        grid[i][-1] += -1
        grid[i+1][-1] += 1
print(len(ans))
for i in range(len(ans)):
    for k in range(4):
        if k != 3:
            print(ans[i][k],end = " ")
        else:
            print(ans[i][k])

Solution (Python):
import numpy as np

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


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


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

print(len(O))
for o in O:
    print("{} {} {} {}".format(*o) )

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

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

m = []
for i in range(H-1):
  for j in range(W):
    if a[i][j] % 2 == 1:
      s = str(i+1) + " " + str(j+1) + " " + \
      	str(i+2) + " " + str(j+1)
      m.append(s)
      a[i+1][j] += 1

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

Solution (Python):
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append([int(m) for m in input().split()])
n = 0
printlist= []
for i in range(h):
    for j in range(w):
        if i % 2 == 0 and j == w - 1:
            nx = j
            ny = i + 1
            if i == h - 1:
                break
        elif i % 2 == 0 and j != w - 1:
            nx = j + 1
            ny = i
        elif i % 2 != 0 and j == w - 1:
            j = w - j - 1
            nx = j
            ny = i + 1
            if i == h - 1:
                break
        elif i % 2 != 0 and j != w - 1:
            j = w - j - 1
            nx = j - 1
            ny = i
        if a[i][j] % 2 != 0:
            a[i][j] -= 1
            a[ny][nx] += 1
            printlist.append([i + 1, j + 1, ny + 1, nx + 1])
            n += 1

print(n)
for i in range(n):
    print(printlist[i][0], printlist[i][1], printlist[i][2], printlist[i][3])

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

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

reslis = []
flag = False
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if j == W-1:
                ne = (i + 1, j)
            else:
                ne = (i, j + 1)

            if A[i][j] % 2 == 1:
                if flag:
                    flag = False
                else:
                    flag = True
            
            if flag and ne[0] <= H - 1:
                reslis.append("{} {} {} {}".format(i+1,j+1,ne[0]+1,ne[1]+1))

    else:
        for j in range(W-1, -1, -1):
            if j == 0 :
                ne = (i + 1, j)
            else:
                ne = (i, j - 1)

            if A[i][j] % 2 == 1:
                if flag:
                    flag = False
                else:
                    flag = True

            if flag and ne[0] <= H - 1:
                reslis.append("{} {} {} {}".format(i+1,j+1,ne[0]+1,ne[1]+1))

print(len(reslis))
for st in reslis:
    print(st)

Solution (Python):
class Manipulation:
    def __init__(self, x_prev, y_prev, x_after, y_after):
        self.x_prev = x_prev
        self.y_prev = y_prev
        self.x_after = x_after
        self.y_after = y_after

    def print(self):
        print(self.x_prev, self.y_prev, self.x_after, self.y_after)


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

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

N = 0
manipulations = []

for i in range(H):
    for j in range(W):
        x = j+1
        y = i+1
        if A[i][j] % 2 == 1:
            if j == W-1:
                if i != H-1:
                    A[i+1][j] += 1
                    N += 1
                    manip = Manipulation(y, x, y+1, x)
                    manipulations.append(manip)
            else:
                A[i][j+1] += 1
                N += 1
                manip = Manipulation(y, x, y, x+1)
                manipulations.append(manip)
print(N)
for manip in manipulations:
    manip.print()

Solution (Python):
def d_make_them_even(H, W, A):
    from itertools import product
    
    wall = [[-1] * (W + 2)]
    grid = wall + [[-1] + row + [-1] for row in A] + wall

    ans_tmp = []
    for h, w in product(range(1, H + 1), range(1, W + 1)):
        if grid[h][w] % 2 == 1:
            
            for dh, dw in zip((0, 1), (1, 0)):
                nh, nw = h + dh, w + dw
                if grid[nh][nw] != -1:
                    grid[nh][nw] += 1
                    grid[h][w] -= 1
                    ans_tmp.append('{0} {1} {2} {3}'.format(h, w, nh, nw))
                    break
    
    ans = str(len(ans_tmp)) + '\n' + '\n'.join(ans_tmp)
    return ans

H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
print(d_make_them_even(H, W, A))

Solution (Python):
import math

H, W = [int(x) for x in input().split()]
A = [[0] * W for _ in range(H)]

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

retlist = []

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
            retlist.append((i, j, i, j + 1))

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

print(len(retlist))
for i1, j1, i2, j2 in retlist:
    print("{} {} {} {}".format(i1 + 1, j1 + 1, i2 + 1, j2 + 1))

Solution (Python):
(h, w) = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(list(map(int, input().split())))
move = []
def print_move(bh, bw, ah, aw):
    global move
    move.append(str(bh + 1) + ' ' + str(bw + 1) + ' ' + str(ah + 1) + ' ' + str(aw + 1))

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
            print_move(i, j, i + 1, j)

for j in range(w - 1):
    if a[h - 1][j] % 2 == 1:
        a[h - 1][j] -= 1
        a[h - 1][j + 1] += 1
        print_move(h - 1, j, h - 1, j+1)
print(len(move))
for i in move:
    print(i)

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

order=[]
for i in range(H):
    if i%2==0:
        for j in range(W):
            order.append((i,j))
    else:
        for j in reversed(range(W)):
            order.append((i,j))

ans=[]

for(y1,x1),(y2,x2) in zip(order,order[1:]):
    if src[y1][x1]%2:
        ans.append((y1+1,x1+1,y2+1,x2+1))
        src[y2][x2]+=1
print(len(ans))
for row in ans:
    print(*row)

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


H, W = [int(elem) for elem in fin().split()]
grid = [[int(elem) for elem in fin().split()] for _ in range(H)]
assert len(grid[0]) == W

directions = ((0, 1), (1, 0))

operations = []
for y in range(H):
    for x in range(W):
        if grid[y][x] % 2 == 0:
            continue
        for dy, dx in directions:
            next_y, next_x = y + dy, x + dx
            if next_y >= H or next_x >= W:
                continue
            elif grid[next_y][next_x] % 2 == 1:
                grid[y][x] -= 1
                grid[next_y][next_x] += 1
                operations.append((y + 1, x + 1, next_y + 1, next_x + 1))
                break
        else:
            if y == H - 1 and x == W - 1:
                break
            elif x == W - 1:
                next_y, next_x = y + 1, x
            else:
                next_y, next_x = y, x + 1
            grid[y][x] -= 1
            grid[next_y][next_x] += 1
            operations.append((y + 1, x + 1, next_y + 1, next_x + 1))  

print(len(operations))
for y, x, next_y, next_x in operations:
    print(y, x, next_y, next_x)

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

order = []
for i in range(H):
    if i%2==0:
        for j in range(W):
            order.append((i,j))
    else:
        for j in reversed(range(W)):
            order.append((i,j))

ans = []
for (y1,x1),(y2,x2) in zip(order, order[1:]):
    if src[y1][x1]%2:
        ans.append((y1+1,x1+1,y2+1,x2+1))
        src[y2][x2] += 1

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

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

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

print(n)
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)]

ANSLIST=[]

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

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

print(len(ANSLIST))
for x,y,z,w in ANSLIST:
    print(x+1,y+1,z+1,w+1)

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

yx = []
for y in range(1, h+1):
    if y % 2 == 1:
        yx.extend([(y, x) for x in range(1, w+1)])
    else:
        yx.extend([(y, x) for x in range(w, 0, -1)])

n = 0
op_list = []
for i in range(h * w - 1):
    sy, sx = yx[i]
    if a[sy-1][sx-1] % 2 == 1:
        ey, ex = yx[i+1]
        a[sy-1][sx-1] -= 1
        a[ey-1][ex-1] += 1
        n += 1
        op_list.append((sy, sx, ey, ex))

print(n)
for op in op_list:
    print(' '.join(map(str, op)))

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

for i in range(H):
    L1=list(map(int,input().split()))
    L.append(L1)
ans=[]
cnt=0
for a in range(H):
    for b in range(W):
        if a%2==0:
            if b<W-1:
                if L[a][b]%2==1:
                    L[a][b]-=1
                    L[a][b+1]+=1
                    ans.append([a+1,b+1,a+1,b+2])
                    cnt+=1
            if b==W-1:
                if a<H-1:
                    if L[a][b]%2==1:
                        L[a][b]-=1
                        L[a+1][b]+=1
                        ans.append([a+1,b+1,a+2,b+1])
                        cnt+=1
        if a%2==1:
            if b<W-1:
                if L[a][W-1-b]%2==1:
                    L[a][W-1-b]-=1
                    L[a][W-1-b-1]+=1
                    ans.append([a+1,W-b,a+1,W-1-b])
                    cnt+=1
            if b==W-1:
                if a<H-1:
                    if L[a][W-1-b]%2==1:
                        L[a][W-1-b]-=1
                        L[a+1][W-1-b]+=1
                        ans.append([a+1,W-b,a+2,W-b])
                        cnt+=1
print(cnt)
for x in range(len(ans)):
    print(ans[x][0],ans[x][1],ans[x][2],ans[x][3])

Solution (Python):
H,W=map(int,input().split())
Map=[[int(i) for i in input().split()] for i in range(H)]
Tell=[]
for y in range(H): 
  for x in range(W):
    if Map[y][x]%2==1:
      if x==W-1:
        Map[y][x]=1
      elif Map[y][x+1]%2==0:
        Map[y][x]=0
        Map[y][x+1]=1
        Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+1)+" "+str(x+2))
      else:
        Map[y][x]=0
        Map[y][x+1]=0
        Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+1)+" "+str(x+2))
    else:
      Map[y][x]=0
for y in range(H):
  if Map[y][W-1]==1:
    if y==H-1:
      pass
    elif Map[y+1][W-1]==0:
      Map[y][W-1]=0
      Map[y+1][W-1]=1
      Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+2)+" "+str(x+1))
    elif Map[y+1][W-1]==1:
      Map[y][W-1]=0
      Map[y+1][W-1]=0
      Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+2)+" "+str(x+1))
print(len(Tell))
for t in Tell:
  print(t)

Solution (Python):
h, w = raw_input().split(" ")
h, w = int(h), int(w)

a = []
for i in range(h):
   a.append([int(x) for x in raw_input().split(" ")])


move = []

for i in range(h):
    for j in range(w-1):
        if a[i][j] & 1:
            a[i][j], a[i][j+1] = 0, a[i][j] + a[i][j+1]
            move.append((i+1,j+1,i+1,j+1+1))

e = w-1
for i in range(h-1):
    if a[i][e] & 1:
        a[i][e], a[i+1][e] = 0, a[i][e] + a[i+1][e]
        move.append((i+1,e+1,i+1+1,e+1))

print(len(move))

for step in move:
    print("{} {} {} {}".format(*step))

Solution (Python):
h, w = raw_input().split(" ")
h, w = int(h), int(w)

a = []
for i in range(h):
   a.append([int(x) for x in raw_input().split(" ")])


move = []

for i in range(h):
    for j in range(w-1):
        if a[i][j] & 1:
            a[i][j], a[i][j+1] = 0, a[i][j] + a[i][j+1]
            move.append((i+1,j+1,i+1,j+1+1))

e = w-1
for i in range(h-1):
    if a[i][e] & 1:
        a[i][e], a[i+1][e] = 0, a[i][e] + a[i+1][e]
        move.append((i+1,e+1,i+1+1,e+1))

print(len(move))

for step in move:
    print("{} {} {} {}".format(*step))

Solution (Python):



s = raw_input()
H, W = [int(x) for x in s.split()]

A = [None] * H

for i in xrange(H):
	s = raw_input()
	A[i] = [int(x) for x in s.split()]
	

choose = [[False]*W for i in xrange(H)]
answer = -1
answerOps = []
ops = []

def dfs(y, x, even):
	global H, W, A, answer, answerOps, ops

	if x >= W:
		x, y = 0, y+1
	if x == 0 and y == H:
		if even > answer:
			answer = even
			answerOps = ops
		return
	if even + (H-y-1)*W + (W-x) <= answer:
		return

	
	

	coin = A[y][x]
	if coin % 2 == 1:
		A[y][x] = 0
		if x+1 < W:
			A[y][x+1] += coin
			ops.append((y, x, y, x+1))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y][x+1] -= coin

		if y+1 < H:
			A[y+1][x] += coin
			ops.append((y, x, y+1, x))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y+1][x] -= coin
		A[y][x] = coin

		dfs(y, x+1, even)
	else:
		dfs(y, x+1, even+1)





def check(y, x):
	if x+1 < W:
		if A[y][x+1] % 2 == 1:
			return 'right'
	if y+1 < H:
		if A[y+1][x] % 2 == 1:
			return 'down'
	if x+1 < W:
		return 'right'
	if y+1 < H:
		return 'down'

for i in xrange(H):
	for j in range(W):
		if A[i][j] % 2 == 1:
			ret = check(i, j)
			if ret == 'right':
				A[i][j+1] += A[i][j]
				answerOps.append((i, j, i, j+1))
			elif ret == 'down':
				A[i+1][j] += A[i][j]
				answerOps.append((i, j, i+1, j))

print len(answerOps)
for t in answerOps:
	print '%d %d %d %d' % tuple([x+1 for x in t])

Solution (Python):



s = raw_input()
H, W = [int(x) for x in s.split()]

A = [None] * H

for i in xrange(H):
	s = raw_input()
	A[i] = [int(x) for x in s.split()]
	

choose = [[False]*W for i in xrange(H)]
answer = -1
answerOps = []
ops = []

def dfs(y, x, even):
	global H, W, A, answer, answerOps, ops

	if x >= W:
		x, y = 0, y+1
	if x == 0 and y == H:
		if even > answer:
			answer = even
			answerOps = ops
		return
	if even + (H-y-1)*W + (W-x) <= answer:
		return

	
	

	coin = A[y][x]
	if coin % 2 == 1:
		A[y][x] = 0
		if x+1 < W:
			A[y][x+1] += coin
			ops.append((y, x, y, x+1))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y][x+1] -= coin

		if y+1 < H:
			A[y+1][x] += coin
			ops.append((y, x, y+1, x))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y+1][x] -= coin
		A[y][x] = coin

		dfs(y, x+1, even)
	else:
		dfs(y, x+1, even+1)





def check(y, x):
	if x+1 < W:
		if A[y][x+1] % 2 == 1:
			return 'right'
	if y+1 < H:
		if A[y+1][x] % 2 == 1:
			return 'down'
	if x+1 < W:
		return 'right'
	if y+1 < H:
		return 'down'

for i in xrange(H):
	for j in range(W):
		if A[i][j] % 2 == 1:
			ret = check(i, j)
			if ret == 'right':
				A[i][j+1] += A[i][j]
				answerOps.append((i, j, i, j+1))
			elif ret == 'down':
				A[i+1][j] += A[i][j]
				answerOps.append((i, j, i+1, j))

print len(answerOps)
for t in answerOps:
	print '%d %d %d %d' % tuple([x+1 for x in t])

Solution (Python):



s = raw_input()
H, W = [int(x) for x in s.split()]

A = [None] * H

for i in xrange(H):
	s = raw_input()
	A[i] = [int(x) for x in s.split()]
	

choose = [[False]*W for i in xrange(H)]
answer = -1
answerOps = []
ops = []

def dfs(y, x, even):
	global H, W, A, answer, answerOps, ops

	if x >= W:
		x, y = 0, y+1
	if x == 0 and y == H:
		if even > answer:
			answer = even
			answerOps = ops
		return
	if even + (H-y-1)*W + (W-x) <= answer:
		return

	
	

	coin = A[y][x]
	if coin % 2 == 1:
		A[y][x] = 0
		if x+1 < W:
			A[y][x+1] += coin
			ops.append((y, x, y, x+1))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y][x+1] -= coin

		if y+1 < H:
			A[y+1][x] += coin
			ops.append((y, x, y+1, x))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y+1][x] -= coin
		A[y][x] = coin

		dfs(y, x+1, even)
	else:
		dfs(y, x+1, even+1)





def check(y, x):
	if x+1 < W:
		if A[y][x+1] % 2 == 1:
			return 'right'
	if y+1 < H:
		if A[y+1][x] % 2 == 1:
			return 'down'
	if x+1 < W:
		return 'right'
	if y+1 < H:
		return 'down'

for i in xrange(H):
	for j in range(W):
		if A[i][j] % 2 == 1:
			ret = check(i, j)
			if ret == 'right':
				A[i][j+1] += A[i][j]
				answerOps.append((i, j, i, j+1))
			elif ret == 'down':
				A[i+1][j] += A[i][j]
				answerOps.append((i, j, i+1, j))

print len(answerOps)
for t in answerOps:
	print '%d %d %d %d' % tuple([x+1 for x in t])

Solution (Python):
def solve(string):
    h, w = map(int, string.split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, input().strip().split(" "))) for _i in range(h)]
    move = []
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)
 
 
if __name__ == '__main__':
    line = input().strip()
    print(solve(line))

Solution (Python):
def is_odd(num):
    return num % 2 == 1

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


m()