let iota ?(start=0) ?(step=1) cnt = let rec doit i acc = if i <= 0 then acc else doit (i - 1) (start + step*(i - 1) :: acc) in doit cnt [] let () = let n, m = Scanf.scanf "%d %d " (fun n m -> n, m) in let l = iota ~start:1 n in let rec doit i l = if i = m then l else let a = Scanf.scanf "%d " (fun i -> i) in let a = a - 1 in let rec aux j xs = function | [] -> assert false | hd :: tl -> if j = a then hd :: List.rev_append xs tl else aux (j + 1) (hd :: xs) tl in aux 0 [] l |> doit (i + 1) in match doit 0 l with | [] -> assert false | hd :: _ -> Printf.printf "%d\n" hd