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: Accepted)

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

namespace ProgrammingContest
{
    class Writer : IDisposable
    {
        private System.IO.TextWriter Out { get; }
        private StringBuilder Sb { get; }
        private bool IsReactive { get; }
        public Writer(string path)
            : this(new System.IO.StreamWriter(path))
        {
        }
        public Writer(bool isReactive)
            : this(null, isReactive)
        {
        }
        public Writer(System.IO.TextWriter writer = null, bool isReactive = false)
        {
            this.Out = (writer ?? Console.Out);
            this.IsReactive = isReactive;
            if (!this.IsReactive)
            {
                this.Sb = new StringBuilder();
            }
        }
        public void Dispose()
        {
            if (!this.IsReactive)
            {
                this.Out.Write(Sb.ToString());
            }
            if (!this.Out.Equals(Console.Out))
            {
                this.Out.Dispose();
            }
        }
        public void Write(object val)
        {
            if (this.IsReactive)
            {
                this.Out.Write(val.ToString());
                this.Out.Flush();
            }
            else
            {
                this.Sb.Append(val.ToString());
            }
        }
        public void WriteFormat(string format, params object[] vals)
        {
            if (this.IsReactive)
            {
                this.Out.Write(format, vals);
                this.Out.Flush();
            }
            else
            {
                this.Sb.AppendFormat(format, vals);
            }
        }
        public void WriteLine(object val = null)
        {
            this.WriteFormat((val ?? string.Empty).ToString() + Environment.NewLine);
        }
        public void WriteLine(int val)
        {
            this.WriteLine(val.ToString());
        }
        public void WriteLine(long val)
        {
            this.WriteLine(val.ToString());
        }
        public void WriteLine(string val)
        {
            this.WriteLine((object)val);
        }
        public void WriteLine(string format, params object[] vals)
        {
            this.WriteFormat(format + Environment.NewLine, vals);
        }
    }

    class Scanner : IDisposable
    {
        private Queue<string> Buffer { get; }
        private char[] Sep { get; }
        private System.IO.TextReader Reader { get; }
        public Scanner(string path, char[] sep = null)
            : this(new System.IO.StreamReader(path), sep)
        {
        }
        public Scanner(System.IO.TextReader reader = null,
                        char[] sep = null)
        {
            this.Buffer = new Queue<string>();
            this.Sep = (sep ?? new char[] { ' ' });
            this.Reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.Buffer.Count == 0 && this.Reader.Peek() != -1)
            {
                string str = string.Empty;
                for (; string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str);
                    str = this.Reader.ReadLine()) ;

                var strs = str.Split(this.Sep).Where(el => !(string.IsNullOrEmpty(el) || string.IsNullOrWhiteSpace(el)));
                foreach (var el in strs)
                {
                    this.Buffer.Enqueue(el);
                }
            }
        }

        public void Dispose()
        {
            if (!this.Reader.Equals(Console.In))
            {
                this.Reader.Dispose();
            }
        }

        public string Next()
        {
            this.CheckBuffer();
                return this.Buffer.Dequeue();
        }
        public string[] GetStringArray(int N)
        {
            return Enumerable.Range(0, N)
                             .Select(e => this.Next())
                             .ToArray();
        }

        public int NextInt()
        {
            return int.Parse(this.Next());
        }
        public int[] GetIntArray(int N)
        {
            return Enumerable.Range(0, N)
                             .Select(e => this.NextInt())
                             .ToArray();
        }

        public double NextDouble()
        {
            return double.Parse(this.Next());
    }
        public double[] GetdoubleArray(int N)
        {
            return Enumerable.Range(0, N)
                             .Select(e => this.NextDouble())
                             .ToArray();
        }

        public long NextLong()
        {
            return long.Parse(this.Next());
        }
        public long[] GetLongArray(int N)
        {
            return Enumerable.Range(0, N)
                             .Select(e => this.NextLong())
                             .ToArray();
        }

        public bool IsEnd
        {
            get
            {
                this.CheckBuffer();
                return this.Buffer.Count == 0;
            }
        }
    }

    class MainClass : IDisposable
    {
        private Scanner Sc { get; }
        private Writer Wr { get; }
        static string BackPath { get; } = "..";
        private char DirSep { get; } = System.IO.Path.DirectorySeparatorChar;
        private string InFilePath { get; } = string.Empty;
        private string OutFilePath { get; } = string.Empty;
        public MainClass()
        {
            this.InFilePath = MainClass.BackPath
                            + this.DirSep
                            + MainClass.BackPath
                            + this.DirSep
                            + "in.txt";
            this.OutFilePath = MainClass.BackPath
                             + this.DirSep
                             + MainClass.BackPath
                             + this.DirSep
                             + "out.txt";

            this.Wr = new Writer(this.IsReactive);
            //this.wr = new Writer(this.OutFilePath);
#if DEBUG
            if (!this.IsReactive)
            {
                this.Sc = new Scanner(this.InFilePath);
            }
            else
            {
                this.Sc = new Scanner();
            }
#else
            this.Sc = new Scanner();
#endif
        }
        static void Main(string[] args)
        {
            using (var mainClass = new MainClass())
            {
                mainClass.Solve();
            }
        }

        public void Dispose()
        {
            this.Sc?.Dispose();
            this.Wr?.Dispose();
#if DEBUG
            Console.WriteLine("press any key to continue...");
            Console.ReadKey();
#endif
        }

        long Gcd(long a, long b)
        {
            if (a < b)
            {
                var tmp = b;
                b = a;
                a = tmp;
            }
            var ret = 1L;
            while (b != 0)
            {
                ret = b;
                b = a % b;
                a = ret;
            }
            return ret;
        }

        void Solve()
        {
            int H = Sc.NextInt();
            int W = Sc.NextInt();
            int[,] a = new int[H, W];
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    a[i, j] = Sc.NextInt() % 2;
                }
            }
            List<string> ans = new List<string>();
            Pair<int, int> p = new Pair<int, int>(-1, -1);
            for (int i = 0; i < H; i++)
            {
                if (i % 2 == 0)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (a[i, j] == 1)
                        {
                            if (p.Equals(new Pair<int, int>(-1, -1)))
                            {
                                p = new Pair<int, int>(i, j);
                            }
                            else
                            {
                                ans.Add($"{p.First + 1} {p.Second + 1} {i + 1} {j + 1}");
                                p = new Pair<int, int>(-1, -1);
                            }
                        }
                        else
                        {
                            if (!p.Equals(new Pair<int, int>(-1, -1)))
                            {
                                ans.Add($"{p.First + 1} {p.Second + 1} {i + 1} {j + 1}");
                                p = new Pair<int, int>(i, j);
                            }
                        }
                    }
                }
                else
                {
                    for (int j = W - 1; j >= 0; j--)
                    {
                        if (a[i, j] == 1)
                        {
                            if (p.Equals(new Pair<int, int>(-1, -1)))
                            {
                                p = new Pair<int, int>(i, j);
                            }
                            else
                            {
                                ans.Add($"{p.First + 1} {p.Second + 1} {i + 1} {j + 1}");
                                p = new Pair<int, int>(-1, -1);
                            }
                        }
                        else
                        {
                            if (!p.Equals(new Pair<int, int>(-1, -1)))
                            {
                                ans.Add($"{p.First + 1} {p.Second + 1} {i + 1} {j + 1}");
                                p = new Pair<int, int>(i, j);
                            }
                        }
                    }
                }
            }
            Wr.WriteLine(ans.Count);
            foreach (var el in ans)
            {
                Wr.WriteLine(el);
            }
        }

        private bool IsReactive { get; } = false; // TODO: reactive check !!
    }
    class Pair<T1, T2>
        : IComparable<Pair<T1, T2>>,
          IEquatable<Pair<T1, T2>>,
          IDisposable
    {
        public T1 First { get; set; }
        public T2 Second { get; set; }

        public Pair() { }

        public Pair(T1 f, T2 s)
        {
            this.First = f;
            this.Second = s;
        }

        public int CompareTo(Pair<T1, T2> other)
        {
            int ret = 0;
            if (First is IComparable<T1>)
            {
                ret = (First as IComparable<T1>).CompareTo(other.First);
            }
            if (ret == 0 && Second is IComparable<T2>)
            {
                ret = (Second as IComparable<T2>).CompareTo(other.Second);
            }
            return ret;
        }
        public override bool Equals(object obj)
        {
            if (obj is Pair<T1, T2>)
            {
                return this.Equals(obj as Pair<T1, T2>);
            }
            else
            {
                return false;
            }
        }
        public override int GetHashCode()
        {
            return this.First.GetHashCode() ^ this.Second.GetHashCode();
        }
        public Pair<T1, T2> Clone()
        {
            return new Pair<T1, T2>(this.First, this.Second);
        }

        public bool Equals(Pair<T1, T2> other)
        {
            return this.First.Equals(other.First) && this.Second.Equals(other.Second);
        }

        public void Dispose()
        {
            if (this.First is IDisposable)
            {
                (this.First as IDisposable).Dispose();
            }
            if (this.Second is IDisposable)
            {
                (this.Second as IDisposable).Dispose();
            }
        }
    }
}