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 in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using static System.Console;
using static PB10004.Algorithm.Util;

namespace PB10004.Algorithm
{
    class Template
    {
        static void Main(string[] args)
        {
            new D().Solve();
        }
    }
    class A{
        public void Solve(){
            var array = ReadIntArray();
            if((array[0]* array[1]) % 2 == 1){
                WriteLine("Yes");
            }
            else{
                WriteLine("No");
            }
        }
    }
    class B{
        HashSet<string> hash = new HashSet<string>();
        public void Solve(){
            var N = ReadInt();
            var current = "";
            for(int i=0;i<N;i++){
              var tmp = ReadLine();
              if(!hash.Add(tmp)){
                  WriteLine("No");
                  return;
              }
              if(i != 0){
                  if(tmp[0] != current[current.Length-1]){
                      WriteLine("No");
                      return;
                  }
              }
              current = tmp;
            }
            WriteLine("Yes");
        }
    }
    class C{
        public void Solve(){
            var array1 = ReadLongArray();
            var N = array1[0];
            var X = array1[1];
            var array2 = ReadLongArray();
            var array = array2.Select(x=>Math.Abs(x-X)).ToArray();
            var res = array.Aggregate((g,next) => Gcd(g, next));
            WriteLine(res);
        }
    }
    class D{
        int[,] table;
        List<Query> queries = new List<Query>();
        public void Solve(){
            var array = ReadIntArray();
            var H = array[0];
            var W = array[1];
            table = new int[W, H];
            for(int i=0; i<H; i++){
                var line = ReadIntArray();
                for(int j=0;j<W;j++){
                    table[j, i] = line[j];
                }
            }
            int ii = 0;
            int jj = 0;
            while(ii < W && jj < H){
                //WriteLine("{0},{1}", ii, jj);
                if(table[ii,jj] % 2 == 1){
                    var x = ii+1;
                    var y = jj+1;
                    while(ii < W && jj < H){
                        if(ii < W-1) ii++;
                        else if(jj < H-1){
                            jj++;
                            ii=0;
                        }
                        else break;
                        if(table[ii,jj] % 2 == 1){
                            Move(x,y, ii+1, jj+1);
                            break;
                        }
                    }
                }
                if(ii < W-1) ii++;
                else{
                    jj++;
                    ii=0;
                }
            }
            WriteLine(queries.Count);
            WriteLine(string.Join("\n", queries));
        }
        void Move(int x1, int y1, int x2, int y2){
            //WriteLine("{0}, {1}, {2}, {3}", x1, y1, x2, y2);
            if(y1 < y2){
                while(y1 < y2){
                    queries.Add(new Query(x2, y2, x2, y2-1));
                    y2--;
                }
            }
            else{
                while(y2 < y1){
                    queries.Add(new Query(x1, y1, x1, y1-1));
                    y1--;
                }
            }
            if(x1 < x2){
                while(x1 < x2){
                    queries.Add(new Query(x1, y1, x1+1, y1));
                    x1++;
                }
            }
            else{
                while(x2 < x1){
                    queries.Add(new Query(x2, y2, x2+1, y2));
                    x2++;
                }
            }
            
        }
    }
    struct Query{
        public int X1,Y1,X2,Y2;
        public Query(int x1, int y1, int x2, int y2){
            X1 = x1;
            Y1 = y1;
            X2 = x2;
            Y2 = y2;
        }
        public override string ToString(){
            return string.Format("{0} {1} {2} {3}", Y1, X1, Y2, X2);
        }
    }
    public static class Util
    {
        /// <summary>
        /// 標準入力をint型にパースする
        /// </summary>
        /// <returns></returns>
        public static int ReadInt(){
            return int.Parse(ReadLine());
        }
        /// <summary>
        /// 標準入力をint型の配列にする
        /// </summary>
        /// <returns></returns>
        public static int[] ReadIntArray(){
            return ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        }
        /// <summary>
        /// 標準入力をlong型にパースする
        /// </summary>
        /// <returns></returns>
        public static long ReadLong()
        {
            return long.Parse(ReadLine());
        }
        /// <summary>
        /// 標準入力をlong型の配列にする
        /// </summary>
        /// <returns></returns>
        public static long[] ReadLongArray()
        {
            return ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        /// <summary>
        /// 一定値の数列を生成する
        /// </summary>
        /// <param name="value"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static IEnumerable<long> ConstSeq(long value, long length)
        {
            for (int i = 0; i < length; i++)
            {
                yield return value;
            }
        }
        /// <summary>
        /// int配列の累積和を求める
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static IEnumerable<int> CumulativeSum(IEnumerable<int> array)
        {
            int tmp = 0;
            foreach (var num in array)
                yield return tmp += num;
        }
        /// <summary>
        /// long配列の累積和を求める
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static IEnumerable<long> CumulativeSum(IEnumerable<long> array)
        {
            long tmp = 0;
            foreach (var num in array)
                yield return tmp += num;
        }
        /// <summary>
        /// 最大公約数をユークリッドの互除法で求める
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }
        /// <summary>
        /// 最小公倍数を求める
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }
    }
}