let ( @! ) lst n = List.nth lst n let read_AB_arr k x = let abArr = Array.make k (0, 0) in let rec read_AB_arr' i = if i >= k then abArr else ( let line = read_line () in let a, b = if i = (x - 1) then (-1, -1) else Str.split (Str.regexp_string " ") line |> List.map int_of_string |> (fun lst -> (lst @! 0, lst @! 1)) in abArr.(i) <- (a, b); read_AB_arr' (i + 1)) in read_AB_arr' 0 let do_swap_cup (cupArr: int array) abArr startIdx step = let swap_cup a b = let tmp = cupArr.(a - 1) in cupArr.(a - 1) <- cupArr.(b - 1); cupArr.(b - 1) <- tmp in let rec do_swap_cup' idx = let a, b = abArr.(idx) in if a <> -1 then ( swap_cup a b; do_swap_cup' (idx + step)) in do_swap_cup' startIdx let diff_cups n arr1 arr2 = let rec diff_cups' idx cnt result = if idx >= n || cnt = 2 then result else ( let nextCnt, nextResult = if arr1.(idx) <> arr2.(idx) then (cnt + 1), (idx + 1) :: result else cnt, result in diff_cups' (idx + 1) nextCnt nextResult) in diff_cups' 0 0 [] |> List.rev let () = let n, k, x = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string |> (fun lst -> (lst @! 0, lst @! 1, lst @! 2)) in let abArr = read_AB_arr k x and cArr = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string |> Array.of_list and cupArr = Array.init n (fun i -> i + 1) in do_swap_cup cupArr abArr 0 1; do_swap_cup cArr abArr (k - 1) (-1); diff_cups n cupArr cArr |> List.map string_of_int |> String.concat " " |> print_endline