let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)

let log2 x =
  let x = x lor (x lsr 1) in
  let x = x lor (x lsr 2) in
  let x = x lor (x lsr 4) in
  let x = x lor (x lsr 8) in
  let x = x lor (x lsr 16) in
  let x = x lor (x lsr 32) in
  popcnt x

let () = Scanf.scanf "%d\n" @@ fun l ->
  let n = log2 l in
  let es = List.concat @@ Array.to_list @@ Array.init (n - 1) @@ fun i ->
    [(i + 1, i + 2, 0); (i + 1, i + 2, 1 lsl i)] @
    if l land (1 lsl i) = 0 then []
    else [i + 1, n, l lxor (l land ((1 lsl (i + 1)) - 1))] in
  Printf.printf "%d %d\n" n (List.length es);
  List.iter (fun (u, v, w) -> Printf.printf "%d %d %d\n" u v w) es

