Problem:
Score : 700 points

Problem Statement

You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists.

The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N.

The number of edges, M, is at most 60. Each edge has an integer length between 0 and 10^6 (inclusive).

Every edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, 1,2,...,N is one possible topological order of the vertices.

There are exactly L different paths from Vertex 1 to Vertex N. The lengths of these paths are all different, and they are integers between 0 and L-1.

Here, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different.

Constraints

2 \leq L \leq 10^6

L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

In the first line, print N and M, the number of the vertices and edges in your graph.
In the i-th of the following M lines, print three integers u_i,v_i and w_i, representing the starting vertex, the ending vertex and the length of the i-th edge.
If there are multiple solutions, any of them will be accepted.

Sample Input 1

4

Sample Output 1

8 10
1 2 0
2 3 0
3 4 0
1 5 0
2 6 0
3 7 0
4 8 0
5 6 1
6 7 1
7 8 1

In the graph represented by the sample output, there are four paths from Vertex 1 to N=8:

1 → 2 → 3 → 4 → 8 with length 0

1 → 2 → 3 → 7 → 8 with length 1

1 → 2 → 6 → 7 → 8 with length 2

1 → 5 → 6 → 7 → 8 with length 3

There are other possible solutions.

Sample Input 2

5

Sample Output 2

5 7
1 2 0
2 3 1
3 4 0
4 5 0
2 4 0
1 3 3
3 5 1

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

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

/***** type *****/
using namespace std;
using ll = long long;
using ld = long double;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
using ml = boost::multiprecision::cpp_int;

/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define val(itr) *(itr)                          // get value
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define mod 1000000007                           // 1e9 + 7
#define pi 3.14159265                            // 3.14 ...
/***** for each macro *****/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, c) fori(i, auto e = c.begin(); e != c.end(); ++e)
#define forir(i, v, ...) if(ll i = Size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, c) forir(i, auto e = c.rbegin(); e != c.rend(); ++e)

/***** lambda *****/
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoN = [] // char to number
(auto c) { return (ll)(c - '0'); };
auto DivC = [] // long double div ceiling
(auto a, auto b) { return ceil((ld)a / (ld)b); };
auto Fix = [] // fix value
(auto b, auto e, auto fix)
{ for (auto it = b; it != e; ++it)* it += fix; };
auto Pow = [] // long long pow
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = [] // long long pow2
(auto n) { return (1LL << n); };
auto Pow10 = [] // long long pow10
(auto n) { return (ll)pow(10, n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** template *****/
template <class T> vvt<T> VVT
(ll ys, ll xs, T fill = T())
{	// vector<vector<T>> resize + fill
	vvt<T> v(ys);
	each(i, y, v) { val(y).resize(xs, fill); } return v;
}
template <class T> vvvt<T> VVVT
(ll zs, ll ys, ll xs, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	vvvt<T> v(zs);
	each(i, z, v) { val(z) = VVT(ys, xs, fill); } return v;
}
template <class T> vt<T> InputVT
(ll size, T fix = T())
{   // input vector<T> (T != struct) + fix
	vt<T> v(size);
	each(i, e, v) { cin >> val(e); val(e) += fix; } return v;
}
template <class T> vvt<T> InputVVT
(ll ys, ll xs, T fix = T())
{   // input vector<vector<T>> (T != struct) + fix
	vvt<T> v(ys); each(i, y, v) val(y).resize(xs);
	each(i, y, v) each(j, x, val(y)) { cin >> val(x); val(x) += fix; } return v;
}
template <class T> vvvt<T> InputVVVT
(ll zs, ll ys, ll xs, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	vvvt<T> v(zs);
	each(i, z, v) { val(z) = InputVVT<T>(ys, xs, fix); } return v;
}

namespace NyaGadget
{
	/*** Bit操作ライブラリ ***/

	struct Bit
	{
		/**
		@brief コンテナ各要素の任意桁でビットが1になっている数を返す関数
		@note
		 半開区間[b, e)でi桁目ビットが1になっている数を返す。
		 sumは初期値で通常デフォルト引数のままで良い。
		**/
		template <class T> static ll Count(T b, T e, ll i, ll sum = 0)
		{
			for (auto it = b; it != e; ++it) sum += Test(*it, i);
			return sum;
		}

		/**
		@brief コンテナ各要素の任意桁でビットが1になっている数を返す関数
		@note
		 半開区間[b, e)でi桁目ビットが1になっている数を返す。
		 flipをtrueにするとビットが0になっている数を返す。
		 sumは初期値で通常デフォルト引数のままで良い。
		**/
		template <class T> static ll Count(T b, T e, ll i, bool flip, ll sum = 0)
		{
			for (auto it = b; it != e; ++it) sum += Test(*it, i, flip);
			return sum;
		}

		/**
		@brief 任意範囲でビットが1になっている数を返す関数
		@note
		 結果はBit::Test()と同じ。
		**/
		static ll Count(ll x, ll b, ll e, ll sum = 0)
		{
			rep(i, b, e) sum += Test(x, i);
			return sum;
		}

		/**
		@brief 任意桁でビットが1になっている数を返す関数
		@note
		 結果はBit::Test()と同じ。
		**/
		static ll Count(ll x, ll i)
		{
			return Test(x, i);
		}

		/**
		@brief 任意桁でビットが1になっている数を返す関数
		@note
		 結果はBit::Test()と同じ。
		 flipがtrueならビットが0になっている数を返す。
		**/
		static ll Count(ll x, ll i, bool flip)
		{
			return Test(x, i, flip);
		}

		/**
		@brief ビットシフトした結果を返す関数
		@note
		 値xをnビット左シフトした結果を10進数で返す。
		**/
		static ll Shift(ll x, ll n)
		{
			return (x << n);
		}

		/**
		@brief サイズを返す関数
		@note
		 値xのサイズを返す。
		**/
		static ll Size(ll x, ll size = 0)
		{
			while (Pow2(size) <= x) size++;
			return size;
		}

		/**
		@brief 任意桁のビットを返す関数
		@note
		 値xのi桁目ビットを返す。
		**/
		static ll Test(ll x, ll i)
		{
			return ((x & Shift(1, i)) != 0) ? 1 : 0;
		}

		/**
		@brief 任意桁のビットを返す関数
		@note
		 値xのi桁目ビットを返す。
		 flipがtrueなら反転したビットを返す。
		**/
		static ll Test(ll x, ll i, bool flip)
		{
			if (flip)
				return ((x & Shift(1, i)) != 0) ? 0 : 1;
			else
				return ((x & Shift(1, i)) != 0) ? 1 : 0;
		}

		/**
		@brief 任意桁のビットを10進数に変換して返す
		@note
		 値xのi桁目ビットを10進数に変換して返す。
		**/
		static ll To10(ll x, ll i)
		{
			return Test(x, i) * Pow2(i);
		}
	};
}

using namespace NyaGadget;

struct Edge
{
	ll u;
	ll v;
	ll w;
};



int main(void)
{
	ll L; cin >> L;

	ll N = 0;
	while (Pow2(N) < L) N++;

	vt<Edge> ans;
	rep(i, 0, N)
	{
		ans.push_back({ i, i + 1, 0 });
		ans.push_back({ i, i + 1, Pow2(i) });
	}

	ll newl = Pow2(N);
	repr(i, N-1, -1)
	{
		if (Bit::Test(L, i) == 1)
		{
			ans.push_back({ i-1, i, newl });
			newl += Pow2(i - 1) - 1;
		}
	}

	cout << N+1 << " " << Size(ans) << endl;
	each(i, e, ans) cout << e->u + 1 << e->v + 1 << e->w << endl;

	return 0;
}