Language: C++

#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>

using namespace std;

long long L;

struct edge
{
	int x, y, z;
};

vector<edge> edges;

int main ()
{
	cin >> L;

	for (int i = 2; i < 20; i++)
	{
		edges.emplace_back(i, i+1, 0);
		edges.emplace_back(i, i+1, 1<<(19-i));
	}

	int idx = 20;
	int pow = 0;
	int S = 0;

	edges.emplace_back(1, 20, 0);

	while (L > 0)
	{
		if (L%2 == 1)
		{
			edges.emplace_back(1, idx, S);
			S += 1 << pow;
		}
		pow++;
		idx--;
	}
	
	cout << edges.size() << endl;
	for (const edge& e : edges)
	{
		cout << e.x << " " << e.y << " " << e.z << endl;
	}

}

Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = edge; _Args = {int&, int, int}; _Tp = edge]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = edge; _Args = {int&, int, int}; _Tp = edge; allocator_type = std::allocator<edge>]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int, int}; _Tp = edge; _Alloc = std::allocator<edge>; reference = edge&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:26:21:   required from here
   26 |                 edges.emplace_back(i, i+1, 0);
      |                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: new initializer expression list treated as compound expression [-fpermissive]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'edge::edge(int)'
a.cc:13:8: note: candidate: 'edge::edge()'
   13 | struct edge
      |        ^~~~
a.cc:13:8: note:   candidate expects 0 arguments, 1 provided
a.cc:13:8: note: candidate: 'constexpr edge::edge(const edge&)'
a.cc:13:8: note:   no known conversion for argument 1 from 'int' to 'const edge&'
a.cc:13:8: note: candidate: 'constexpr edge::edge(edge&&)'
a.cc:13:8: note:   no known conversion for argument 1 from 'int' to 'edge&&'
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = edge; _Args = {int, int, int}; _Tp = edge]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = edge; _Args = {int, int, int}; _Tp = edge; allocator_type = std::allocator<edge>]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int, int, int}; _Tp = edge; _Alloc = std::allocator<edge>; reference = edge&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:34:20:   required from here
   34 |         edges.emplace_back(1, 20, 0);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: new initializer expression list treated as compound expression [-fpermissive]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'edge::edge(int)'
a.cc:13:8: note: candidate: 'edge::edge()'
   13 | struct edge
      |        ^~~~
a.cc:13:8: note:   candidate expects 0 arguments, 1 provided
a.cc:13:8: note: candidate: 'constexpr edge::edge(const edge&)'
a.cc:13:8: note:   no known conversion for argument 1 from 'int' to 'const edge&'
a.cc:13:8: note: candidate: 'constexpr edge::edge(edge&&)'
a.cc:13:8: note:   no known conversion for argument 1 from 'int' to 'edge&&'
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = edge; _Args = {int, int&, int&}; _Tp = edge]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = edge; _Args = {int, int&, int&}; _Tp = edge; allocator_type = std::allocator<edge>]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int, int&, int&}; _Tp = edge; _Alloc = std::allocator<edge>; reference = edge&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:40:22:   required from here
   40 |                         edges.emplace_back(1, idx, S);
      |                         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: new initializer expression list treated as compound expression [-fpermissive]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'edge::edge(int&)'
a.cc:13:8: note: candidate: 'edge::edge()'
   13 | struct edge
      |        ^~~~
a.cc:13:8: note:   candidate expects 0 arguments, 1 provided
a.cc:13:8: note: candidate: 'constexpr edge::edge(const edge&)'
a.cc:13:8: note:   no known conversion for argument 1 from 'int' to 'const edge&'
a.cc:13:8: note: candidate: 'constexpr edge::edge(edge&&)'
a.cc:13:8: note:   no known conversion for argument 1 from 'int' to 'edge&&'