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 <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;

ll euclidean_gcd(ll a, ll b) {
	if (a < b) euclidean_gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}


int main() {
	ll H,W;
	cin >> H>>W;
	vb a(H*W);
	rep(i, 0, H) {
		rep(j, 0, W)
		{	
			ll x;
			cin>> x;
			if (i% 2 == 0) {
				a[i*W+j] = (x % 2 == 0);

			}
			else {
				a[i*W + W-j-1] = (x % 2 == 0);

			}

		}
	}
	vector<pair<pll, pll>> res;

	pair<bool, bool> state{ 0,0 };
	bool isGoodState = a[0];
	rep(i, 1, H*W) {
		if ( a[i]) {
			if (isGoodState) {

			}
			else {
				ll row = i / W;

				if (row % 2 == 0) {
					if (i%W != 0) {
						res.push_back({ { i / W,i%W - 1 }, { i / W,i%W } });
					}
					else {//corner
						res.push_back({ { i / W-1,i%W  },{ i / W,i%W } });
					}

				}
				else {
					if (i%W != 0) {
						res.push_back({ { i / W,W- i%W  },{ i / W, W- i%W -1} });

					}
					else {
						res.push_back({ { i / W - 1,W-1 },{ i /W,W-1 } });
					}

				}
			
			}
		}
		else  {
			if (isGoodState) {
				isGoodState = false;
				
			}
			else {
				isGoodState = true;
				ll row = i / W;

				if (row % 2 == 0) {
					if (i%W != 0) {
						res.push_back({ { i / W,i%W - 1 },{ i / W,i%W } });
					}
					else {//corner
						res.push_back({ { i / W - 1,i%W },{ i / W,i%W } });
					}

				}
				else {
					if (i%W != 0) {
						res.push_back({ { i / W,W - i % W },{ i / W, W - i % W - 1 } });

					}
					else {
						res.push_back({ { i / W - 1,W - 1 },{ i / W,W - 1 } });
					}

				}

			}
		}
	}



	//rep(i, 0, H) {
	//	if (i % 2 == 0) {
	//		rep(j, 1, W) {
	//			if ()break;
	//			if (a[i][j]) {
	//				res.push_back({ {i,j - 1},{i,j} });

	//			}
	//			else {
	//				res.push_back({ { i,j - 1 },{ i,j } });
	//				isGoodState = true;
	//			}
	//		}
	//	}
	//}


		cout << res.size() << endl;
	rep(i, 0, res.size()) {
		cout << res[i].first.first+1 <<" "<< res[i].first.second +1<<" "<< res[i].second.first+1 <<" "<< res[i].second.second+1 << endl;
	}

}
//ll N;
//cin >> N;
//vll a(N);
//rep(i,0, N) cin >> a[i];