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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mem(x, val) memset(x, val, sizeof(x))
#define mk make_pair
#define f(i,n) for(i = 0; i < n; i++)
#define f1(i,n) for(i = 1; i <= n; i++)
#define all(a) a.begin(),a.end()
#define upp(v,val) upper_bound(v.begin(), v.end(), val)
#define lower(v,val) lower_bound(v.begin(), v.end(), val)
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define jaldi_chal() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define S second
#define F first
#define fm(it,m) for(it = m.begin(); it != m.end(); it++)
#define ct_set(n) __builtin_popcount(n) // count no of set bits
#define INF 0x3f3f3f3f
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265    // acosl(-1)
#define precision cout << setprecision(15)
#define print_arr(a,n) for(int i = 0; i < n; i++) cout << a[i] << " ";
#define print_vec(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " ";
//vec.erase(std::remove(vec.begin(), vec.end(), val), vec.end());
using namespace std;

// v.resize(unique(v.begin(), v.end()) - v.begin());   // for unique elements in sorted vector
// fflush(stdout);  // after every output

// Using 128 bit integers
/*
	std::string toString(__int128 num) {
    std::string str;
    do {
        int digit = num % 10;
        str = std::to_string(digit) + str;
	        num = (num - digit) / 10;
	    } while (num != 0);
	    return str;
	}
	
	int main() {
	    __int128_t x;
	    string s;
	    cin >> s;
	    x = (stoll)(s);
	    __int128_t ans = x * x * x;
	    cout << toString(ans);
	}

*/

bool isPrime(ll n) {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
 
    if (n % 2 == 0 || n % 3 == 0)
        return false;
 
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
 
    return true;
}

ll gcd(ll a,ll b) {
	if (a == 0)    
		return b; 	
	return gcd(b % a, a); 
}

ll lcm(ll a, ll b) {	
	ll g = gcd(a, b); 
	ll ans = (a * b) / g; 
	return ans;	
}

ll add(ll a, ll b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}
 
ll sub(ll a, ll b) {
	a -= b;
	if (a < 0) {
		a += mod;
	}
	return a;
}
 
ll mul(ll a, ll b) {
	return (a * b) % mod;
}

vector <ll> primes;

bool prime[10005];
void seive() {
	mem(prime, 1);
	prime[0] = 0;
	prime[1] = 0;
	for(ll i = 2; i <= 10000; i++)
	{
		if(prime[i] == 1)
		{
			for(ll j = i * i; j <= 10000; j += i)
			prime[j] = 0;
		}
	}	
}

ll power(ll a, ll b) {
	ll ans = 1;
	while(b > 0)
	{
		if(b % 2 == 1)
		ans = (ans % mod * a % mod) % mod;
		a = (a * a) % mod;
		b = b / 2;
	}
	return ans;
}

template <typename T>
std::string NumberToString ( T Number ) {
	std::ostringstream ss;
	ss << Number;
	return ss.str();
}

string num_to_bits(ll n) {
	string ans = "";
	while(n) {
		ans += (n % 2) + '0';
		n /= 2;
	}
	reverse(all(ans));
	return ans;
}

ll bits_to_num(string s) {
	ll ans = 0;
	for(ll i = 0; i < s.size(); i++) {
		ll x = s.size() - i - 1;
		ll val = pow(2LL, x);
		if(s[i] == '1') {
			ans = ans + val;
		}
	}
	return ans;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y);   
ll modInverse(ll b, ll m) { 
    ll x, y; 
    ll g = gcdExtended(b, m, &x, &y); 
    if (g != 1) 
        return -1; 
    return (x % m + m) % m; 
} 
  
// Function to compute a/b under modlo m 
ll modDivide(ll a, ll b, ll m) { 
    a = a % m; 
    ll inv = modInverse(b, m); 
    //if (inv == -1) 
       //cout << "Division not defined"; 
    //else
       //cout << "Result of division is " << (inv * a) % m; 
       return (inv * a) % m;
} 

ll gcdExtended(ll a, ll b, ll *x, ll *y) { 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b % a, a, &x1, &y1); 
    *x = y1 - (b / a) * x1; 
    *y = x1; 
    return gcd; 
} 
// To call for modulo division (a / b) % m : modDivide(a, b, m);

/* This will store divisors of the number from 1 to n
	for(i = 1; i <= n; i++) {
		for(j = i; j <= n; j += i) {
			v[j].pb(i);
		}
	}
*/

void solve() {
	
	ll n, m;
	cin >> n >> m;
	
	ll a[n][m], i, j;
	
	for(i = 0; i < n; i++) { 
		for(j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	
	vector <pair <ll, ll> > to, from;
	for(i = 0; i < n; i++) {
		for(j = 0; j < m - 1; j++) {
			if(a[i][j] % 2 == 1) {
				from.pb({i, j});
				to.pb({i, j + 1});
				a[i][j]--;
				a[i][j + 1]++;
			}
		}
	}
	for(i = 0; i < n - 1; i++) {
		if(a[i][m - 1] % 2 == 1) {
			from.pb({i, m - 1});
			to.pb({i + 1, m - 1});
			a[i][m - 1]--;
			a[i + 1][m - 1]++;
		}
	}
	cout << to.size() << endl;
	for(i = 0; i < to.size(); i++) {
		cout << from[i].F + 1 << " " << from[i].S + 1 << " " << to[i].F + 1 << " " << to[i].S + 1 << endl;
	}
}

int main() {
	jaldi_chal()
	
//	freopen("input.txt", "r" , stdin);
//  freopen("output.txt", "w", stdout);
	
//	seive();
//	for(int i = 2; i <= 10000; i++)	{
//		if(prime[i])
//		primes.pb(i);
//	}
	
	bool codechef = 0;
	ll t = 1;
	
	if(codechef) {
		cin >> t;
	}
	
	while(t--) {
		solve();
	}
	
	return 0;
}