let rec for_fold a b v f = if a > b then v else for_fold (a+1) b (f v a) f
let () =
  Scanf.scanf "%d" @@ fun n ->
  let rec f c i m =
    if c = 0 then []
    else if i mod 2 = 0 || i mod 3 = 0 || i mod 5 = 0 then
      i :: f (c-1) (i+1) (m+i)
    else f c (i+1) m
  in
  let xs = List.rev @@ f (n-2) 2 0 in
  let m = List.fold_left (fun s x -> (s+x) mod 30) 0 xs in
  let x0 = List.hd xs in
  for_fold (x0+1) 30000 None (fun z i ->
    match z with
    | Some _ -> z
    | None -> begin
      if (i mod 2) * (i mod 3) * (i mod 5) > 0 then None else
      for_fold (i+1) 30000 None @@ fun z j ->
        match z with
        | Some _ -> z
        | None ->
            if (j mod 2) * (j mod 3) * (j mod 5) > 0 then None else
            if (i+j+m) mod 30 = 0 then Some (i, j) else None
    end)
  |> (fun (Some (y, z)) ->
      List.rev (z::y::xs) |> List.iter (Printf.printf "%d ");
      print_newline ())