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(x) for x in input().split()]
a = [ [int(x)%2!=0 for x in input().split()] for _ in range(h)]

mvs = []
for i, row in enumerate(a):
    if i<h-1:
        for j, elem in enumerate(row):
            if elem:
                mvs.append((i, j, i+1, j))
                a[i+1][j] = not a[i+1][j]
    else:
        for j, elem in enumerate(row):
            if j==w-1:
                break
            if elem:
                mvs.append((i, j, i, j+1))
                a[i][j+1] = not a[i][j+1]

print(len(mvs))
for y, x, yp, xp in mvs:
    print(y+1, x+1, yp+1, xp+1)

Solution (Python):
def d_make_them_even(H, W, A):
    board = [row for row in A]
    ans = []
    for h in range(H):
        for w in range(W):
            if board[h][w] % 2 == 1:
                for nh, nw in zip((0, 1), (1, 0)):
                    if 0 <= h + nh <= H - 1 and 0 <= w + nw <= W - 1:
                        board[h + nh][w + nw] += 1
                        board[h][w] -= 1
                        ans.append('{0} {1} {2} {3}'.format(h + 1, w + 1, h + nh + 1, w + nw + 1))
                        break
    ans.insert(0, str(len(ans)))
    ans = '\n'.join(ans)
    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):



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


def main():
    ans = []
    for i in range(H):
        for j in range(W):
            if not mat[i][j] % 2:
                continue

            if j + 1 < W:
                mat[i][j] -= 1
                mat[i][j+1] += 1
                ans.append((i+1, j+1, i+1, j+2))
            elif i + 1 < H:
                mat[i][j] -= 1
                mat[i+1][j] += 1
                ans.append((i+1, j+1, i+2, j+1))

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


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
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:
            continue
        if a[i][j]%2 == 0:
            continue
        else:
            if j < w-1 and a[i][j+1]%2 == 1:
                a[i][j] -= 1
                a[i][j+1] += 1
                ans.append([i+1, j+1, i+1, j+2])
                continue
            elif i < h-1 and a[i+1][j]%2 == 1:
                a[i][j] -= 1
                a[i+1][j] += 1
                ans.append([i+1, j+1, i+2, j+1])
                continue
            if j < w-1:
                a[i][j] -= 1
                a[i][j+1] += 1
                ans.append([i+1, j+1, i+1, j+2])
                continue
            elif i < h-1:
                a[i][j] -= 1
                a[i+1][j] += 1
                ans.append([i+1, j+1, i+2, j+1])
                continue


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

Solution (Python):




import copy

def advance(h, w, nx, ny):
    if 0 == ny % 2:
        if nx == w - 1:
            return nx , ny + 1
        else:
            return nx + 1, ny
    elif 1 == ny % 2:
        if nx == 0:
            return nx, ny + 1
        else:
            return nx - 1, ny

    

def main(h, x, mat):
    nx = 0
    ny = 0
    retlist = []
    while nx < w and ny < h:
        ''' 終了条件
        '''
        next_x, next_y = advance(h, w, nx, ny)
        if next_x == w or next_y == h:
            break
        if 0 == mat[ny][nx] % 2:
            pass
        else:
            mat[ny][nx] -= 1
            mat[next_y][next_x] += 1
            retlist.append([ny, nx, next_y, next_x])
            
        nx = next_x
        ny = next_y

        
    print(len(retlist))
    for i in range(len(retlist)):
        print('{} {} {} {}'.format(retlist[i][0] + 1, retlist[i][1] + 1, retlist[i][2] + 1, retlist[i][3] + 1))
                
    
if __name__ == '__main__':
    try:
        h, w  = list(map(int, input().strip().split(' ')))
        mat = []
        for i in range(h):
            mat.append(list(map(int, input().strip().split(' '))))
        main(h, w, mat)
    except EOFError:
        pass

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

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

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

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

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

print(len(move))

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

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

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

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

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

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

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

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

print(len(ans))

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

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

ODD = []
PAIR = [] 
BACK = [0,0]
for i in range(H):
    A = list(map(int,input().split()))
    RangeW = range(W)
    if i%2==1: RangeW = RangeW[::-1]
    for j in RangeW:
        if A[j]%2==1:
            if ODD: 
                ODD.pop()
                PAIR.append(BACK+[i+1,j+1])
            else:
                ODD.append([i+1,j+1])
        else:
            if ODD:
                PAIR.append(BACK+[i+1,j+1])
        BACK = [i+1,j+1]

print(len(PAIR))
for p in PAIR:
    print(" ".join([str(s) for s in p]))

Solution (Python):
H, W = map(int,input().split())
A = [list(map(int,input().split())) for k in range(H)]
t = 0
B = []
for y in range(W):
    for x in range(H):
        if A[x][y] % 2 == 1:
            if x+1<H:
                A[x+1][y] += 1
                A[x][y] -= 1
                B.append([x+1,y+1,x+2,y+1])
            elif y+1<W:
                A[x][y+1] += 1
                A[x][y] -= 1
                B.append([x+1,y+1,x+1,y+2])
            elif x+1<H and y+1<W:
                A[x+1][y+1] += 1
                A[x][y] -= 1
                B.append([x+1,y+1,x+2,y+2])
print(len(B))
for b in B:
    print(" ".join(map(str,b)))

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):
    tw=w//2
    for j in range(tw):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j+2])
            a[i][j]-=1
            a[i][j+1]+=1
    for j in range(w-1,tw,-1):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j])
            a[i][j]-=1
            a[i][j-1]+=1
th=h//2
for i in range(th):
    if a[i][tw]%2==1:
        n+=1
        ans.append([i+1,tw+1,i+2,tw+1])
        a[i][tw]-=1
        a[i+1][tw]+=1
for i in range(h-1,th,-1):
    if a[i][tw]%2==1:
        n+=1
        ans.append([i+1,tw+1,i,tw+1])
        a[i][tw]-=1
        a[i-1][tw]+=1
print(n)
for t in ans:
    t=[str(t[i]) for i in range(4)]
    print(" ".join(t))

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

count=0
arry=[]
for i in range(h):
    for j in range(w):
        if(arr[i][j]%2!=0):
            flag=0
            if(j>0 and arr[i][j-1]%2!=0):
                arr[i][j]-=1
                arr[i][j-1]+=1
                count+=1
                arry.append((j+1,i+1,j,i+1))
                flag=1
            elif(j<w-1 and arr[i][j+1]%2!=0):
                arr[i][j]-=1
                arr[i][j+1]+=1
                count+=1
                arry.append((j+1,i+1,j+2,i+1))
                flag=1
            elif(i>0 and arr[i-1][j]%2!=0):
                arr[i][j]-=1
                arr[i-1][j]+=1
                count+=1
                arry.append((j+1,i+1,j+1,i))
                flag=1

            elif(i<h-1 and arr[i+1][j]%2!=0):
                arr[i][j]-=1
                arr[i+1][j]+=1
                count+=1
                arry.append((j+1,i+1,j+1,i+2))
                flag=1
            if(flag==0):
                if(j<w-1):
                    arr[i][j]-=1
                    arr[i][j+1]+=1
                    count+=1
                    arry.append((j+1,i+1,j+2,i+1))
                elif(i<h-1):
                    arr[i][j]-=1
                    arr[i+1][j]+=1
                    count+=1
                    arry.append((j+1,i+1,j+1,i+2))
print(count)
for i in range(len(arry)):
    print(arry[i][1],arry[i][0],arry[i][3],arry[i][2])

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

cnt=0
for i in range(h):
    for j in range(w):
        if j!=(w-1):
            if a[i][j]%2==1 and a[i][j]!=0:
                mani[cnt] = [i,j,i,j+1]
                cnt +=1
                a[i][j+1] +=1
        elif i!=(h-1):
            if a[i][j]%2==1 and a[i][j]!=0 :
                mani[cnt] = [i,j,i+1,j]
                cnt +=1
                a[i+1][j]+=1
print(cnt)
for k in range(cnt):
    print("{} {} {} {}".format(mani[k][0]+1, mani[k][1]+1, mani[k][2]+1, mani[k][3]+1))

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

for i in range(h):
    for j in range(w):
        b[i][j] = a[i][j]

counter = 0
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
            counter += 1
for i in range(h-1):
    if (a[i][-1] % 2) != 0:
        a[i+1][-1] += 1
        a[i][-1] -= 1
        counter += 1

print(counter)
for i in range(h):
    for j in range(w-1):
        if b[i][j] % 2 != 0:
            b[i][j+1] += 1
            b[i][j] -= 1
            print("{} {} {} {}".format(i+1, j+1, i+1, j+2))
for i in range(h-1):
    if b[i][-1] % 2 != 0:
        b[i+1][-1] += 1
        b[i][-1] -= 1
        print("{} {} {} {}".format(i+1, w, i+2, w))

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

N = 0
ans = []

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


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

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

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

ans = []

aw = []

for y in range(1, h + 1):
    ay = list(map(int, input().split(' ')))
    for x in range(1, w):
        if ay[x - 1] % 2 == 1:
            ans.append((y, x, y, x + 1))
            ay[x] += 1
    aw.append(ay[w - 1])

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

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

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


def check(i, j):
    for dx, dy in [(0, 1), (1, 0)]:
        x, y = j + dx, i + dy
        if 0 <= x < W and 0 <= y < H:
            if a[y][x] % 2 == 1:
                return y, x
    if i + 1 < H:
        return i + 1, j
    elif j + 1 < W:
        return i, j + 1
    else:
        return -1, -1


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

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

Solution (Python):
h,w=map(int, input().split())
s = [list(map(int, input().split())) for i in range(h)]
count=0
step=[]
for i in range(h):
    for j in range(w):
        if s[i][j]%2==1:
            if (j+1)==w:
                if (i+1)!=h:
                    step.append([i+1,j+1,i+2,j+1])
                    s[i+1][j]+=1
                    count+=1
            else:
                step.append([i+1,j+1,i+1,j+2])
                s[i][j+1]+=1
                count+=1
print(count)
for i in step:
    print(' '.join(list(map(str,i))))

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

for h in range(H):
    for w in range(W):
        A[h][w] %= 2


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

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

Solution (Python):
H, W = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
ans = []
N = 0
for i in range(H):
    for j in range(W - 1):
        if (grid[i][j]) % 2  == 1:
            x = grid[i][j]
            ans.append([i + 1, j + 1, i + 1, j + 2])
            grid[i][j + 1] += 1
            grid[i][j] -= 1
            N += 1

    if i < H - 1 and (grid[i][W - 1]) % 2 == 1:
        y = grid[i][W - 1]
        ans.append([i + 1, W, i + 2, W])
        grid[i][W - 1] -= 1
        grid[i + 1][W - 1] += 1
        N += 1

print(N)
if N > 0:
    for proc in ans:
        y, x, Y, X = proc
        print(y, x, Y, X)

Solution (Python):
h,w = map(int,input().split())
lis = []
for i in range(h):
  lis.append(list(map(int,input().split())))
cou = 0
ans = []
for i in range(h):
  for j in range(w):
    if lis[i][j] % 2 == 1:
      if j != w-1:
        ans.append([str(i+1),str(j+1),str(i+1),str(j+2)])
        lis[i][j]-=1
        lis[i][j+1]+= 1
        cou += 1
      else:
        if i != h-1:
          ans.append([str(i+1),str(j+1),str(i+2),str(j+1)])
          lis[i][j]-=1
          lis[i+1][j]+= 1
          cou += 1
print(cou)
for i in range(len(ans)):
  print(" ".join(ans[i]))

Solution (Python):
h,w = map(int, input().split())
grid = []
for i in range(h):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
x=1
y=1
anslis = []
n = 0
while x*y < h*w:
  if grid[y-1][x-1]%2 == 1:
    if x != w:
      grid[y-1][x-1] += -1
      grid[y-1][x] += 1
      anslis.append(y)
      anslis.append(x)
      anslis.append(y)
      anslis.append(x+1)
      n += 1
    else:
      grid[y-1][x-1] += -1
      grid[y][x-1] += 1
      anslis.append(y)
      anslis.append(x)
      anslis.append(y+1)
      anslis.append(x)
      n += 1
  if x < w:
    x += 1
  else:
    x = 1
    y += 1
print(n)
i = 0
while i < n:
  print(anslis[4*i],anslis[4*i+1],anslis[4*i+2],anslis[4*i+3])
  i += 1

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

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

operation=[]
def search(x,y):
    if x==w-1 and y==h-1:
        return

    if a[y][x]%2==1:
        if x==w-1 and y<h-1:
            a[y][x]-=1
            a[y+1][x]+=1

            operation.append([y,x,y+1,x])
        else:
            a[y][x]-=1
            a[y][x+1]+=1

            operation.append([y,x,y,x+1])

for x in range(w):
    for y in range(h):
        search(x,y)

print(len(operation))
for i in range(len(operation)):
    o=operation[i]
    print(o[0]+1,o[1]+1,o[2]+1,o[3]+1)

Solution (Python):
H, W = map(int, input().split())
a = [0 for i in range(H)]
for i in range(H):
    a[i] = list(map(int, input().split()))
result = []
for i in range(H):
    for j in range(W):
        if i == H-1 and j == W-1:
            continue
        if j == W-1 and a[i][j] % 2 == 1 and i < H-1:
            a[i][j] -= 1
            a[i+1][j] += 1
            result.append([i+1, j+1, i+2, j+1])

        elif a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i][j+1] += 1
            result.append([i+1, j+1,i+1, j+2])

print(len(result))
for i in range(len(result)):
    print('%d %d %d %d' % (result[i][0],result[i][1],result[i][2],result[i][3]))

Solution (Python):
import sys
h,w =map(int,input().split())
a = [list(map(int,input().split())) for l in range(h)]
ki = 0
ans = []
for i in range(h):
  if i%2 == 0:
    for j in range(w):
      if ki == 1:
        if j != 0:
          ans.append([i+1,j,i+1,j+1])
        else:
          ans.append([i,j+1,i+1,j+1])
      if a[i][j]%2 ==1:
        ki += 1
        if ki == 2:
          ki = 0
  else:
    for j in range(w-1,-1,-1):
      if ki == 1:
        if j != w-1:
          ans.append([i+1,j+2,i+1,j+1])
        else:
          ans.append([i,j+1,i+1,j+1])
      if a[i][j]%2 ==1:
        ki += 1
        if ki == 2:
          ki = 0
print(len(ans))
for b,c,d,e in ans:
  print(b,c,d,e)

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

                  a[i][j] -= 1
                  a[i][j+1] += 1            
                  answer.append([i+1, j+1, i+1, j+2])
          except:
              try:

                      a[i][j] -= 1
                      a[i+1][j] += 1  
                      answer.append([i+1, j+1, i+2, j+1])
              except:
                  pass
    
print(len(answer))
for i in range(len(answer)):
    print(" ".join(map(str, answer[i])))

Solution (Python):

def inpl(): return list(map(int, input().split()))
H, W = inpl()

A = [inpl() for _ in range(H)]

order = []
move = False
for i, h in enumerate(range(H)):
    direction = 1 - 2*(h%2==1)
    for j, w in enumerate(range(W)[::direction]):
        value = A[h][w] %2
        if move == value:
            if move:
                move = False
        else:
            if not move:
                move = True
            if j == W-1 and i == H-1:
                pass
            elif j == W-1:
                order.append([h+1, w+1, h+2, w+1])
            else:
                order.append([h+1, w+1, h+1, w+1+direction ])
            if not move:
                move = False

print(len(order))
for o in order:
    print(*o)

Solution (Python):
H,W=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(H)]
E=[]
b=[[(0,0) for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j]%2==1:
            E.append((i,j))
for i in range(H):
    for j in range(W):
        if i%2==0:
            if j==W-1:
                if i==H-1:
                    b[i][j]=(-1,-1)
                else:
                    b[i][j]=(i+1,j)
            else:
                b[i][j]=(i,j+1)
        else:
            if j==0:
                if i==H-1:
                    b[i][j]=(-1,-1)
                else:
                    b[i][j]=(i+1,j)
            else:
                b[i][j]=(i,j-1)
c=[[0 for i in range(W)] for i in range(H)]
p=(0,0)
k=0
while(True):
    c[p[0]][p[1]]=k
    k+=1
    p=b[p[0]][p[1]]
    if p[0]==-1 and p[1]==-1:
        break
F=sorted([(c[p[0]][p[1]],p[0],p[1]) for p in E])
N=len(F)//2
G=[]
for i in range(N):
    x=F[2*i]
    y=F[2*i+1]
    G.append((x[1],x[2],y[1],y[2]))
ans=[]
for pair in G:
    st=(pair[0],pair[1])
    fi=(pair[2],pair[3])
    np=st
    while(True):
        xp=b[np[0]][np[1]]
        if xp==(-1,-1):
            break
        ans.append((np[0],np[1],xp[0],xp[1]))
        if xp==fi:
            break
        np=xp
print(len(ans))
for t in ans:
    print(t[0]+1,t[1]+1,t[2]+1,t[3]+1)

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

odd = src[0][0]%2
prev = (0,0)
ans = []
for i in range(H):
    if i%2==0:
        for j in range(W):
            if (i,j) == (0,0):
                continue
            if odd:
                ans.append((prev[0]+1, prev[1]+1, i+1, j+1))
                if src[i][j]%2:
                    odd = False
            elif src[i][j]%2:
                odd = True
            prev = (i,j)
    else:
        for j in range(W-1,-1,-1):
            if odd:
                ans.append((prev[0]+1, prev[1]+1, i+1, j+1))
                if src[i][j]%2:
                    odd = False
            elif src[i][j]%2:
                odd = True
            prev = (i,j)

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

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

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

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

print(len(sousa))
for s in sousa:
    print(" ".join([str(i) for i in s]))

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

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

for i in range(H):
  if sum(A[i]) % 2 == 1 and i < H-1:
    kurikosi_flag = True
  else:
    kurikosi_flag = False
   
  for j in range(W):
    
    if A[i][j] % 2 == 0:
      continue
    elif kurikosi_flag:
      Q.append([i+1, j+1, i+2, j+1])
      A[i+1][j] += 1
      kurikosi_flag = False
    elif i < H-1:
      Q.append([i+1, j+1, i+1, j+2])
      A[i][j+1] += 1
    elif j+1 < W:
      Q.append([i+1, j+1, i+1, j+2])
      A[i][j+1] += 1
      
print(len(Q))
for i in range(len(Q)):
  print(" ".join(map(str,Q[i])))

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

for y in range(h):
  for x in range(w):
    if x<w-1 and l[y][x]%2:
      l[y][x]-=1
      l[y][x+1]+=1
      m.extend([[y+1,x+1,y+1,x+2]])

for x in range(w):
  for y in range(h):
    if y<h-1 and l[y][x]%2:
      l[y][x]-=1
      l[y+1][x]+=1
      m.extend([[y+1,x+1,y+2,x+1]])

print(len(m))
for i in m:
  print(*i,sep=" ")

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

ans = []
for i in range(h - 1):
    for j in range(w):
        if a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i + 1][j] += 1
            ans.append([i + 1, j + 1, i + 2, j + 1])
for i in range(w - 1):
    if a[-1][i] % 2 == 1:
        a[-1][i] -= 1
        a[-1][i + 1] += 1
        ans.append([h, i + 1, h, i + 2])
print(len(ans))
for ln in ans:
    print(' '.join(map(str, ln)))

Solution (Python):


import itertools
import sys


DELTAS = [(0, 1), (1, 0), (0, -1), (-1, 0)]


def in_stage(h, w, r, c):
    return 0 <= r < h and 0 <= c < w


def in_place_solve(h, w, stage):
    ops = []
    for r0, c0 in itertools.product(range(h), range(w)):
        tr, tc = None, None
        if stage[r0][c0] % 2 == 0:
            continue
        for dr, dc in DELTAS:
            r, c = r0 + dr, c0 + dc
            if in_stage(h, w, r, c) and stage[r][c] % 2 == 1:
                tr, tc = r, c
                break
        else:
            for dr, dc in DELTAS:
                r, c = r0 + dr, c0 + dc
                if in_stage(h, w, r, c):
                    tr, tc = r, c
                    break
        if tr is None or tc is None:
            continue
        ops.append((r0 + 1, c0 + 1, tr + 1, tc + 1))
        stage[r0][c0] -= 1
        stage[tr][tc] += 1
    return ops


def main():
    h, w = (int(x) for x in input().split())
    stage = [[int(x) for x in input().split()] for _ in range(h)]
    
    
    ops = in_place_solve(h, w, stage)
    
    
    print(len(ops))
    for y0, x0, y, x in ops:
        print(y0, x0, y, x)


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
A = [[] for i in range(H)]
for i in range(H):
  A[i] = [int(x) % 2 for x in input().split()]
output = []
for i in range(H - 1):
  for j in range(W):
    if A[i][j] == 1:
      output += [[i + 1, j + 1, i + 2, j + 1]]
      A[i + 1][j] = 1 - A[i + 1][j]
for j in range(W - 1):
  if A[H - 1][j] == 1:
    output += [[H, j + 1, H, j + 2]]
    A[H - 1][j + 1] = 1 - A[H - 1][j + 1]
print(len(output))
for o in output:
  print(o[0], o[1], o[2], o[3])

Solution (Python):
H, W = map( int, input().split())
A = []
for _ in range(H):
    a = list( map( int, input().split()))
    A.append(a)
N = 0
ANS = []
for i in range(H):
    for j in range(W):
        if A[i][j]%2 == 0:
            pass
        else:
            if j == W-1:
                if i == H-1:
                    pass
                else:
                    A[i][j] -= 1
                    A[i+1][j] += 1
                    N += 1
                    ANS.append([i+1, j+1, i+2, j+1])
            else:
                A[i][j] -= 1
                A[i][j+1] += 1
                ANS.append([i+1,j+1,i+1,j+2])
                N += 1
print(N)
for a in ANS:
    a = map( str, a)
    print(' '.join(a))

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

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

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

print(cnt)
for i,j,k,l in ans:
    print("{0} {1} {2} {3}".format(i,j,k,l))

Solution (Python):
n, m = map(int, raw_input().split())
a = []
for i in xrange(n):
	row = map(int, raw_input().split())
	a.append(row)

order = []
for i in xrange(n):
	for j in xrange(m):
		if i % 2 == 0:
			order.append((i, j))
		else:
			order.append((i, m - j - 1))

ans = []
for i in xrange(1, len(order)):
	x1, y1 = order[i - 1]
	x2, y2 = order[i]
	if a[x1][y1] % 2 != 0:
		ans.append(" ".join(map(str, (x1 + 1, y1 + 1, x2 + 1, y2 + 1))))
		a[x2][y2] += 1

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

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[h,w]=i2()
a=[]
for i in range(h):
 a.append(i2())
z=[]
for i in range(h):
 for j in range(w-1):
   if a[i][j]%2==1:
      a[i][j+1]+=1
      z.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
    z.append([i+1,w,i+2,w])

print(len(z))
for i,j,k,l in z:
  print(i,j,k,l)

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

Solution (Python):
h, w = [int(x) for x in input().split()]
grid = [[]]
for _ in range(h):
    grid.append([0] + [int(x) for x in input().split()])

operations = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if grid[i][j] % 2 == 0: continue
        if j < w:
            operations.append((i, j, i, j+1))
            grid[i][j+1] += grid[i][j]
        elif i < h:
            operations.append((i, j, i+1, j))
            grid[i+1][j] += grid[i][j]

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