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 = map(int,input().split())
a=[]
N2=0
for i in range(H):
    b=[int(i) for i in input().split()]
    for j in range(W):
        if b[j]%2==1:
            N2+=1
    a.append(b)
if N2%2==1:
    N2-=1
N=0
N3=0
idou=1
if W==1:
    idou=2
c=0
i=0
j=0
s=[]
for k in range(H*W):
    if N3==N2:
        break
    if idou==1:
        if a[i][j]%2==1:
            N+=1
            s.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            a[i][j+1]+=1
            a[i][j]-=1
            if a[i][j+1]%2==0:
                N3+=2
        j+=1
        if j==W-1-c:
            idou=2
    elif idou==2:
        if a[i][j]%2==1:
            N+=1
            s.append(str(i+1)+" "+str(j+1)+" "+str(i+2)+" "+str(j+1))
            a[i+1][j]+=1
            a[i][j]-=1
            if a[i+1][j]%2==0:
                N3+=2
        i+=1
        if i==H-1-c:
            idou=3
    elif idou==3:
        if a[i][j]%2==1:
            N+=1
            s.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j))
            a[i][j-1]+=1
            a[i][j]-=1
            if a[i][j-1]%2==0:
                N3+=2
        j-=1
        if j==c:
            idou=4
    elif idou==4:
        if a[i][j]%2==1:
            N+=1
            s.append(str(i+1)+" "+str(j+1)+" "+str(i)+" "+str(j+1))
            a[i-1][j]+=1
            a[i][j]-=1
            if a[i-1][j]%2==0:
                N3+=2
        i-=1
        if i==c+1:
            idou=1
            c+=1
print(N)
for i in range(N):
    print(s[i])

Solution (Python):
import numpy as np
h,w = list(map(int, input().split()))
xs = []
for _ in range(h):
    xs.append(list(map(int, input().split())))


def move_yoko(k,x):
    temp = np.where(x[k] == 1)[0]
    ms = []
    if len(temp)%2 == 0:
        for j in range(int(len(temp)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
                ms.append([k,a+i,k,a+1+i])
        x[k] = 0
    else:
        for j in range(int((len(temp)-1)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
                ms.append([k,a+i,k,a+1+i])
        a = temp[-1]
        b = w - 1
        for i in range(b - a):
            ms.append([k,a+i,k,a+1+i])
        x[k] = 0
        x[k,-1] = 1
    return ms,x

def move_tate(k,x):
    temp = np.where(x[:,k] == 1)[0]
    ms = []
    if len(temp)%2 == 0:
        for j in range(int(len(temp)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):

                ms.append([a+i,k,a+1+i,k])
        x[:,k] = 0
    else:
        for j in range(int((len(temp)-1)/2)):
            a = temp[2*j]
            b = temp[2*j+1]
            for i in range(b - a):
                ms.append([a+i,k,a+1+i,k])
                
        a = temp[-1]
        b = h - 1
        for i in range(b - a):
            ms.append([a+i,k,a+1+i,k])
        x[:,k] = 0
        x[-1,k] = 1
    return ms,x

x = np.vstack(xs)
x = x%2

mss = []
for k in range(h):
    ms, x = move_yoko(k,x)
    mss += ms
ms, x = move_tate(w-1,x)
mss += ms
ms = mss

import sys
print(len(ms))
for a in ms:
    for k in range(len(a)):
        if k == len(a)-1:
            sys.stdout.write('{}'.format(a[k] + 1))
        else:
            sys.stdout.write('{} '.format(a[k] + 1))
    sys.stdout.write('\n')

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

def judge(t):
    if int(t)%2 == 1:
        return "d"
    else:
        return int(t)

field = [["n" for i in range(w+1)]]
for i in range(1,h+1):
    field.append(list(map(judge,input().split(" "))))
    field[i] = ["n"] + field[i]
d_num = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if field[i][j] == "d":
            d_num += 1

ans_a = []
ans_a2 = []
pri = False
for i in range(1,h+1):
    if i%2 == 1:
        dir_j = [i+1 for i in range(w)]
    else:
        dir_j = [w-i for i in range(w)]
    for j in dir_j:
        if field[i][j] == "d" and d_num >= 2:
            if pri:
                pri = False
                ans_a.append([i,j])
                for k in range(len(ans_a)-1):
                    ans_a2.append(ans_a[k]+ans_a[k+1])
                ans_a = []
            else:
                pri = True
        if pri:
            ans_a.append([i,j])

print(len(ans_a2))
for i in ans_a2:
    print(" ".join(list(map(str,i))))

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

if h==1 and w==1 :
    print(0)
else:


    aa=0
    C=[]
    ha=0
    s=1
    a=0
    b=0
    for i in range(h*w):
        if A[a][b]%2==1 :
            ha=(ha+1)%2
        if ha==1:
            if b+s<w and b+s>=0 :
                C.append([a,b,a,b+s])
            elif a<h :
                C.append([a,b,a+1,b])
        if ha==0 :
            aa=len(C)

        if b+s<w and b+s>=0 :
            b+=s
        else:
            a+=1
            s = -s

            
    print(aa)

    for i in range(aa):
        print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))

Solution (Python):
line = input().split()
H = int(line[0])
W = int(line[1])

array = []

def get_ij(index):
    i = index // W
    if (i % 2 == 0):
        j = index % W
    else:
        j = W - index % W - 1
    return i+1, j+1


for i in range(H):
    if i % 2 == 0:
        array.extend([int(a) for a in input().split()])
    else:
        array.extend(reversed([int(a) for a in input().split()]))

move_index = []
previous_move = False
for i, a in enumerate(array[:-1]):
    even = a % 2 == 0

    if previous_move and even:
        
        move_index.append(i)
        previous_move = True
    elif not previous_move and not even:
        
        move_index.append(i)
        previous_move = True
    else:
        previous_move = False

print(len(move_index))

for i in move_index:
    ind_from = get_ij(i)
    ind_to = get_ij(i+1)
    print("{} {} {} {}".format(ind_from[0], ind_from[1], ind_to[0], ind_to[1]))

Solution (Python):

from pprint import pprint
h,w = map(int, input().split())
m = []
for _ in range(h):
    line = [int(x) for x in input().split()]
    m.append(line)

ret = []
for i in range(h):
    j = 0
    while j<w:
        if m[i][j]%2==1:
            jj = j+1
            while jj<w and m[i][jj]%2==0:
                jj += 1
            if jj==w:
                jj = w-1
            for dj in range(j,jj):
                ret.append([i,dj,i,dj+1])
            if m[i][jj]%2==1:
                m[i][j] -= 1
                m[i][jj] += 1
            elif jj == w-1:
                m[i][j] -= 1
                m[i][jj] += 1
        j += 1

i = 0
while i<h:
    if m[i][w-1]%2==1:
        ii = i+1
        while ii<h and m[ii][w-1]%2==0:
            ii += 1
        if ii==h:
            ii = h-1
        for di in range(i,ii):
            ret.append([di,w-1,di+1,w-1])
        if m[ii][w-1]%2==1:
            m[i][w-1] -= 1
            m[ii][w-1] += 1
    i += 1

print(len(ret))
for r in ret:
    print(r[0]+1,r[1]+1,r[2]+1,r[3]+1)

Solution (Python):
H,W = map(int,input().split())
a = []
for i in range(H):
    a.append(list(map(int,input().split())))
if H%2 == 1:
    endGrid=(H-1,W-1)
else:
    endGrid=(H-1,0)

answer = []
def move(i,j):
    if (i,j) == endGrid:
        return()
    if i%2 == 0:
        if j<W-1:
            
            answer.append(" ".join(map(str,[i+1,j+1,i+1,j+2])))
        else:
            answer.append(" ".join(map(str,[i+1,j+1,i+2,j+1])))
            
    else:
        if j>0:
            answer.append(" ".join(map(str,[i+1,j+1,i+1,j])))
            
        else:
            answer.append(" ".join(map(str,[i+1,j+1,i+2,j+1])))
            
            
evenraw = True
movingOdd = False
for i in range(H):
    if evenraw:
        j = 0
        while j < W:
            
            if movingOdd:
                if a[i][j]%2 == 0:
                    move(i,j)
                else:
                    movingOdd = False
            else:
                if a[i][j]%2 == 1:
                    move(i,j)
                    movingOdd = True
            j += 1
        evenraw = False
    else:
        j = W-1
        while j >= 0:
            
            if movingOdd:
                if a[i][j]%2 == 0:
                    move(i,j)
                else:
                    movingOdd = False
            else:
                if a[i][j]%2 == 1:
                    move(i,j)
                    movingOdd = True
            j -= 1
        evenraw = True


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

Solution (Python):

import copy

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

a_cp = copy.deepcopy(a)

itr = 0
for i in range(H):
    for j in range(W-1):
        if a_cp[i][j]%2==1:
            itr+=1
            a_cp[i][j]-=1
            a_cp[i][j+1]+=1

for i in range(H-1):
    j = W-1
    if a_cp[i][j]%2==1:
        itr+=1
        a_cp[i][j]-=1
        a_cp[i+1][j]+=1

print(itr)
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):
    j = W-1
    if a[i][j]%2==1:
        print(i+1,j+1,i+2,j+1)
        a[i][j]-=1
        a[i+1][j]+=1

Solution (Python):
import copy


h, w = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(h)]
b = copy.deepcopy(a)
buf = 0
count = 0
for i,ai in enumerate(a):
    for j,aij in enumerate(ai):
        if aij % 2 != 0:
            buf = 1
            if i == h-1 and j == w-1:
                continue
            elif j != w-1:
                count += 1
                a[i][j+1] += 1
                
            else:
                count += 1
                a[i+1][j] += 1
                
print(count)
buf = 0
count = 0
for i,ai in enumerate(b):
    for j,aij in enumerate(ai):
        if aij % 2 != 0:
            buf = 1
            if i == h-1 and j == w-1:
                continue
            elif j != w-1:
                count += 1
                b[i][j+1] += 1
                print(i+1,j+1,i+1,j+2)
            else:
                count += 1
                b[i+1][j] += 1
                print(i+1,j+1,i+2,j+1)

Solution (Python):

"""
Created on Sat Sep  8 22:00:58 2018

@author: maezawa
"""
h, w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(list(map(int, input().split())))
    


pos = [1, 1]
route = []
for i in range(h):
    if i%2 == 0:
        route.extend([[i+1,j] for j in range(1,w+1)])
    else:
        route.extend([[i+1,j] for j in reversed(range(1,w+1))])
cnt = 0
move =[]
i = 0
while i<w*h-1:
    if a[pos[0]-1][pos[1]-1]%2 == 0:
        i += 1
        pos[0] = route[i][0]
        pos[1] = route[i][1]
        continue
    else:
        a[pos[0]-1][pos[1]-1] -= 1
        y1 = pos[0]
        x1 = pos[1]
        i += 1
        pos[0] = route[i][0]        
        pos[1] = route[i][1]         
        a[pos[0]-1][pos[1]-1] += 1
        y2 = pos[0]
        x2 = pos[1]
        move.append([y1,x1,y2,x2])
        cnt += 1
  
print(cnt)
for i in range(len(move)):
    print(*move[i])

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

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

flag = False 
ans = []
for y in range(H):
	if y%2 == 0:
		xx = range(W)
	else:
		xx = reversed(range(W))
	for x in xx:
		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):
H, W = map(int, input().split())
a = []
for _ in range(H):
    a.append(list(map(int, input().split())))

ans = []

i = 0
flag = False

while i < H * W:
    row = i // W
    if row % 2 == 0:
        col = i % W
    else:
        col = W - i % W - 1

    if a[row][col] % 2 == 1 and flag == False:
        flag = True
    elif a[row][col] % 2 == 1 and flag == True:
        flag = False

    if flag == True:
        j = i + 1
        if j == H * W:
            break
        row_ = j // W
        if row_ % 2 == 0:
            col_ = j % W
        else:
            col_ = W - j % W - 1
        ans.append(str(row+1)+' '+str(col+1)+' '+str(row_+1)+' '+str(col_+1))

    i += 1

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

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

a = [[int(i) for i in input().split()] for _ in range(h)]

total = 0

ans = []

for i,row in enumerate(a):
    for j,cell in enumerate(row):
        if(cell % 2 == 0):
            continue
        
        if(i == h - 1 and j == w -1):
            break
        
        if(j != w - 1):
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])
            total += 1
        elif(i != h - 1):
            a[i+1][j] += 1
            ans.append([i+1,j+1,i+2,j+1])
            total += 1

        
print(total)

for a in ans:
    print(*a)

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-1):
		if a[i][j] % 2 == 1:
			a[i][j+1] += 1
			ans.append([i+1,j+1,i+1,j+2])

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

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

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

dictate_list = []
mini_dictate_list = []
Flag= False
for i in range(H):
    for j in range(W):
        if i%2==0:
            if a[i][j]%2==1:
                if Flag:
                    Flag=False
                    dictate_list.append(mini_dictate_list)
                    mini_dictate_list = []
                else:
                    Flag=True
            if Flag:
                if j!=W-1:
                    mini_dictate_list.append(str(i+1) + " " +str(j+1) + " " + str(i+1) + " " + str(j+2))
                elif i!=H-1:
                    mini_dictate_list.append(str(i+1) + " " +str(j+1) + " " + str(i+2) + " " + str(j+1))


                    
        else:
            if a[i][W-j-1]%2==1:
                if Flag:
                    Flag=False
                    dictate_list.append(mini_dictate_list)
                    mini_dictate_list = []
                else:
                    Flag=True
            if Flag:
                if j!=W-1:
                    mini_dictate_list.append(str(i+1) + " " +str(W-j) + " " + str(i+1) + " " + str(W-j-1))
                elif i!=H-1:
                    mini_dictate_list.append(str(i+1) + " " +str(W-j) + " " + str(i+2) + " " + str(W-j))


new_dictate_list = []

for mini in dictate_list:
    for dic in mini:
        new_dictate_list.append(dic)            


N=len(new_dictate_list)
print N
for d in new_dictate_list:
    print d

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

ans = []

for hi in range(h):
  for wi in range(w):
    y = hi
    if hi % 2:
      x = w - 1 - wi
    else:
      x = wi
    if a[y][x] % 2 and not (wi == w-1 and hi == h-1):
      a[y][x] -= 1
      if wi == w-1:
        a[y+1][x] += 1
        ans.append([y+1, x+1, y+1+1, x+1])
      elif hi % 2:
        a[y][x - 1] += 1
        ans.append([y+1, x+1, y+1, x-1+1])
      else:
        a[y][x + 1] += 1
        ans.append([y+1, x+1, y+1, x+1+1])
print(len(ans))
for an in ans:
  print(*an)

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

ma = []
swap = []

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

for i in range(H):
    row = ma[i]
    for j in range(len(row)):
        coins = int(row[j])
        if coins%2 == 1:
            if j == len(row)-1:
                if i == H-1:
                    break
                swap.append([i+1, j+1, i+2, j+1])
                ma[i+1][j] += 1
            else:
                swap.append([i+1, j+1, i+1, j+2])
                ma[i][j+1] += 1
        
print(len(swap))
for w in swap:
    z = [str(u) for u in w]
    print(" ".join(z))

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


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

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

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

Solution (Python):
def run(h, w, a):
    move = []
    for i in range(h):
        if i % 2 == 0:
            for j in range(w):
                if a[i][j] % 2 == 1:
                    if j < w-1:
                        move.append([i+1, j+1, i+1, j+2])
                        a[i][j] -= 1
                        a[i][j+1] += 1
                    elif i < h-1:
                        move.append([i+1, j+1, i+2, j+1])
                        a[i][j] -= 1
                        a[i+1][j] += 1
        else:
            for j in range(w-1, -1, -1):
                if a[i][j] % 2 == 1:
                    if j > 0:
                        move.append([i+1, j+1, i+1, j])
                        a[i][j] -= 1
                        a[i][j-1] += 1
                    elif i < h-1:
                        move.append([i+1, j+1, i+2, j+1])
                        a[i][j] -= 1
                        a[i+1][j] += 1
    return move


def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(list(map(int, input().split())))
    move = run(h, w, a)
    print(len(move))
    for mv in move:
        mv = map(str, mv)
        print(' '.join(mv))


if __name__ == '__main__':
    main()

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

Solution (Python):
H,W=map(int,input().split())
ans=[]
flag=False
for i in range(H):
    a=list(map(int,input().split()))
    if i%2==0:
        if flag==True:
            a[0]+=1
        for j in range(W):
            if j!=W-1:
                if a[j]%2==1:
                    a[j+1]+=1
                    ans.append([i+1,j+1,i+1,j+2])
            elif i!=H-1:
                if a[j]%2==1:
                    flag=True
                    ans.append([i+1,j+1,i+2,j+1])
                else:
                    flag=False
                    
    else:
        if flag==True:
            a[W-1]+=1
        for j in range(W):
            if j!=W-1:
                if a[W-1-j]%2==1:
                    a[W-1-j-1]+=1
                    ans.append([i+1,W-j,i+1,W-j-1])
            elif i!=H-1:
                if a[0]%2==1:
                    flag=True
                    ans.append([i+1,1,i+2,1])
                else:
                    flag=False

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

Solution (Python):
def main():
    H, W = map(int, raw_input().split())
    a = []
    result = []
    for i in range(H):
        a.append(map(int, raw_input().split()))
    
    for i in range(H):
        for j in range(W):
            if a[i][j] %2 == 0:
                continue
            else:
                
                if j + 1 < W:
                    result.append([i+1,j+1,i+1,j+2])
                    a[i][j] = a[i][j]-1
                    a[i][j+1] = a[i][j+1]+1
                
                elif j+1 == W and i+1 < H:
                    result.append([i+1,j+1,i+2,j+1])
                    a[i][j] = a[i][j]-1
                    a[i+1][j] = a[i+1][j]+1
                
                    
                    
                    
    print(len(result))
    for i in range(len(result)):
        for j in range(len(result[i])):
            if j == len(result[i]) - 1:
                print(result[i][j])
            else:
                print(result[i][j]),

if __name__ == '__main__':
    main()

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

ans = []
x = -1
for i in range(H):
    x = x * (-1)
    l, r, d = (0, W, 1) if i % 2 == 0 else (W-1, -1, -1)
    for j in range(l, r, d):
        
        if A[i][j] % 2 == 0:
            continue
        if x == 1 and i == H - 1 and j == W - 1:
            continue
        if x == -1 and i == H - 1 and j == 0:
            continue
        
        if not(j + x < 0 or j + x >= W):
            A[i][j] = A[i][j] - 1
            A[i][j + x] = A[i][j + x] + 1
            ans.append((i, j, i, j+x))
        else :
            A[i][j] = A[i][j] - 1;
            A[i+1][j] = A[i+1][j] + 1
            ans.append((i, j, i+1, j));


print (len(ans))
for y, x, b, a in ans:
    print (y+1, x+1, b+1, a+1)

Solution (Python):



def surround_odd_check(board_cond, r, c):
    try:
        right = board_cond[r][c+1] % 2
    except IndexError:
        right =2

    try:
        down = board_cond[r+1][c] % 2
    except IndexError:
        down = 2

    return [right, down]


if __name__ == '__main__':
    H, W = map(int, input().split())

    board = [list(map(int, input().split())) for i in range(H)]
    ctr = 0
    moves = []
    odd_counter = 0
    for i in range(H):
        for j in range(W):
            if board[i][j] % 2 == 1:
                odd_counter += 1

    for i in range(H):
        for j in range(W):
            flag = surround_odd_check(board, i, j)
            if board[i][j] % 2 == 1:
                if flag[0] == 1:
                    ctr += 1
                    board[i][j] -= 1
                    board[i][j+1] += 1
                    moves.append([i+1, j+1, i+1, j+2])
                    odd_counter -= 2
                elif flag[1] == 1:
                    ctr += 1
                    board[i][j] -= 1
                    board[i+1][j] += 1
                    moves.append([i+1, j+1, i+2, j+1])
                    odd_counter -= 2
                elif flag[0] == 0 and odd_counter > 0:
                    ctr += 1
                    board[i][j] -= 1
                    board[i][j+1] += 1
                    moves.append([i+1, j+1, i+1, j+2])
                elif flag[1] == 0 and odd_counter > 0:
                    ctr += 1
                    board[i][j] -= 1
                    board[i+1][j] += 1
                    moves.append([i+1, j+1, i+2, j+1])

    print(ctr)
    [print(' '.join(map(str, elm))) for elm in moves]

Solution (Python):
H,W = map(int,raw_input().split())
count = 0
c = []
d = 0
e = []
for i in range(H):
  count += 1
  a = raw_input().split()
  b = []
  for j in range(W):
    b.append(int(a[j]))
  for k in range(W-1):
    if b[k]%2 == 1:
      d += 1
      f = [count,k+1,count,k+2]
      e.append(f)
      b[k] -= 1
      b[k+1] += 1
  c.append(b[W-1])
count = 0
for i in range(H-1):
  count += 1
  if c[i]%2 == 1:
    d += 1
    f = [count,W,count+1,W]
    e.append(f)
    c[i] -= 1
    c[i+1] +=1
print d
for i in range(d):
  x = e[i]
  print x[0],x[1],x[2],x[3]

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

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

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

print(len(move))
for (y1, x1), (y2, x2) in move:
    print("%d %d %d %d" % (y1+1, x1+1, y2+1, x2+1))

Solution (Python):
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


h, w = LI()
a = []
for _ in range(h):
    a.append([x%2 for x in LI()])

operations = []
for i in range(h):
    for j in range(w-1):
        if not a[i][j]:
            continue
        else:
            a[i][j+1] ^= 1
            operations.append(' '.join(map(str, [i+1, j+1, i+1, j+2])))

for i in range(h-1):
    if not a[i][-1]:
        continue
    else:
        a[i+1][-1] ^= 1
        operations.append(' '.join(map(str, [i+1, w, i+2, w])))

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

Solution (Python):









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


x = []
for i in range(1, h + 1):
	x.append(list(map(int, input().split())))






operations = []

def main():
	for i in range(0, h):
		for j in range(0, w):
			if x[i][j] % 2 == 1:
				if j < w - 1:
					x[i][j] -= 1
					x[i][j + 1] += 1
					operations.append([i + 1, j + 1, i + 1, j + 2])
				elif i < h - 1:
					x[i][j] -= 1
					x[i + 1][j] += 1
					operations.append([i + 1, j + 1, i + 2, j + 1])
	print(len(operations))
	for ope in operations:
		print(ope[0], ope[1], ope[2], ope[3])
			
main()

Solution (Python):
h, w = list(map(int, input().split(" ")))
board = [w*[0] for i in range(h)]
for i in range(h):
    for j, a in enumerate(list(map(int, input().split(" ")))):
        board[i][j] = a

ans = []
for i in range(h):
    for j in range(w):
        if(board[i][j] % 2 == 1):
            if(i != 0):
                if(board[i-1][j] % 2 == 1):
                    board[i][j] -= 1
                    board[i-1][j] += 1
                    ans.append("%d %d %d %d" %(i+1, j+1, i, j+1))
                    continue
            if(i != h-1):
                if(board[i+1][j] % 2 == 1):
                    board[i][j] -= 1
                    board[i+1][j] += 1
                    ans.append("%d %d %d %d" %(i+1, j+1, i+2, j+1))
                    continue
            if(j != 0):
                if(board[i][j-1] % 2 == 1):
                    board[i][j] -= 1
                    board[i][j-1] += 1
                    ans.append("%d %d %d %d" %(i+1, j+1, i+1, j))
                    continue
            if(j != w-1):
                if(board[i][j+1] % 2 == 1):
                    board[i][j] -= 1
                    board[i][j+1] += 1
                    ans.append("%d %d %d %d" %(i+1, j+1, i+1, j+2))
                    continue
            if(h-i >= w-j):
                if(i != h-1):
                    board[i][j] -= 1
                    board[i+1][j] += 1
                    ans.append("%d %d %d %d" %(i+1, j+1, i+2, j+1))
                    continue
            else:
                if(j != w-1):
                    board[i][j] -= 1
                    board[i][j+1] += 1
                    ans.append("%d %d %d %d" %(i+1, j+1, i+1, j+2))
                    continue

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

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

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

print(len(move))
for m in move:
    print("{} {} {} {}".format(m[0] + 1, m[1] + 1, m[2] + 1, m[3] + 1))

Solution (Python):


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

a = []
for i in range(h):
    a.append([int(i) % 2 for i in input().split()])

res = []
prev = []
status = False

for y in range(h):
    for xx in range(w):
        if y % 2 == 1:
            x = w - xx - 1
        else:
            x = xx
        if status == True:
            res.append([prev[0] + 1, prev[1] + 1, y + 1, x + 1])
        if a[y][x] == 1:
            status = not status

        prev = [y, x]

print(len(res))
for arr in res:
    print(arr[0], arr[1], arr[2], arr[3])