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: Wrong Answer)

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

using namespace std;
using bint = boost::multiprecision::cpp_int;
typedef uint64_t ulint;
typedef int64_t lint;

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);


bool flagdebug = false;

// struct area
// {
//     lint x;
//     lint y;
// public:
//     area (lint xx, lint yy)
//     {
//         x = xx;
//         y = yy;
//     }
// };


int main(){
//////////////////////////////////////////////////////

    flagdebug = true; ///本番時削除！！！！！

    //入力

    lint h,w;
    cin >> h >> w;

    vector<pair<lint,lint>> odd;

    lint num;

    rep1(i, h)
    {
        rep1(j, w)
        {
            cin >> num;
            if(num % 2 == 1)
            {
                odd.push_back(make_pair(i,j));
            }
        }
    }

    vector<pair<lint,lint>> con1;
    vector<pair<lint,lint>> con2;

    lint n = odd.size();
    lint cnt = 0;
    
    while(n>=2)
    {
        while(odd[n-2].first != odd[n-1].first)
        {
            con1.push_back(odd[n-1]);
            if(odd[n-2].first > odd[n-1].first)
            {
                odd[n-1].first ++;
            }
            else
            {
                odd[n-1].first --;
            }
            con2.push_back(odd[n-1]);
            cnt ++;
        }
        while(odd[n-2].second != odd[n-1].second)
        {
            con1.push_back(odd[n-1]);
            if(odd[n-2].second > odd[n-1].second)
            {
                odd[n-1].second ++;
            }
            else
            {
                odd[n-1].second --;
            }
            con2.push_back(odd[n-1]);
            cnt ++;
        }

        n -= 2;
        
        
    }

    cout << cnt << endl;

    rep0(i,cnt)
    {
        cout << con1[i].first << " " << con1[i].second << " " << con2[i].first << " " << con2[i].second <<endl;
    }

    //2次元配列
    //vector<vector<lint>> mat(row, vector<lint>(column, 初期値));
    //ペア
    //pair<lint,lint> p = make_pair(1,2);
    //vector<pair<lint,lint>> c(100010, pair<lint,lint>(0,0));
    //タプル
    //tuple<lint,lint,lint> t  = make_tuple(1,2,3);


    //昇順ソート
    //sort(all(a));
    //降順ソート
    //sort(all(a),greater<lint>());
    //特殊なソート（ラムダ式）
    //sort(all(mat), [&i](const vector<lint> &a, const vector<lint> &b){return a[i] < b[i];});
    // //[&i]は参照する変数，いらなければからの大括弧でよし．
    
    //////////////////////////////////////////////////////
    //キュー
    //queue<lint> que;
    //que.push(value);
    //que.front(); //先頭を参照
    //que.top(); //トップを参照（消されないので消したい場合は直後にpop()を使う）
    //que.pop(); //追い出す
    //que.empty(); //空なら1，あれば0
    //優先度付きキュー
    //priority_queue<lint> que;
    //キューにque.push()で入れると最大値順に並べられる．que.pop()で取り出すときは常に最大値が前にくる．
    //最小値から取り出したい時はpriority_queue< lint, std::vector<lint>, std::greater<lint> >
    //////////////////////////////////////////////////////
    //スタック
    //stack<lint> stk;
    //stk.push(value);
    //stk.top(); //先頭を参照（消されないので消したい場合は直後にpop()を使う）
    //stk.pop(); //トップを削除
    //stk.empty(); //空なら1,あれば0
    //stk.size(); //数
    //
    // sort(input.begin() , input.end());
    // uint64_t max = numeric_limits<uint64_t>::max();

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


struct node
{
    node* parent;
    node* firstchild;
    node* lastchild;
    node* olderbrother;
    node* youngerbrother;
    lint childnum;
    lint value;
public:
    node()
    {
        parent = NULL;
        firstchild = NULL;
        lastchild = NULL;
        olderbrother = NULL;
        youngerbrother = NULL;
        childnum = 0;
        value = 0;
    }

    void addchild(node* newchild)
    {
        if(childnum == 0)
        {
            firstchild = newchild;
        }
        else
        {
            lastchild->youngerbrother = newchild;
            newchild->olderbrother = lastchild;
            
        }
        lastchild = newchild;
        newchild->parent = this;
        childnum++;
    }
    void deletechild(node* child)
    {
        if(child->parent != this)return;
        if(child->youngerbrother != NULL)
        {
            child->youngerbrother->olderbrother = child->olderbrother;
        }
        if(child->olderbrother != NULL)
        {
            child->olderbrother->youngerbrother = child->youngerbrother;
        }
        childnum--;
    }

    bool operator<(const node &another) const{return value < another.value;};
    bool operator>(const node &another) const{return value > another.value;};   
};


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// 最大公約数
ulint gcd(lint a, lint b){
    if(b!=0){gcd(b, a % b);}
    return a;    
}
ulint gcd(vector<lint> v){
    lint l = v.size();
    if(l>=2){
        v[l-2] = gcd(v[l-2] , v[l-1]);
        v.pop_back();
    }
    if(l==1)return v[0];
    else return 0;
}

//最小公倍数
ulint lcm(lint a, lint b){
    return a / gcd(a, b) * b;
}
ulint lcm(vector<lint> v){
    lint l = v.size();
    if(l>=2){
        v[l-2] = lcm(v[l-2], v[l-1]);
        v.pop_back();
    }
    if(l==1)return v[0];
    else{
        return 0;
    }
}