#include <bits/stdc++.h>

#define ll long long
#define loop(i, s, e) for(ll i = s; i < e; i++)

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll n, m, a, b, c, d, res = 0;
    cin >> n >> m;

    unordered_map<ll, ll> polja;
    vector<ll> maxims(m);
    cin >> a >> b;
    loop(i, 0, m) {
        cin >> c >> d;
        a -= c;
        b -= c;
        d -= c;
        polja[i] += c;
        res += c;
        maxims[i] = d;
    }

    loop(i, 0, m) {
        if (b - maxims[i] >= 0) {
            b -= maxims[i];
            res += maxims[i];
            polja[i] += maxims[i];
        }    
    }

    cout << res << '\n';
    vector<pair<ll, ll>> sol;
    for(const auto &x : polja) {
        if (x.second != 0) {
            sol.push_back(x);
        }
    }
    cout << sol.size() << '\n';
    for(const auto &x : sol) {
        cout << "1 " << x.first + 1 << " " << x.second << '\n';
    }

    return 0;
}