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 Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(unused_imports)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repositry is at "https://github.com/Loptall/sfcpl"

/*
    水コーダーになれてうれしいです
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::fmt;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{
    clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Signed, Unsigned, Zero,
};
use permutohedron::Heap;
use proconio::{
    derive_readable, fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub use visualize::*;
pub mod visualize {
    use itertools::*;
    pub trait Visualize {
        fn visualize(&self, split: &str);
        fn continuous(&self) {
            self.visualize("");
        }
        fn spaces(&self) {
            self.visualize(" ");
        }
        fn lines(&self) {
            self.visualize("\n");
        }
    }
    macro_rules ! impl_vis_for_sized {($ ($ t : ty ) ,+ ) => {$ (impl Visualize for $ t {fn visualize (& self , _split : & str ) {print ! ("{}" , self ) ; } } ) + } ; }
    impl_vis_for_sized! {usize , u8 , u16 , u32 , u64 , u128 , isize , i8 , i16 , i32 , i64 , i128 , String , & str , char }
    impl<T: std::fmt::Display> Visualize for [T] {
        fn visualize(&self, split: &str) {
            print!("{}", self.iter().join(split));
        }
    }
    #[test]
    fn fmt() {
        let a = 2;
        a.visualize("");
        let b = "str";
        b.visualize("");
        let c = vec![1, 2, 3];
        c.visualize(" ");
        c.visualize("\n");
    }
    /// macro to output answer improved to println
    /// this macro will print '\n' at the last.
    /// # Patterns
    /// `,`, it means one space, it formats the elements, which is before, space-split.
    /// And insert a space after the prefix, unless it is at last.
    /// `=>`, it means empty string, it formats the element, witch is before, without any split.
    /// And insert nothing between two element.
    /// `;`, it means newline(\n), it formats the element, witch is before, newline-split.
    /// And insert a newline after the prefix, unless it is at last.
    /// # Eample
    /// ```
    /// #[test]
    /// fn vis_test() {
    ///     let a = 1;
    ///     let b = 2;
    ///     let c = 3;
    ///     let v = vec!['a', 'b', 'c'];
    ///     // single element test ...
    ///     vis!(a); // 1\n
    ///     vis!(a,); // 1\n
    ///     vis!(a =>); // 1\n
    ///     vis!(a;); // 1\n
    ///     println!();
    ///     vis!(a + b); // 3\n
    ///     println!();
    ///     vis!(v); // a b c\n
    ///     vis!(v,); // a b c\n
    ///     vis!(v =>); // abc\n
    ///     vis!(v;); // a\nb\nc\n
    ///     println!();
    ///     // multi elements connected by common operater test ...
    ///     println!();
    ///     vis!(a, b); // 1 2\n
    ///     vis!(a, b, c); // 1 2 3\n
    ///     vis!(a, b, c;); // 1 2 3\n
    ///     println!();
    ///     vis!(a => b); // 12\n
    ///     vis!(a => b => c); // 123\n
    ///     vis!(a => b => c ,); // 123\n
    ///     println!();
    ///     vis!(a; b); // 1\n2\n
    ///     vis!(a; b; c); // 1\n2\n3\n
    ///     vis!(a; b; c =>); // 1\n2\n3\n
    ///     println!();
    ///     // multi elements connected by different operater test ...
    ///     vis!(a, b; c); // 1 2\n3\n
    ///     vis!(a; b, c); // 1\n2 3\n
    ///     vis!(a => b, c); // 12 3\n
    ///     vis!(a; b => c); // 1\n23\n
    ///     println!();
    ///     vis!(a, v); // 1 a b c\n;
    ///     vis!(a, v;); // 1 a\nb\nc\n;
    ///     vis!(a => v =>); // 1abc\n;
    ///     println!("\d");
    ///     // panic!()
    /// }
    /// ```
    #[macro_export]
    macro_rules ! vis {() => {println ! () ; } ; ($ last : expr ; ) => {$ last . lines () ; vis ! () } ; ($ last : expr => ) => {$ last . continuous () ; vis ! () ; } ; ($ last : expr $ (, ) ? ) => {$ last . spaces () ; vis ! () ; } ; ($ first : expr ; $ ($ rest : tt ) * ) => {$ first . lines () ; println ! () ; vis ! ($ ($ rest ) * ) ; } ; ($ first : expr => $ ($ rest : tt ) * ) => {$ first . continuous () ; vis ! ($ ($ rest ) * ) ; } ; ($ first : expr , $ ($ rest : tt ) * ) => {$ first . spaces () ; print ! (" " ) ; vis ! ($ ($ rest ) * ) ; } ; }
    #[test]
    fn vis_test() {
        let a = 1;
        let b = 2;
        let c = 3;
        let v = vec!['a', 'b', 'c'];
        vis!();
        vis!(a);
        vis!(a,);
        vis ! (a => );
        vis ! (a ; );
        println!();
        vis!(a + b);
        println!();
        vis!(v);
        vis!(v,);
        vis ! (v => );
        vis ! (v ; );
        println!();
        println!();
        vis!(a, b);
        vis!(a, b, c);
        vis ! (a , b , c ; );
        println!();
        vis ! (a => b );
        vis ! (a => b => c );
        vis ! (a => b => c , );
        println!();
        vis ! (a ; b );
        vis ! (a ; b ; c );
        vis ! (a ; b ; c => );
        println!();
        vis ! (a , b ; c );
        vis ! (a ; b , c );
        vis ! (a => b , c );
        vis ! (a ; b => c );
        println!();
        vis!(a, v);
        vis ! (a , v ; );
        vis ! (a => v => );
    }
}

pub use consts::*;
pub mod consts {
    pub const MOD10E9_7: usize = 1000000007; // 10 ^ 9 + 7
    pub const MOD99_: usize = 998244353;
    pub const MAX: usize = std::usize::MAX; // = 2 ^ 64 - 1 = 18446744073709551615 ≈ 1.8 * 10 ^ 19
    pub const INF: usize = 2000000000000000000; // MAX / 9 < 2 * 10e18 < MAX / 10
    pub const FNI: i64 = -2000000000000000000; // == -(INF as i64)
    pub const PI: f64 = std::f64::consts::PI; // 3.141592653589793 -- 10 ^ -15
    pub const ASCII_A_LARGE: u8 = 65;
    pub const ASCII_A_SMALL: u8 = 97;
    pub const ASCII_0: u8 = 48;
    pub const ADJ4: &[(isize, isize); 4] = &[(1, 0), (0, 1), (-1, 0), (0, -1)];
    pub const ADJ8: &[(isize, isize); 8] = &[
        (1, 0),
        (1, 1),
        (0, 1),
        (-1, 1),
        (-1, 0),
        (-1, -1),
        (0, -1),
        (1, -1),
    ];
}
// code...
// #[fastout]
fn main() {
    input! {
        h: usize, w: usize,
        mut board: [[usize; w]; h]
    }

    let mut ans = Vec::new();
    for i in 0..h - 1 {
        for j in 0..w - 1 {
            if board[i][j].is_odd() {
                board[i][j] -= 1;
                board[i][j + 1] += 1;
                ans.push((i, j, i, j + 1));
            }
        }

        if board[i][w - 1].is_odd() {
            board[i][w - 1] -= 1;
            board[i + 1][w - 1] += 1;
            ans.push((i, w - 1, i + 1, w - 1));
        }
    }

    for j in 0..w - 1 {
        if board[h - 1][j].is_odd() {
            board[h - 1][j] -= 1;
            board[h - 1][j + 1] += 1;
            ans.push((h - 1, j, h - 1, j + 1));
        }
    }

    vis!(ans.len());
    for (a, b, c, d) in ans {
        vis!(a, b, c, d);
    }
}