#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ull;
int main()
{
	int n, m;
	cin >> n >> m;
	ull o, p;
	vector <ull> k;
	vector <ull>a, b;
	ull a1, b1;
	ull bb = 0;
	ull aa = 0;
	int bm = 0;
	if (n = 1)
	{
		cin >> o >> p;
		for (int i = 0; i < m; i++)
		{
			cin >> a1 >> b1;
			a.push_back(a1);
			b.push_back(b1);
			k.push_back(a1);
			bb += b1;
			aa += a1;
		}
		if (p > bb)
		{
			cout << bb;
			cout << m;
			for (int i = 0; i < m; i++)
			{
				cout << 1 << " " << i + 1 << " " << b[i] << endl;
			}
		}
		else
		{
			cout << p << endl;
			for (int i = 0; i < m; i++)
			{
				p -= a[i];
			}
			int i = 0;
			while (p > 0)
			{
				if (p >= (b[i] - a[i]))
				{
					p -= b[i] - a[i];
					k[i] = b[i];
				}
				else
				{
					k[i] += p;
					p = 0;
				}
				i++;
			}
			for (i = 0; i < k.size(); i++)
			{
				if (k[i] > 0)
					bm++;
			}
			cout << bm << endl;
			for (i = 0; i < k.size(); i++)
			{
				if (k[i] > 0)
					cout << 1 << " " << i + 1 << " " << k[i] << endl;
			}
		}

	}

}