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 (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
L = ni()
S = bin(L)[2::]
S=S[::-1]
l=len(S)-1
ans = []
cnt=0
tmp=2**l
for i in range(l-1,-1,-1):
    ans.append((i+1,i+2,2**i));cnt+=1
    ans.append((i+1,i+2,0));cnt+=1
    if S[i]=="1":
        ans.append((i+1,l+1,tmp))
        cnt+=1
    tmp+=2**i*int(S[i])
print(l+1,cnt)
for u,v,w in ans:
    print(u,v,w)

Solution (Python):
l=int(input())



n=l.bit_length()
abc=[]
v=1
now=0
while l>1:
    if l%2==1:
        abc.append((v,n,l-1))
    abc.append((v,v+1,0))
    abc.append((v,v+1,l//2))
    now+=1
    v+=1
    l//=2
print(n,len(abc))
for u,v,c in abc:
    print(u,v,c)

Solution (Python):
L = int(input())
n = L.bit_length()
path = []
tmp = 1
for i in range(1, n):
    path.append((n-i, n-i+1, 0))
    path.append((n - i, n - i + 1, tmp))
    tmp *= 2
    if (L >> (n - i - 1)) & 1:
        path.append((n - i, n, tmp))
        tmp += 1
print(n, len(path))
for p in path[::-1]:
    print(' '.join(map(str, p)))

Solution (Python):
l = int(input())
bits = []
x = l
while(x>0):
    bits.append(x%2)
    x //= 2

ans = []
n = len(bits)
for i in range(1,n):
    ans.append('{} {} {}'.format(i,i+1,0))
    ans.append('{} {} {}'.format(i,i+1,2**(n-i-1)))

base = 2**(n-1)
for i,bi in enumerate(bits[:-1]):
    if(bi==1):
        ans.append('{} {} {}'.format(1,n-i,base))
        base += 2**i

print('{} {}'.format(n,len(ans)))
print('\n'.join(ans))

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    l = int(input())

    ll = l
    key = 0
    while ll > 0:
        key += 1
        ll //= 2
    
    ans = []
    for i in range(key-1):
        ans.append((i+1, i+2, 0))
        ans.append((i+1, i+2, pow(2, i)))
    
    l -= pow(2, key-1)
    l = bin(l)[2:]
    sub = pow(2, key-1)
    
    for i in range(len(l)):
        if l[i] == '1':
            ans.append((len(l)-i, key, sub))
            sub += pow(2, len(l)-i-1)
    

    print(key, len(ans))
    for a in ans:
        print(*a)




    
if __name__ == "__main__":
    main()

Solution (Python):
l = int(input())
le = l.bit_length()
li = []
for i in range(1, le):
    li.append([i, i + 1, 0])
    li.append([i, i + 1, 1 << (i - 1)])
for i in range(1, le):
    if (1 << (i - 1)) & l:
        l -= 1 << (i - 1)
        li.append([i, le, l])
print(le, len(li))
for i in range(len(li)):
    print(*li[i])

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    l = int(ipt())
    if l <= 60:
        print(2,l)
        for i in range(l):
            print(1,2,i)
        exit()
    else:
        l2 = format(l,'b')
        n = len(l2)
        ans = []
        for i in range(n-1):
            ans.append((i+1,i+2,0))
            ans.append((i+1,i+2,2**i))
        nii = 2**(n-1)
        for i in range(1,n):
            if (l>>(n-1-i))&1:
                ans.append((n-i,n,nii))
                nii += 2**(n-i-1)
        print(n,len(ans))
        for a,b,c in ans:
            print(a,b,c)
    return None

if __name__ == '__main__':
    main()

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    l = int(ipt())
    if l <= 60:
        print(2,l)
        for i in range(l):
            print(1,2,i)
        exit()
    else:
        l2 = format(l,'b')
        n = len(l2)
        ans = [(1,2,0),(1,2,1),(1,2,2),(1,2,3)]
        for i in range(2,n-1):
            ans.append((i,i+1,0))
            ans.append((i,i+1,2**i))
        nii = 2**(n-1)
        for i in range(1,n-2):
            if (l>>(n-1-i))&1:
                ans.append((n-i-1,n-1,nii))
                nii += 2**(n-i-1)
        if (l>>1)&1:
            ans.append((1,n-1,nii))
            ans.append((1,n-1,nii+1))
            nii += 2
        if l&1:
            ans.append((1,n-1,nii))
        print(n-1,len(ans))
        for a,b,c in ans:
            print(a,b,c)
    return None

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
L = int(input())

B = bin(L)[2:]
N = len(B)

ans = []
for i in range(1,N):
    ans.append((i,i+1,0))
    ans.append((i,i+1,2**(N-i-1)))

base = 2**(N-1)
for i,b in enumerate(B[1:]):
    if b == '1':
        ans.append((1,i+2,base))
        base += 2**(N-i-2)

print(N,len(ans))
for a in ans:
    print(*a)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


l = int(input())
n = 20
es = []
for i in range(n-1):
    es.append((i,i+1,0))
    if pow(2,i+1)<=l:
        es.append((i,i+1,pow(2,i)))
v = 1
while v*2<=l:
    v *= 2
for i in range(n-1):
    if l>>i&1 and (l>>i)>1:
        es.append((i,n-1,v))
        v += pow(2,i)
print(20, len(es))
for u,v,c in es:
    print(u+1,v+1,c)

Solution (Python):
import math
l=int(input())
n=int(math.log2(l))+1
m=0
ed=[]
for i in range(n,1,-1):
  if l%2:
    ed.append([1,i,l-1])
    m+=1
    l-=1
  m+=2
  ed.append([i-1,i,0])
  ed.append([i-1,i,l//2])
  l=l//2

print(n,m)
for i in ed:
  print(i[0],i[1],i[2])

Solution (Python):
L=int(input())
N=1
X=1
while X*2<=L:
  N+=1
  X*=2
G=[[(i+1,0),(i+1,1<<i)] for i in range(N)]
G[-1]=[]
L-=X
for i in range(N):
  if L&(1<<i):
    G[i].append((N-1,X))
    X+=(1<<i)
print(N,sum([len(G[i]) for i in range(N)]))
for i in range(N):
  for j in range(len(G[i])):
    print(i+1,G[i][j][0]+1,G[i][j][1])

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

l = inn()
arcs = []
for i in range(21):
    if 2**i>l:
        break
for j in range(1,i):
        arcs.append((j,j+1,0))
        arcs.append((j,j+1,2**(j-1)))
for j in range(i-1):
    if (l>>j)%2!=0:
        l -= 2**j
        arcs.append((j+1,i,l))

print(f"{i} {len(arcs)}")
for f,t,c in arcs:
    print(f"{f} {t} {c}")

Solution (Python):
L = int(input())

bits = format(L, 'b')
n = len(bits)

print(20, n+bits.count('1')+17)

for i in range(1, 20):
    print(i, i+1, 0)
for i in range(1, n):
    print(i, i+1, 1 << (n-i-1))

num = 1 << (n-1)
for i, c in enumerate(bits):
    if i == 0:
        continue
    if c == '1':
        print(1, i+1, num)
        num += 1 << (n-i-1)

Solution (Python):
L = int(input())

r = 0
while 1:
    if 2**(r+1)<=L:
        r += 1
    else:
        break

N = r + 1
M = 0
ans = []

for i in range(1, N):
    ans.append((i, i+1, 2**(i-1)))
    ans.append((i, i+1, 0))
    M += 2

for t in range(1, N)[::-1]:
    if L-(2**(t-1))>=2**r:
        ans.append((t, N, L-(2**(t-1))))
        M += 1
        L -= 2**(t-1)

print(N, M)
for i in ans:
    print(*i)

Solution (Python):
l=int(input())
ans=[]
now=1
while l:
  if l%2==1:
    if l==1:break
    ans.append((now,20,l-1))
    l-=1
  if l==0:break
  ans.append((now,now+1,0))
  ans.append((now,now+1,l//2))
  now+=1
  l//=2
if now!=20:
  ans.append((now,20,0))
print(20,len(ans))
for a in ans:
  print(' '.join(map(str,a)))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))




l  =readint()

ans = []

n = l.bit_length()
for i in range(1,n):
    ans.append([i,i+1,0])
    ans.append([i,i+1,1<<(i-1)])

for i in range(n-1):
    if l & 1<<i:
        ans.append([i+1,n,(l>>(i+1))<<(i+1)])

print(n,len(ans))
for i in range(len(ans)):
    printline(ans[i])

Solution (Python):
L=int(input())
N=L.bit_length()
a=[]
x,y=1,1
for b in range(N-1):
    a.append((x,x+1,0))
    a.append((x,x+1,y))
    x+=1
    y*=2
x=2**(N-1)
for b in range(N-1,-1,-1):
    if L-x>=2**b:
        a.append((b+1,N,x))
        x+=2**b
print(N,len(a))
for l in a:
    print(*l)

Solution (Python):
import sys

import math


from collections import deque

from fractions  import gcd

input=sys.stdin.readline
l=int(input())
n=l.bit_length()
d=[]

for i in range(n-1):
    d.append((i+1,i+2,0))
    d.append((i+1,i+2,2**i))
res=l-2**(n-1)
for i in range(n-1):
    if 2**(n-1-i-1)>l-2**(n-1):
        continue
    x=l-2**(n-1-i-1)
    d.append((n-i-1,n,x))
    l=x
m=len(d)
print(n,m)
for i in d:
  print(*i)

Solution (Python):
l=int(input())
r=l.bit_length()-1
n=r+1
ans=[]
for i in range(n-1):
    ans.append((i+1,i+2,0))
    ans.append((i+1,i+2,2**i))
for i in range(n-1,-1,-1):
    if l-2**i>=2**r:
        ans.append((i+1,n,l-2**i))
        l-=2**i
print(n,len(ans))
for i in ans:
    print(*i,sep=' ')

Solution (Python):
L = int(input())
S = bin(L)[2:]
N = len(S)
ans = []
m = 2**(N-2)
for i in range(1,N):
  ans.append((i,i+1,m))
  ans.append((i,i+1,0))
  m >>= 1
s = '1'
for i,c in enumerate(S[1:],1):
  if c=='1':
    ans.append((1,i+1,int(s,2)<<(N-i)))
  s += c
print(N,len(ans))
for a in ans:
  print(*a)

Solution (Python):
def main():
    L = int(input())

    n = 1
    var = 1  
    while n <= 20 and (var << 1) <= L:
        n += 1
        var <<= 1

    g = tuple(set() for _ in range(n))
    for v in range(n - 1):
        g[v].add((v + 1, 0))  

    t = 1
    for v in range(n - 1):
        g[v].add((v + 1, t))
        t <<= 1

    m = var
    rest = L - var
    for v in range(n - 1, -1, -1):
        if rest >= t:
            g[v].add((n - 1, m))
            rest -= t
            m += (1 << v)
            if rest == 0: break
        t >>= 1

    print(n, sum(len(g[v]) for v in range(n)))
    for v in range(n):
        for u, c in g[v]:
            print(v + 1, u + 1, c)


if __name__ == '__main__':
    main()

Solution (Python):
l = int(input())-1
cnt = 0
for i in range(21):
    if l>>i==0:
        digit = i
        break
    if cnt>0 and (l>>i)&1:
        cnt += 1
    if cnt==0 and (l>>i)&1==0:
        cnt = 1
        z = i
if cnt==0:
    print(digit+1, digit*2)
    for i in range(digit):
        print(i+1, i+2, 0)
        print(i+1, i+2, 2**(digit-i-1))
else:
    cnt -= 1
    print(digit, digit*2+cnt-2)
    accu = 2**(digit-1)
    for i in range(digit-1):
        print(i+1, i+2, 0)
        print(i+1, i+2, 2**(digit-i-2))
        if cnt>1 and (l>>(digit-i-2))&1:
            print(1, i+2, accu)
            accu += 2**(digit-i-2)
            cnt -= 1
        elif z==digit-i-2:
            print(1, i+2, accu)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 9)
    MOD = 10 ** 9 + 7

    L = int(input())

    if L == 2:
        print (2, 2)
        print (1, 2, 0)
        print (1, 2, 1)
        exit()

    L -= 1

    N = len(bin(L)) - 2 


    M = 0
    G = []
    G_append = G.append

    for i in range(N - 1):
        G.append((i + 1, i + 2, 0))
        G.append((i + 1, i + 2, 2 ** (N - 2 - i)))

    
    tmp = 2 ** (N - 1)
    for i in range(N - 2, 0, -1):
        if (L >> i) & 1:
            G.append((1, N - i, tmp))
            tmp += 2 ** i

    if 2 ** (N - 1) == L + 1:
        pass
    else:
        if (L >> 0) & 1:
            G.append((1, N, tmp))
            G.append((1, N, tmp + 1))
        else:
            G.append((1, N , tmp))

    print (N, len(G))
    for g in G:
        print (*g, sep = ' ')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

L = int(input())

if L == 2:
    print (2, 2)
    print (1, 2, 0)
    print (1, 2, 1)
    exit()

L -= 1

N = len(bin(L)) - 2 


M = 0
G = []
G_append = G.append

for i in range(N - 1):
    G.append((i + 1, i + 2, 0))
    G.append((i + 1, i + 2, 2 ** (N - 2 - i)))


tmp = 2 ** (N - 1)
for i in range(N - 2, 0, -1):
    if (L >> i) & 1:
        G.append((1, N - i, tmp))
        tmp += 2 ** i

if 2 ** (N - 1) == L + 1:
    pass
else:
    if (L >> 0) & 1:
        G.append((1, N, tmp))
        G.append((1, N, tmp + 1))
    else:
        G.append((1, N , tmp))

print (N, len(G))
for g in G:
    print (*g, sep = ' ')

Solution (Python):
L = int(input())
cur = 0

N = len(bin(L)) - 2
res = []

for i in range(N - 1):
    res.append([i, i + 1, 0])
    res.append([i, i + 1, 2 ** i])
cur = 2 ** (N - 1)

while cur < L:
    sz = L - cur
    b = len(bin(sz)) - 2
    res.append([b - 1, N - 1, cur])
    cur += 2 ** (b - 1)

print(N, len(res))
for i in res:
    a, b, c = i
    print(a + 1, b + 1, c)

Solution (Python):
def examA():
    S = SI()
    T = SI()
    N = len(S)
    ans = "No"
    for i in range(N):
        cur = S[i:] + S[:i]
        
        if cur==T:
            ans = "Yes"
    print(ans)
    return

def examB():
    H, W = LI()
    S = [SI()for _ in range(H)]
    flag = True
    ans = 0
    print(ans)
    return

def examC():
    L, R = LI()
    ans = inf
    if R-L>=3000:
        R = L+3000

    for l in range(L, R + 1):
        for r in range(l+1, R + 1):
            now = (l*r) %2019
            ans = min(ans,now)
    print(ans)
    return

def examD():
    T = ["dream", "dreamer", "erase", "eraser"]
    S = SI()
    ans = "NO"
    t = ""
    for s in S[::-1]:
        t += s
        if t[::-1] in T:
            t = ""
    if t=="":
        ans = "YES"
    print(ans)
    return

def examE():
    N = 50
    K = I()
    base = K//N
    A = [base+i for i in range(N)]
    rest = K%N
    for i in range(rest):
        A[-i-1] += 1
    print(N)
    print(" ".join(map(str,A)))
    return

def examF():
    N = 20
    C = [2**i for i in range(N)]
    L = I()
    cur = 1
    V = [[i+1, i+2, 0]for i in range(N-1)]
    now = 1
    while(now<N):
        if C[now]<=L:
            cur = C[now]
            V.append([now,now+1,C[now-1]])
            now += 1
        else:
            break
    


    for i in range(now)[::-1]:
        if C[i]<=L-cur:
            cost = cur
            V.append([i+1,N,cost])
            cur += C[i]

    print(N,len(V))
    for s,t,c in V:
        print(s,t,c)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
l=int(input())
n=20
ans=[]
for i in range(19):
  ans.append((i+1,i+2,0))
for i in range(l.bit_length()-1):
  ans.append((i+1,i+2,1<<i))
  m=l-(1<<(i+1))
x=1<<(i+1)
for i in range(m.bit_length()):
  if m&(1<<i):
    ans.append((i+1,n,x))
    x+=(1<<i)
print(n,len(ans))
for i in ans:print(*i)

Solution (Python):
L = int(input())
L -= 1
n = 1
x = 0
ans = []
now = 1
while x + x+1 <= L:
    x += x+1
    n += 1
    ans.append((n-1,n,0))
    ans.append((n-1,n,now))
    now *= 2

now = now // 2
i = n-1
while now >= 1:
    if x + now<= L:
        ans.append((i,n,x+1))
        x += now
        if now == 0:now -= 1
    else:
        now = now // 2
        i -= 1
if x < L:
    ans.append((1,n,L))
print(n,len(ans))
for a in ans:
    print(' '.join(str(i) for i in a))

Solution (Python):
L=int(input())
L-=1
if L!=1:
    n=L.bit_length()
    edge=[]
    for i in range(2,n+1):
        edge.append((i,i-1,0))
        edge.append((i,i-1,2**(i-2)))
    
    bit=[]
    for i in range(0,20):
        if L>>i &1==1:
            bit.append(i)
    
    x=L
    for j in range(len(bit)-1):
        i=bit[j]
        x-=2**i
        edge.append((n,i+1,x))
    edge.append((n,1,L))
    
    M=len(edge)
    print(n,M)
    for i in range(M):
        j,k,cost=edge[i]
        print(n+1-j,n+1-k,cost)
else:
    print(2,2)
    print(1,2,0)
    print(1,2,1)

Solution (Python):


def main():
    l = int(input())
    r = len(bin(l)[2:]) - 1
    n = r + 1
    edges = []
    for i in range(1, n):
        edges.append((i, i + 1, 0))
        edges.append((i, i + 1, 2 ** (i - 1)))

    for t in reversed(range(1, n)):
        if l - 2 ** (t - 1) >= 2 ** r:
            edges.append((t, n, l - 2 ** (t - 1)))
            l -= 2 ** (t - 1)
    print(n, len(edges))
    for u, v, w in edges:
        print(u, v, w)

if __name__ == "__main__":
    main()

Solution (Python):


def main():
    l = int(input())
    r = 0
    while True:
        if 2 ** (r + 1) <= l:
            r += 1
        else:
            break
    n = r + 1
    edges = []
    for i in range(1, n):
        edges.append((i, i + 1, 0))
        edges.append((i, i + 1, 2 ** (i - 1)))

    for t in reversed(range(1, n)):
        if l - 2 ** (t - 1) >= 2 ** r:
            edges.append((t, n, l - 2 ** (t - 1)))
            l -= 2 ** (t - 1)
    print(n, len(edges))
    for u, v, w in edges:
        print(u, v, w)

if __name__ == "__main__":
    main()

Solution (Python):
l = int(input())

t = l-1
cnt = 1

edge = []

while t > 0:
    if t % 2 == 0:
        edge.append((cnt, -1, t))
        t -= 1

    k = (t+1)//2
    edge.append((cnt, cnt+1, 0))
    edge.append((cnt, cnt+1, k))
    t = k-1
    cnt += 1

print(cnt, len(edge))

for u, v, w in edge:
    if v == -1:
        v = cnt
    print(u, v, w)

Solution (Python):
l = int(input())

n = 20
e = []
for i in range(n - 2):
    e.append([i + 1, i + 2, 0])
    e.append([i + 1, i + 2, 2 ** i])
i = 0
while l:
    if (l >> i) & 1 == 1:
        l -= 1 << i
        e.append([i + 1, n, l])
    i += 1
if e[-1][0] == n:
    e.pop()
    e.append([n - 1, n, 0])
    e.append([n - 1, n, 2 ** (n - 2)])

print(n, len(e))
for a, b, c in e:
    print(a, b, c)

Solution (Python):
l = int(input())

r = 1
power = 2
while power * 2 <= l:
    power *= 2
    r += 1

n = r + 1
m = 0
adj = [[] for _ in range(n + 1)]

power = 1
for i in range(1, n):
    adj[i].append([i+1, power])
    adj[i].append([i+1, 0])
    power *= 2
    m += 2

power = 2 ** (n - 1)
base = pow(2, r)
for t in range(n - 1, 0, -1):
    power //= 2
    if l - power >= base:
        adj[t].append([n, l - power])
        l -= power
        m += 1

print(n, m)
for i, edges in enumerate(adj[1:], 1):
    for j, w in edges:
        print(i, j, w)

Solution (Python):
L = int(input())
N = min(L.bit_length()-1, 19) + 1
base = (1 << N - 1) - 1

edges = []
for i in range(1, N):
  edges.append([i, i+1, 0])
  edges.append([i, i+1, 1<<(i-1)])

for t in range(N-1, 0, -1):
  l = 1 << (t-1)
  if L - l > base:
    edges.append([t, N, L - l])
    L -= l

M = len(edges)
print(N, M)
for edge in edges:
  print(*edge)

Solution (Python):
l=int(input())
d=l.bit_length()
graph=[]
for i in range(d-1):
  graph.append((i+1,i+2,0))
  graph.append((i+1,i+2,2**(d-i-2)))
s=1<<(d-1)
for i in reversed(range(d-1)):
  if (1<<i)&l:
    graph.append((1,d-i,s))
    s+=1<<i
print(d,len(graph))
for u,v,c in graph:
  print(u,v,c)

Solution (Python):
import sys
input = sys.stdin.readline
L = int(input()) - 1
N = L.bit_length() + 1
res = []
for x in range(2, N):
  res.append((x, x + 1, 0))
  res.append((x, x + 1, pow(2, N - x - 1)))

b = bin(L)[2: ]
t = 0
for i in range(N - 1):
  if int(b[i]):
    res.append((1, i + 2, t))
  t += pow(2, N - i - 2) * int(b[i])
res.append((1, N, t))
res.sort()
if N > 20:
  rres = []
  for r in res:
    if r[0] == 1:
      if r[1] == 2: continue
      rres.append((r[0], r[1] - 1, r[2]))
    else: rres.append((r[0] - 1, r[1] - 1, r[2]))
  print(N - 1, len(rres))
  for r in rres: print(*r)
else:
  print(N, len(res))
  for r in res: print(*r)

Solution (Python):
L = int(input())
ans = []
N = 20
M = 0
for i in range(1, N-1):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 1<<(i-1)))
    M+=2
if L>=(1<<N-1):
    ans.append((N-1, N, 0))
    ans.append((N-1, N, 1<<(N-2)))    
    M+=2
    cnt = (1<<N-1)
    L-=(1<<N-1)
else:
    cnt = 0
for i in range(N-1):
    if L&(1<<i):
        ans.append((i+1, N, cnt))
        M+=1
        cnt+=(1<<i)
print(N, M)
for i in range(M):
    print(*ans[i])

Solution (Python):
L = int(input())

edges = []
v = 1
m = 1
while m <= L//2:
    edges.append((v, v+1, 0))
    edges.append((v, v+1, m))
    v += 1
    m *= 2

wt = m
for d in range(v-1):
    if L & (1<<(v-2-d)):
        edges.append((v-1-d, v, wt))
        wt += (1<<(v-2-d))

print(v, len(edges))
for u, v, w in edges:
    print(u, v, w)

Solution (Python):
def main():
    lint=int(input())
    l=bin(lint-1)[2:]
    le=len(l)
    if le<20:
        ans=[[1,2,0]]
        if 2**le==lint:
            ans.append([1,2,2**(le-1)])
        for i in range(2,le+1):
            ans.append([i,i+1,0])
            ans.append([i,i+1,2**(le-i)])
        memo=[2**(le-i)-1 for i in range(le)]+[0]
        temp=[]
        cnt=0
        for i in range(le):
            if l[i]=="1":
                cnt+=2**(le-i-1)
                temp.append(cnt)
        for i in range(le-1,-1,-1):
            if l[i]=="1":
                temp.pop()
            else:
                break
        temp+=[10**9]
        cnt=0
        for i in range(le+1):
            if memo[i]+temp[cnt]<lint:
                ans.append([1,i+1,temp[cnt]])
                cnt+=1
        print(le+1,len(ans))
        for i in ans:
            print(*i)
    else:
        ans=[]
        for i in range(2,le+1):
            ans.append([i-1,i,0])
            ans.append([i-1,i,2**(le-i)])
        memo=[2**(le-i)-1 for i in range(le)]+[0]
        temp=[]
        cnt=0
        for i in range(le):
            if l[i]=="1":
                cnt+=2**(le-i-1)
                temp.append(cnt)
        for i in range(le-1,-1,-1):
            if l[i]=="1":
                temp.pop()
            else:
                break
        temp+=[10**9]
        cnt=0
        for i in range(le+1):
            if memo[i]+temp[cnt]<lint:
                ans.append([1,i,temp[cnt]])
                cnt+=1
        print(le,len(ans))
        for i in ans:
            print(*i)
main()

Solution (Python):
L = int(input())
l = L.bit_length()
graph = []
for i in range(l-1):
    graph.append((i+1, i+2, 0))
    graph.append((i+1, i+2, 2**(l-i-2)))
s = (1 << (l-1))
for i in reversed(range(l-1)):
    if (1 << i) & L:
        graph.append((1, l-i, s))
        s += (1 << i)
print(l, len(graph))
for a, b, c in graph:
    print(a, b, c)

Solution (Python):
L = int(input())

n = 0
M = 0

while L >= 2 ** n:
    n += 1

n -= 1

N = n + 2
ans = []

for i in range(N-2):
    ans.append([i+1,i+2,0])
    M += 1

for i in range(N-2):
    i += 1
    ans.append([i,i+1, 2 ** (N-2-i)])
    M += 1




now = 2 ** n
for i in range(n):

    j = n-1-i
    k = i + 3
    
    if (2 ** j) & L > 0:
        ans.append([1,k-1,now])
        M += 1
        now += 2 ** j

print (N-1,M)
for i in ans:
    print (i[0],i[1],i[2])

Solution (Python):
import math

L = int(input())

N = math.floor(math.log(L, 2)) + 1
ans = []
for i in range(1, N):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 2**(N-i-1)))

tmp = 2 ** (N-1)
for j in range(N-1):
    if L >> j & 1:
        ans.append((1, N-j, (L >> (j+1)) << (j+1)))

print(N, len(ans))
for ans_i in ans:
    print(*ans_i)

Solution (Python):
L = int(input())
l = L.bit_length()

graph = []
for i in range(l-1):
    graph.append((i+1, i+2, 0))
    graph.append((i+1, i+2, 2**(l-i-2)))

s = (1 << (l-1))
for i in reversed(range(l-1)):
    if (1 << i) & L:
        graph.append((1, l-i, s))
        s += (1 << i)

print(l, len(graph))
for a, b, c in graph:
    print(a, b, c)

Solution (Python):
from math import log2
l = int(input())
t = int(log2(l))
g = [[] for _ in range(t + 1)]
for i in range(t):
    g[i].append((i + 1, 0))
    g[i].append((i + 1, 2 ** i))
l -= 2 ** t
c = 2 ** t
for i in range(t):
    if (l >> i) & 1:
        g[i].append((t, c))
        c += 2 ** i
n, m = t + 1, 0
for i in range(t):
    m += len(g[i])
print(n, m)
for i in range(t):
    for node, cost in g[i]:
        print(i + 1, node + 1, cost)

Solution (Python):
import math
L = int(input())
if L >= 2**19: 
    l = 19
else:
    l = int(math.log2(L))

L -= 2**l
cnt = 2**l
M = 2*l
stack = []
for i in range(l,0,-1): 
    while L >= 2**(i-1):
        L -= 2**(i-1)
        stack.append([i,l+1,cnt])
        M += 1
        cnt += 2**(i-1)

N = l+1
print(str(N)+' '+str(M))
for i in range(1,l+1):
    print(str(i)+' '+str(i+1)+' '+'0')
    print(str(i)+' '+str(i+1)+' '+str(2**(i-1)))

for i in range(len(stack)):
    print(str(stack[i][0])+' '+str(stack[i][1])+' '+str(stack[i][2]))

Solution (Python):
L = int(input())
N = L.bit_length()
Ans = []
for i in range(1, N):
    Ans.append((i, i+1, 0))
    Ans.append((i, i+1, 2**(i-1)))
for i in range(1, N):
    if 2**(i-1) & L:
        L -= 2**(i-1)
        Ans.append((i, N, L))
print(N, len(Ans))
for a in Ans:
    print(*a)

Solution (Python):
import math
L = int(input())

t = int(math.log2(L))
ans = []
N = t+1

for i in range(t):
    ans.append((i,i+1,0))
    ans.append((i,i+1,2**i))
offset = 2**t
while True:
    remains = L - offset
    if remains <= 0:
        break

    t = int(math.log2(remains))
    ans.append((t,N-1,offset))

    offset += 2 ** t


print(N,len(ans))
for a,b,l in ans:
    print(a+1,b+1,l)

def check_ans(ans,N):
    assert  N <= 20
    from collections import defaultdict
    d = defaultdict(list)
    for a,b, l in ans:
        d[a].append((b,l))

    def guchoku(d,i=0,l_tmp=0):
        if i==N-1:
            return [l_tmp]
        tmp = []
        for _next,l in d[i]:
            tmp+= guchoku(d,_next,l_tmp+l)
        return tmp
    
    print(tuple(sorted(guchoku(d))) == tuple(range(L)))

Solution (Python):
def gen_graph(i,step,L):
  
  
  if L == 1:
    return [i],[]
  v,e = gen_graph(i+1,2*step,L//2)
  v = [i] + v
  e = e + [(i,i+1,0),(i,i+1,step)]
  
  if L%2 == 0:
    return v,e
  e.append((i,v[-1],step*(L-1)))
  return v,e

L = int(input())

v,e = gen_graph(1,1,L)
print(len(v),len(e))
for a,b,c in e:
  print(a,b,c)

Solution (Python):
l = int(input()) - 1
edge = []
for i in range(1, 20):
    edge.append([i, i+1, 0])

a = 1
count = 0
length = []
while a*2-1 <= l:
    edge.append([count+1, count+2, a])
    length.append(a)
    a *= 2
    count += 1
dest = count+1
val = a
lest = l - (a-1)
lest_sep = []
for i in range(19, -1, -1):
    if lest >= 2**i:
        lest -= 2**i
        lest_sep.append(i)

for item in lest_sep:
    edge.append([item+1, dest, val])
    val += 2**(item)

print(20, len(edge))
for a, b, c in edge:
    print(a, b, c)

Solution (Python):
inp = int(input())
sequ = []
se = 1

incp = inp
while incp:
    if incp > se:
        incp -= se
        sequ.append(se)
        se = se << 1
        
    else:
        break

res=[]
for i in range(len(sequ)):
    res.append([i+1, i+2, 0])
    res.append([i+1, i+2, sequ[i]])

sd = 2**len(sequ)

for i, elem in reversed(list(enumerate(sequ))):
    if 2**(i+1) + sd <= inp:
        
        res.append([i+2, len(sequ)+1, sd])
        sd += 2**(i+1)
        
if sd == inp - 1:
    res.append([1, len(sequ)+1, sd])

print(len(sequ)+1, len(res))
for r in res:
    print(*r)

Solution (Python):
l = int(input())

d = max([d for d in range(30) if 2**d <= l])
n = d+1
m = 2*d
ans = []
for i in range(1, n):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 2**(i-1)))

while l > 2**d:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) > 2**d-1:
            ans.append((i, n, l-2**(i-1)))
            m += 1
            l -= 2**(i-1)
            break

print(n, m)
for a in ans:
    print(*a)

Solution (Python):
from math import log, ceil
l = int(input())

d = max([d if 2**d <= l else 0 for d in range(100)])
n = d+1
m = 2*d
ans = []
for i in range(1, n):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 2**(i-1)))

while l > 2**d:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**d:
            ans.append((i, n, l-2**(i-1)))
            l -= 2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(*a)

Solution (Python):

import sys
import math
INF = float("inf")


def bitsum(n):
    wa = 0
    while n > 0:
        wa += n & 1
        n >>= 1
    return wa


def solve(L: int):
    N = int(math.log2(L))+1
    M = (N-1)*2

    
    K = L-2**(N-1)

    
    M += bitsum(K)

    print(N, M)
    
    for i in range(1, N):
        print(i, i+1, 0)
    
    for i in range(1, N):
        print(i, i+1, 2**(i-1))

    
    
    i = 0
    while K >= 2**i:
        if K & 2**i:
            print(i+1, N, L-2**i)
            L -= 2**i
        i += 1

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  
    solve(L)


if __name__ == '__main__':
    main()