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):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

H, W = reads()
A = []
for _ in range(H):
  A.append(reads())

def key(p):
  i, j = p
  return i * W + (j if i % 2 == 0 else W - 1 - j)

acts = []

ls = sorted(product(range(H), range(W)), key=key)
for u in range(len(ls)-1):
  i, j = ls[u]
  if A[i][j] % 2 != 0:
    (ii, jj) = ls[u+1]
    A[ii][jj] += 1
    A[i][j] -= 1
    acts.append((i, j, ii, jj))

N = len(acts)
print(N)
for a in acts:
  i, j, ii, jj = a
  print(i+1, j+1, ii+1, jj+1)

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

x, y = 0, 0

result = []

while 1:
    if y % 2 == 0:
        if x < W - 1:
            dx, dy = 1, 0
        else:
            dx, dy = 0, 1
    else:
        if x > 0:
            dx, dy = -1, 0
        else:
            dx, dy = 0, 1
    tx, ty = x + dx, y + dy
    if ty >= H:
        break
    v = a[y][x]
    if v % 2 == 1:
        a[y][x] = 0
        a[ty][tx] += v
        result.append((y+1, x+1, ty+1, tx+1))
    x, y = tx, ty

print(len(result))
for r in result:
    print(*r)

Solution (Python):
h,w = map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in range(h)]
ret = []
for y in range(h):
    for x in range(w-1):
        if a[y][x]%2==1:
            ret.append((y,x,y,x+1))
            a[y][x+1]+=1
for y in range(h-1):
    if a[y][-1]%2==1:
        ret.append((y,w-1,y+1,w-1))
        a[y+1][-1]+=1
print len(ret)
for seq in ret:
    a,b,c,d = seq
    print a+1,b+1,c+1,d+1

Solution (Python):
h,w = (int(i) for i in input().split())
a = [[int(i) for i in input().split()] for i in range(h)]
ans = []
for i in range(h-1):
	for j in range(w):
		if a[i][j]%2:
			ans.append([i+1,j+1,i+2,j+1])
			a[i+1][j]+=1
for j in range(w-1):
	if a[h-1][j]%2:
		ans.append([h,j+1,h,j+2])
		a[h-1][j+1]+=1
print(len(ans))
for i,j,i2,j2 in ans: print(i,j,i2,j2)

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

Ans=[]
for i in range(H):
  for j in range(W):
    if S[i][j]%2==1:
      if j+1<W:
        S[i][j]-=1
        S[i][j+1]+=1
        Ans.append((i+1,j+1,i+1,j+2))
      elif i+1<H:
        S[i][j]-=1
        S[i+1][j]+=1
        Ans.append((i+1,j+1,i+2,j+1))
      else:
        continue

print(len(Ans))
for i in range(len(Ans)):
  print(*list(Ans[i]))

Solution (Python):
H,W = map(int, raw_input().split())
a = [map(int, raw_input().split()) for y in range(H)]

ans = []
for y in range(H):
  for x in range(W-1):
    if a[y][x]%2!=0:
      a[y][x+1] += 1
      ans += [(y, x, y, x+1)]
  if y<H-1 and a[y][W-1]%2!=0:
    a[y+1][W-1] += 1
    ans += [(y, W-1, y+1, W-1)]
print len(ans)
for y1,x1,y2,x2 in ans:
  print y1+1, x1+1, y2+1, x2+1

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

H,W = inpl()
MAP = [inpl() for i in range(H)]

flag = False 
ans = []
for y in range(H):
	if y%2 == 0:
		for x in range(W):
			if flag:
				ans.append([by,bx,y,x])
			if MAP[y][x]%2 == 1:
				flag = not flag
			bx,by = x,y
	else:
		for x in reversed(range(W)):
			if flag:
				ans.append([by,bx,y,x])
			if MAP[y][x]%2 == 1:
				flag = not flag
			bx,by = x,y

print(len(ans))
for a,zu,nya,n in ans:
	print(a+1,zu+1,nya+1,n+1)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    h,w = LI()
    a = [LI() for _ in range(h)]
    r = []
    for i in range(h):
        for j in range(w-1):
            if a[i][j] % 2 == 1:
                r.append(' '.join(map(lambda x: str(x+1), [i,j,i,j+1])))
                a[i][j] -= 1
                a[i][j+1] += 1
    for i in range(h-1):
        j = w - 1
        if a[i][j] % 2 == 1:
            r.append(' '.join(map(lambda x: str(x+1), [i,j,i+1,j])))
            a[i][j] -= 1
            a[i+1][j] += 1

    return '{}\n{}'.format(len(r), '\n'.join(r))


print(main())

Solution (Python):


from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

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

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

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

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

print N
for p in ls:
    print " ".join(map(str, p))

Solution (Python):
h,w = map(int, input().split())
cells = [[c%2==1 for c in map(int, input().split())] for i in range(h)]


command = []
for i in range(h):
    for j in range(w):
        if cells[i][j]:
            if j < w-1:
                cells[i][j+1] ^= True
                command.append((i+1, j+1, i+1, j+2))
            elif i < h-1:
                cells[i+1][j] ^= True
                command.append((i+1, j+1, i+2, j+1))
print(len(command))
for c in command:
    print(*c)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

h, w = na()

b = []
for i in range(h):
    b.append(na())

hh = []
hist = []
for i in range(h):
    for j in range(w):
        c = j if i % 2 == 0 else w-1-j
        if b[i][c] % 2 == 1:
            if len(hist) == 0:
                hist.append((i,c))
            else:
                hist.append((i,c))
                for k in range(len(hist)-1):
                    hh.append((hist[k][0]+1, hist[k][1]+1, hist[k+1][0]+1, hist[k+1][1]+1))
                hist = []
        else:
            if len(hist) > 0:
                hist.append((i,c))

print(len(hh))
for u in hh:
    print(" ".join(map(str, u)))

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

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

LIST=[]

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


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


print(len(LIST))

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