#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n, m;cin>>n>>m;
    int a[n][m];
    int brp = 0;int maks = 0;
    for(int r = 0; r < n; r++){
        for(int k = 0; k < m;k++){
            int ai, bi, ci, di; cin >> ai >> bi >> ci >> di;
            a[r][k]= min(ai, ci);   
            if(a[r][k]!= 0) brp++;
            maks += a[r][k];

        }
    }
    cout << maks << endl << brp << endl;
    for(int r = 0; r < n; r++){
        for(int k = 0; k < m;k++){
            if(a[r][k]!= 0) 
                cout << r << " " << k << " " << a[r][k] << endl; 
        }}
  
    return 0;
}