Buggy python submission (verdict: Time Limit Exceeded):
def n_ary_notation(N, n):
  if N == 0:
    return '0'
  else:
    s = ''
    while N:
      s = str(N % abs(n)) + s
      N -= N % abs(n)
      N //= n
    return s
strL = input()
N = 21
M = 61
K = 2
sl = int(strL) - 1
while True:
  K += 1
  L = n_ary_notation(sl, K)
  N = len(L) * 2
  M = K * (len(L) - 1)
  for l in L:
    M += int(l) + 1
  if N < 21 and M < 61:
    break
print(N, M)
for i, l in enumerate(L[:-1]):
  k = len(L) - 1 - i
  print(2 * i + 1, 2 * i + 3, int(l) * K ** k)
  for j in range(int(l)):
    print(2 * i + 1, 2 * i + 2, j * K ** k)
for i in range(int(L[-1]) + 1):
  print(2 * len(L) - 1, 2 * len(L), i)
for k in range(len(L) - 1):
  s = 2 * (len(L) - k)
  for i in range(K):
    print(2 * (len(L) - k - 1), 2 * (len(L) - k), i * K ** k)

Fixed submission:
L = int(input())
R = 0
while True:
  R += 1
  if 2 ** R > L:
    R -= 1
    break
N = R + 1
M = 2 * R
_L = L
for r in range(R, 0, -1):
  if _L - 2 ** (r - 1) >= 2 ** R:
    M += 1
    _L -= 2 ** (r - 1)
print(N, M)
for i in range(R):
  print(i + 1, i + 2, 2 ** i)
  print(i + 1, i + 2, 0)
for r in range(R, 0, -1):
  if L - 2 ** (r - 1) >= 2 ** R:
    print(r, N, L - 2 ** (r - 1))
    L -= 2 ** (r - 1)

Buggy python submission (verdict: Runtime Error):
def n_ary_notation(N, n):
  if N == 0:
    return '0'
  else:
    s = ''
    while N:
      s = str(N % abs(n)) + s
      N -= N % abs(n)
      N //= n
    return s
strL = input()
N = 21
M = 61
K = 2
l = int(strL) - 1
while True:
  K += 1
  L = n_ary_notation(l, K)
  N = len(L) * 2
  M = K * (len(L) - 1)
  for l in L:
    M += int(l) + 1
  if N < 21 and M < 61:
    break
print(N, M)
for i, l in enumerate(L[:-1]):
  k = len(L) - 1 - i
  print(2 * i + 1, 2 * i + 3, int(l) * K ** k)
  for j in range(int(l)):
    print(2 * i + 1, 2 * i + 2, j * K ** k)
for i in range(int(L[-1]) + 1):
  print(2 * len(L) - 1, 2 * len(L), i)
for k in range(len(L) - 1):
  s = 2 * (len(L) - k)
  for i in range(K):
    print(2 * (len(L) - k - 1), 2 * (len(L) - k), i * K ** k)

Fixed submission:
L = int(input())
R = 0
while True:
  R += 1
  if 2 ** R > L:
    R -= 1
    break
N = R + 1
M = 2 * R
_L = L
for r in range(R, 0, -1):
  if _L - 2 ** (r - 1) >= 2 ** R:
    M += 1
    _L -= 2 ** (r - 1)
print(N, M)
for i in range(R):
  print(i + 1, i + 2, 2 ** i)
  print(i + 1, i + 2, 0)
for r in range(R, 0, -1):
  if L - 2 ** (r - 1) >= 2 ** R:
    print(r, N, L - 2 ** (r - 1))
    L -= 2 ** (r - 1)

Buggy python submission (verdict: Time Limit Exceeded):
def n_ary_notation(N, n):
  if N == 0:
    return '0'
  else:
    s = ''
    while N:
      s = str(N % abs(n)) + s
      N -= N % abs(n)
      N //= n
    return s
strL = input()
N = 21
M = 61
K = 2
while True:
  K += 1
  L = n_ary_notation(int(strL) - 1, K)
  N = len(L) * 2
  M = K * (len(L) - 1)
  for l in L:
    M += int(l) + 1
  if N < 21 and M < 61:
    break
print(N, M)
for i, l in enumerate(L[:-1]):
  k = len(L) - 1 - i
  print(2 * i + 1, 2 * i + 3, int(l) * K ** k)
  for j in range(int(l)):
    print(2 * i + 1, 2 * i + 2, j * K ** k)
for i in range(int(L[-1]) + 1):
  print(2 * len(L) - 1, 2 * len(L), i)
for k in range(len(L) - 1):
  s = 2 * (len(L) - k)
  for i in range(K):
    print(2 * (len(L) - k - 1), 2 * (len(L) - k), i * K ** k)

Fixed submission:
L = int(input())
R = 0
while True:
  R += 1
  if 2 ** R > L:
    R -= 1
    break
N = R + 1
M = 2 * R
_L = L
for r in range(R, 0, -1):
  if _L - 2 ** (r - 1) >= 2 ** R:
    M += 1
    _L -= 2 ** (r - 1)
print(N, M)
for i in range(R):
  print(i + 1, i + 2, 2 ** i)
  print(i + 1, i + 2, 0)
for r in range(R, 0, -1):
  if L - 2 ** (r - 1) >= 2 ** R:
    print(r, N, L - 2 ** (r - 1))
    L -= 2 ** (r - 1)