let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f
let rec calc_n l = if l = 0 then 0 else 1 + calc_n (l/2)

let () = Scanf.scanf "%d" @@ fun l ->
  let n = calc_n l in

  let edges =
    Array.init (n-1) (fun i -> (i, i+1, 1 lsl (n-2-i)))
    |> Array.to_list |> List.rev
  in

  let edges =
    for_fold 1 n (1 lsl (n-1), edges) (fun (m, es) i ->
      if l land (1 lsl (n-1-i)) = 0 then m, es
      else (m + 1 lsl (n-1-i), (0, i, m) :: es)
    ) |> snd |> List.rev in

  Printf.printf "%d %d\n" n (List.length edges);
  List.iter (fun (a, b, c) -> Printf.printf "%d %d %d\n" (a+1) (b+1) c) edges