Scanf.scanf "%d" (fun n ->
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in

    let rec check2 prev i sum =
        if i > 30000 then true else
            if (i + sum) mod 2 = 0 &&
               (i + sum) mod 3 = 0 &&
               gcd i sum <> 1 then (Printf.printf "%d %d\n" prev i; false)
            else check2 prev (i + 1) sum
    in

    let rec check i sum =
        if i mod 6 = 5 then check (i + 1) sum else
            if check2 i (i + 1) (sum + i) then check (i + 1) sum
    in

    let rec loop i acc sum =
        if acc = n - 2 then check i sum else
        if i mod 2 = 0 || i mod 3 = 0 then (
            let () = Printf.printf "%d " i in
            let acc = acc + 1 in
            let sum = sum + i in
            loop (i + 1) acc sum
        ) else loop (i + 1) acc sum
    in
    loop 2 0 0
)