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 f(i,w):
  p = i%w
  q = i//w
  if q%2 == 1:
    p = w-1-p
  return [q,p]

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

k = 0
s = []
for i in range(h*w-1):
  if  a[f(i,w)[0]][f(i,w)[1]]%2 == 1:
    k = 1-k
  if k == 1:
    s += [f(i,w)[0],f(i,w)[1],f(i+1,w)[0],f(i+1,w)[1]]
m = len(s)//4
print(m)
for i in range(m):
  print(s[4*i]+1,s[4*i+1]+1,s[4*i+2]+1,s[4*i+3]+1)

Solution (Python):
import itertools
H, W = [int(_) for _ in input().split()]
Aij = [[0] * (W + 1)] + [[0] + [int(_) for _ in input().split()] for _ in range(H)]

count = 0
result = []

for i, j in itertools.product(range(1, H + 1), range(1, W)):
    if Aij[i][j] % 2:
        count += 1
        result += ['{} {} {} {}'.format(i, j, i, j + 1)]
        Aij[i][j + 1] += 1
for i in range(1, H):
    if Aij[i][W] % 2:
        count += 1
        result += ['{} {} {} {}'.format(i, W, i + 1, W)]
        Aij[i + 1][W] += 1

print(count)
print('\n'.join(result))

Solution (Python):
import itertools
H, W = [int(_) for _ in input().split()]
Aij = [[0] * (W + 1)] + [[0] + [int(_) for _ in input().split()] for _ in range(H)]

result = []

for i, j in itertools.product(range(1, H + 1), range(1, W)):
    if Aij[i][j] % 2:
        result += [' '.join(map(str, [i, j, i, j + 1]))]
        Aij[i][j + 1] += 1
for i in range(1, H):
    if Aij[i][W] % 2:
        result += [' '.join(map(str, [i, W, i + 1, W]))]
        Aij[i + 1][W] += 1

print(len(result))
[print(_) for _ in result]

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
def nextin(nwin,prin):
    if not prin[1] == nwin[1]+1 and nwin[1] != W-1:
        return [nwin[0],nwin[1]+1]
    if not prin[1] == nwin[1]-1 and nwin[1] != 0:
        return[nwin[0],nwin[1]-1]
    else:
        return[nwin[0]+1,nwin[1]]

H, W = inpl()
HW = []
Ans = []
ctr = 0
for i in range(H):
    gyou = inpl()
    for j in gyou:
        if j%2 != 0:
            ctr += 1
    HW.append(gyou)
ctr = ctr//2
ans = 0
previn = [0,-1]
nowin = [0,0]
while ctr != 0:
    a,b = nowin
    c,d = nextin(nowin,previn)
    if HW[a][b]%2 == 1:
        HW[c][d] += 1
        if HW[c][d]%2 == 0:
            ctr -=1
        Ans.append([a+1,b+1,c+1,d+1])
    previn = [a,b]
    nowin = [c,d]
print(len(Ans))
for i in Ans:
    print(*i)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

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

            if y != H - 1:
                if field[y][-1] > 0 and field[y][-1] % 2 == 1:
                    ans.append((y + 1, W, y + 2, W))
                    field[y][-1] -= 1
                    field[y + 1][-1] += 1

        else:
            for x in range(W - 1, 0, -1):
                if field[y][x] > 0 and field[y][x] % 2 == 1:
                    ans.append((y + 1, x + 1, y + 1, x))
                    field[y][x] -= 1
                    field[y][x - 1] += 1

            if y != H - 1:
                if field[y][0] > 0 and field[y][0] % 2 == 1:
                    ans.append((y + 1, 1, y + 2, 1))
                    field[y][0] -= 1
                    field[y + 1][0] += 1

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


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

H, W = list(map(int, input().split()))
field = []
for _ in range(H):
  field.append([int(s) % 2 for s in input().split()])

q = deque()
for y in range(1, H + 1):
  if y % 2:
    xr = range(1, W + 1)
  else:
    xr = range(W, 0, -1)
  for x in xr:
    q.append((y, x))

manipulations = []
while True:
  y, x = q.popleft()
  if not len(q):
    break
  if field[y - 1][x - 1] % 2:
    manipulations.append((y, x, q[0][0], q[0][1]))
    field[y - 1][x - 1] = 0
    field[q[0][0] - 1][q[0][1] - 1] += 1

print(len(manipulations))
for man in manipulations:
  print(*man)

Solution (Python):
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]
def next(i,j):
    if i%2==0:
        if j == W-1:
            return i+1,j
        else:
            return i,j+1
    else:
        if j == 0:
            return i+1,j
        else:
            return i,j-1
ans = []
i,j = 0,0
while True:
    i_,j_ = next(i,j)
    if i_ == H:
        break
    if a[i][j]%2==1:
        a[i][j] -= 1
        a[i_][j_] += 1
        ans.append('{} {} {} {}'.format(i+1,j+1,i_+1,j_+1))
    i,j = i_,j_
print(len(ans))
for s in ans:
    print(s)

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

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

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

Solution (Python):


from sys import stdin


ns = lambda: stdin.readline()[:-1] 
ni = lambda: int(stdin.readline()) 
na = lambda: list(map(int, stdin.readline().split())) 

H, W = na()

a_list = []
for _ in range(H):
    a_list.append(na())
a_list.append([0]*W)  

operation = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W-1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x+1] += 1
                operation.append([y+1, x+1, y+1, x+2])
        if a_list[y][W-1] % 2 == 1:
            a_list[y+1][W-1] += 1
            operation.append([y+1, W, y+2, W])
    else:
        for x in range(W-1, 0, -1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x-1] += 1
                operation.append([y+1, x+1, y+1, x])
        if a_list[y][0] % 2 == 1:
            a_list[y+1][0] += 1
            operation.append([y+1, 1, y+2, 1])

if operation != [] and operation[-1][2] == H+1:
    operation.pop()


print(len(operation))
for op in operation:
    print(op[0], op[1], op[2], op[3])

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

field=[[-2]*(W+2)]
for _ in range(H):
    field.append([-1] + list(map(int,input().split())) + [-1])
field.append([-1]*(W+2))


result=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if(field[i][j]%2==1):
            if(j!=W):
                field[i][j]-=1
                field[i][j+1]+=1
                result.append([i,j,i,j+1])
            elif(i!=H):
                field[i][j]-=1
                field[i+1][j]+=1
                result.append([i,j,i+1,j])

print(len(result))
for youso in result:
    print(" ".join(list(map(str,youso))))

Solution (Python):
h, w = map(int, raw_input().split())
arr = []

for i in range(h):
    row = map(int, raw_input().split())
    arr.append(row)
num = 0
move = []
for i in range(h):
    for j in range(w-1):
        if arr[i][j] % 2 == 1:
            arr[i][j + 1] += 1
            num += 1
            move.append([i + 1, j + 1, i + 1, j + 2])
    if i < h-1:
        if arr[i][w - 1] % 2 == 1:
            arr[i + 1][w - 1] += 1
            num += 1
            move.append([i + 1, w, i + 2, w])
print num
for i in move:
    for j in i:
        print j,
    print

Solution (Python):
H,W=(int(i) for i in input().split(' '))
a=[]
log=[]
n=0
for h in range(H):
  a.append([int(i) for i in input().split(' ')])
for h in range(H)[::2]:
  for w in range(W-1):
    if a[h][w]%2!=0:
      a[h][w]-=1
      a[h][w+1]+=1
      log.append([h+1,w+1,h+1,w+2])
      n+=1
  if h+1 != H:
    if a[h][W-1]%2!=0:
      a[h][W-1]-=1
      a[h+1][W-1]+=1
      log.append([h+1,W,h+2,W])
      n+=1
  else:
    break
  for w in range(1,W)[::-1]:
    if a[h+1][w]%2!=0:
      a[h+1][w]-=1
      a[h+1][w-1]+=1
      log.append([h+2,w+1,h+2,w])
      n+=1
  if h+2 != H:
    if a[h+1][0]%2!=0:
      a[h+1][0]-=1
      a[h+2][0]+=1
      log.append([h+2,1,h+3,1])
      n+=1
print(n)
for data in log:
  print('{0[0]} {0[1]} {0[2]} {0[3]}'.format(data))

Solution (Python):



def solve(H, W, matrix):
    ugoki = []

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

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

    return ugoki


if __name__ == "__main__":
    H, W = map(int, input().split(" "))
    matrix = [list(map(int, input().split(" "))) for i in range(H)]
    ugoki = solve(H, W, matrix)
    print(len(ugoki))
    for mov in ugoki:
        print("{} {} {} {}".format(mov[0], mov[1], mov[2], mov[3]))

Solution (Python):
def solution(a):
    foo = []
    r = len(a)
    c = len(a[0])
    for i in xrange(r):
        for j in xrange(c):
            if a[i][j] & 1 == 1:
                if j != c - 1:
                    foo.append((i + 1, j + 1, i + 1, j + 2))
                    a[i][j] -= 1
                    a[i][j + 1] += 1
                elif i != r - 1:
                    foo.append((i + 1, j + 1, i + 2, j + 1))
                    a[i][j] -= 1
                    a[i + 1][j] += 1
    return foo

def main():
    r, c = [int(i) for i in raw_input().strip().split()]
    a = [[int(j) for j in raw_input().strip().split()] for i in xrange(r)]
    foo = solution(a)
    print(len(foo))
    for row in foo:
        print('%d %d %d %d' % row)

if __name__ == '__main__':
    main()

Solution (Python):

a,b=input().split()
S=0
T=0
echo=[]
for x in range(int(a)):
    S+=1
    l=[int(x) for x in input().split()]
    for c in range(int(b)-1):
        if l[c]%2==1:
            echo.append(str(str(S)+" "+str(c+1)+" "+str(S)+" "+str(c+2)))
            l[c]=l[c]-1
            l[c+1]=l[c+1]+1
    
    
    if (sum(l)+T)%2==1 and x+1 < int(a):
        echo.append(str(str(S)+" "+str(b)+" "+str(S+1)+" "+str(b)))
        T=1
    else:
        T=0
print(len(echo))
for y in echo:
    print(y)

Solution (Python):
H,W=list(map(int,input().split()))
A=[]
for i in range(H):
    A.append(list(map(int,input().split())))
sum_=0
ans=[]
for i,aline in enumerate(A):
    for j in range(W-1):
        if aline[j]%2==1:
            aline[j+1]+=1
            sum_+=1
            ans.append('{0} {1} {2} {3}'.format(i+1,j+1,i+1,j+2))
for i,aline in enumerate(A[:-1]):
    if aline[W-1]%2==1:
        A[i+1][W-1]+=1
        sum_+=1
        ans.append(('{0} {1} {2} {3}'.format(i+1,W,i+2,W)))
print(sum_)
for x in ans:
    print(x)

Solution (Python):
import sys
from fractions import gcd


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

    ans = []

    for i in range(h):
        if i % 2 == 0:
            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
        else:
            for j in range(w - 1, 0, -1):
                if a[i][j] % 2 == 1:
                    ans.append((i+1, j+1, i+1, j))
                    a[i][j-1] += 1
            
            if i != h - 1 and a[i][0] % 2 == 1:
                ans.append((i+1, 1, i+2, 1))
                a[i+1][0] += 1
    
    print(len(ans))
    for ansi in ans:
        print(*ansi)


if __name__ == '__main__':
    main()

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:
            N += 1
            ans.append((h, w, h, w + 1))
            G[h][w + 1] += 1
            G[h][w] -= 1

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

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

Solution (Python):
import sys
def 解():
    iH, iW = [int(x) for x in input().split()]
    iCount = 0
    iSum = 0
    aHW = [[int(x) % 2 for x in sLine.split() ] for sLine in  sys.stdin.readlines()]
    aRoute = []
    aTe = []
    aMove = []


    for i in range(iH):
        if i % 2 == 0:
            for j in range(iW):
                aRoute.append((i,j))
        else:
            for j in range(iW-1,-1,-1):
                aRoute.append((i,j))
    iF = 0
    for y,x in aRoute:
        iV = aHW[y][x]
        if iV and iF == 0:
            aMove.append((y+1,x+1))
            iF = 1
        elif iV == 0 and iF :
            aMove.append((y+1,x+1))
        elif iV and iF :
            aMove.append((y+1,x+1))
            for i in range(len(aMove)-1):
                aM = (aMove[i],aMove[i+1])
                aTe.append(aM)
            aMove = []
            iF = 0
    aOut=[]
    aOut.append(str(len(aTe)))
    for aE in aTe:
        aOut.append("{} {} {} {}".format(aE[0][0],aE[0][1],aE[1][0],aE[1][1]))
    print("\n".join(aOut))
解()

Solution (Python):
import sys
def 解():
    iH, iW = [int(x) for x in input().split()]
    iCount = 0
    iSum = 0
    aHW = [[int(x) % 2 for x in sLine.split() ] for sLine in  sys.stdin.readlines()]
    aRoute = []
    aTe = []
    aMove = []


    for i in range(iH):
        if i % 2 == 0:
            for j in range(iW):
                aRoute.append((i,j))
        else:
            for j in range(iW-1,-1,-1):
                aRoute.append((i,j))
    iF = 0
    for y,x in aRoute:
        iV = aHW[y][x]
        if iV and iF == 0:
            aMove.append((y+1,x+1))
            iF = 1
        elif iV == 0 and iF :
            aMove.append((y+1,x+1))
        elif iV and iF :
            aMove.append((y+1,x+1))
            for i in range(len(aMove)-1):
                aM = (aMove[i],aMove[i+1])
                aTe.append(aM)
            aMove = []
            iF = 0

    print(len(aTe))
    for aE in aTe:
        print(aE[0][0],aE[0][1],aE[1][0],aE[1][1])
解()

Solution (Python):



def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    H, W = get_ints()
    a = []
    for _ in range(H):
        a.append(get_ints())

    order = []
    for h in range(H):
        s, e, d = (0, W, +1) if h % 2 == 0 else (W - 1, -1, -1)
        w = s
        while w != e:
            order.append((h, w))
            w += d

    seq = []
    for (h, w), (nh, nw) in zip(order[:-1], order[1:]):
        if a[h][w] % 2 == 1:
            a[h][w] -= 1
            a[nh][nw] += 1
            seq.append((h + 1, w + 1, nh + 1, nw + 1))

    print(len(seq))
    for vs in seq:
        print(*vs)


if __name__ == '__main__':
    main()

Solution (Python):

def next(i, j):
    nextI = i
    nextJ = j
    if i % 2 == 0:
        nextJ = j + 1
    else:
        nextJ = j - 1
    if nextJ < 0 or nextJ >= W:
        nextJ = j
        nextI = i+1
    return nextI, nextJ


H, W = [int(x) for x in input().split()]
a = []
for n in range(0, H):
    a.append([int(x) for x in input().split()])


isFinded = (a[0][0] % 2 == 1)
cI, cJ = 0, 0

list = []
for n in range(0, H*W-1):
    nextI, nextJ = next(cI, cJ)
    if (isFinded):
        
        list.append("{} {} {} {}".format(cI+1, cJ+1, nextI+1, nextJ+1))
    if (a[nextI][nextJ] % 2 == 1):
        isFinded = not (isFinded)
    cI = nextI
    cJ = nextJ

print(len(list))
for l in list:
    print(l)

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

x = 0

for i in range(h):
	for j in range(w):
		if a[i][j]%2==1 and i!=h-1:
			a[i][j] -=1
			a[i+1][j] +=1
			x +=1
		elif a[i][j]%2==1 and j!=w-1:
			a[i][j] -=1
			a[i][j+1] +=1	
			x +=1

print(x)

for i in range(h):
	for j in range(w):
		if b[i][j]%2==1 and i!=h-1:
			b[i][j] -=1
			b[i+1][j] +=1
			print(i+1,j+1,i+2,j+1)

		elif b[i][j]%2==1 and j!=w-1:
			b[i][j] -=1
			b[i][j+1] +=1	
			print(i+1,j+1,i+1,j+2)

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

x = 0

for i in range(h):
	for j in range(w):
		if a[i][j]%2==1 and i!=h-1:
			a[i][j] = a[i][j]-1
			a[i+1][j] = a[i+1][j]+1
			x +=1
		elif a[i][j]%2==1 and j!=w-1:
			a[i][j] = a[i][j]-1
			a[i][j+1] = a[i][j+1]+1	
			x +=1

print(x)

for i in range(h):
	for j in range(w):
		if b[i][j]%2==1 and i!=h-1:
			b[i][j] = b[i][j]-1
			b[i+1][j] = b[i+1][j]+1
			print(i+1,j+1,i+2,j+1)

		elif b[i][j]%2==1 and j!=w-1:
			b[i][j] = b[i][j]-1
			b[i][j+1] = b[i][j+1]+1	
			print(i+1,j+1,i+1,j+2)

Solution (Python):
h, w = list(map(int, input().split()))
a = [list(map(lambda x: int(x) & 1, input().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w-1):
        if a[i][j] & 1 == 1:
            ans.append(' '.join([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][-1] & 1 == 1:
        ans.append(' '.join([str(i+1), str(w), str(i+2), str(w)]))
        a[i+1][-1] += 1
print(len(ans))
for s in ans:
    print(s)

Solution (Python):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
z=[]
for i in range(w):
  if i%2==0:
    for j in range(h):
      z.append([j,i])
  else:
    for j in range(h):
      z.append([h-j-1,i])
count=0
ans=[]
for i,(y,x) in enumerate(z):
  if a[y][x]%2!=0 and i<len(z)-1:
    count+=1
    ans.append(i)
    a[z[i+1][0]][z[i+1][1]]+=1
print(count)
for i in ans:
  print(z[i][0]+1,z[i][1]+1,z[i+1][0]+1,z[i+1][1]+1)

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

cnt = 0

res = []

for i in range(h):
    for j in range(w):
        if i == h - 1 and j == w - 1:
            break

        if a[i][j] % 2 == 1:
            cnt += 1
            a[i][j] -= 1
            if j < w - 1:
                a[i][j + 1] += 1
                res.append((i, j, i, j + 1))
            elif j == w - 1:
                a[i + 1][j] += 1
                res.append((i, j, i + 1, j))

print(cnt)
for tpl in res:
    o, p, q, r = tpl
    print(o + 1, p + 1, q + 1, r + 1)

Solution (Python):
from sys import stdin

H, W = [int(i) for i in stdin.readline().rstrip().split()]
a = [[int(i) for i in stdin.readline().rstrip().split()] for _ in range(H)]

ans = []
for row in range(H):
    for col in range(W):
        if row == H - 1 and col == W - 1:
            break

        if a[row][col] % 2 == 1 and col < W - 1:
            ans.append([row + 1, col + 1, row + 1, col + 1 + 1])
            a[row][col] -= 1
            a[row][col + 1] += 1
        elif a[row][col] % 2 == 1 and col == W - 1:
            ans.append([row + 1, col + 1, row + 1 + 1, col + 1])
            a[row][col] -= 1
            a[row + 1][col] += 1

print(len(ans))
for t, u, s, v in ans:
    print(t, u, s, v)

Solution (Python):
H, W = map(int, input().split())
coin_from_upper_row = 0
hand = []
for i in range(H):
    Ai = list(map(int, input().split()))
    for j in range(W):
        if j == W-1:
            Ai[j] += coin_from_upper_row
            coin_from_upper_row = 0
        if not Ai[j] % 2:
            continue
        if j < W-1:
            hand.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
            Ai[j+1] += 1
        else:
            if i == H-1:
                break
            hand.append("{} {} {} {}".format(i+1, j+1, i+2, j+1))
            coin_from_upper_row = 1

N = len(hand)
print(N)
for h in hand:
    print(h)

Solution (Python):
H, W = map(int, input().split())
a = []
operation = []
for _ in range(H):
    a.append(list(map(int, input().split())))
root = []
for i in range(H):
    for j in range(W):
        if i % 2 == 0:
            root.append((i, j))
        else:
            root.append((i, W - j - 1))
for r in range(len(root) - 1):
    y, x = root[r]
    if a[y][x] % 2 == 1:
        a[y][x] -= 1
        a[root[r+1][0]][root[r+1][1]] += 1
        operation.append((y + 1, x + 1, root[r+1][0] + 1, root[r+1][1] + 1))
print(len(operation))
for o in operation:
    print(*o)

Solution (Python):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, _i.strip().split(" "))) for _i in ins[1:]]
    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()
    h, w = map(int, line.split(" "))
    ins = [input() for _ in range(h)]
    ins.insert(0, line)
    print(solve("\n".join(ins)))

Solution (Python):
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
result = list()
for i in range(H):
    for j in range(W):
        if a[i][j]%2 == 1 and j+1 < W:
            a[i][j] -= 1
            a[i][j+1] += 1
            result.append((i+1, j+1, i+1, j+2))
        if a[i][j]%2 == 1 and j == W-1 and i+1<H:
            a[i][j] -= 1
            a[i+1][j] += 1
            result.append((i+1,j+1,i+2,j+1))
print(len(result))
for y, x, y_, x_ in result:
    print('{} {} {} {}'.format(y, x, y_, x_))

Solution (Python):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].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 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 solve(string):
    h, w = map(int, input().split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, input().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__':
    print(solve(""))

Solution (Python):
h, w = map(int, input().split(" "))
a = [list(map(lambda x: int(x) % 2 == 1, input().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)))
print("\n".join(move))

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

ans = []
cnt = 0
for h in range(H):
    for w in range(W):
        if metrics[h][w] % 2 != 0:
            metrics[h][w] -= 1
            if w + 1 < W:
                metrics[h][w + 1] += 1
                ans.append([h + 1, w + 1, h + 1, w + 2])
                cnt += 1
            elif h + 1 < H:
                metrics[h + 1][w] += 1
                ans.append([h + 1, w + 1, h + 2, w + 1])
                cnt += 1
print(cnt)
for row in ans:
    print(*row)

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []

for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))

Solution (Python):
import numpy as np
H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(map(int, input().split())))
rd = [(0,1,0), (1,0,1)]
move_records = []
if H != 1 or W != 1:
    for i in range(H):
        for j in range(W):
            if field[i][j] % 2 == 0:
                continue
            if i == H-1 and j == W-1:
                continue
            if i == H-1 and j == W-2:
                
                if (field[H-1][W-1] + field[H-1][W-2]) % 2 != 0:
                    continue
                else:
                    field[H-1][W-2] -= 1
                    field[H-1][W-1] += 1
                    move_records.append([i+1,j+1,i+1,j+2])
            elif j != W-1:
                field[i][j] -= 1
                field[i][j+1] += 1
                move_records.append([i+1,j+1,i+1,j+2])
            else:
                field[i][j] -= 1
                field[i+1][j] += 1
                move_records.append([i+1,j+1,i+2,j+1])
M = len(move_records)
print(M)
for i in range(M):
    print('{} {} {} {}'.format(move_records[i][0],
                               move_records[i][1],
                               move_records[i][2],
                               move_records[i][3]))

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

ans = []
cnt = 0
for h in range(H):
    for w in range(W):
        if metrics[h][w] % 2 != 0:
            metrics[h][w] -= 1
            if w + 1 < W:
                metrics[h][w + 1] += 1
                ans.append([h + 1, w + 1, h + 1, w + 2])
                cnt += 1
            elif h + 1 < H:
                metrics[h + 1][w] += 1
                ans.append([h + 1, w + 1, h + 2, w + 1])
                cnt += 1
print(cnt)
for row in ans:
    print(*row)

Solution (Python):
H,W = map(int,input().split())
route = []
for i in range(1,H+1):
    line = input().split()
    line = [int(j) for j in line]
    if i%2 != 0:
        for j in range(1,W+1):
            route.append([i,j,line[j-1]])
    else:
        for j in range(W,0,-1):
            route.append([i,j,line[j-1]])
res = []
for i in range(H*W):
    if route[i][2] %2 != 0 and i != H*W -1:
        route[i][2] -=1
        route[i+1][2] +=1
        res.append([route[i][0],route[i][1],route[i+1][0],route[i+1][1]])
print(len(res))
for i in res:
    print(' '.join(map(str,i)))