open Num let solve k darr = let len_darr = Array.length darr in let chk_darr = Array.make len_darr false in let rec get_len_loop start current result = chk_darr.(current) <- true; let next = darr.(current) in if next = start then result else get_len_loop start next (result + 1) in let rec get_len_loop_sum idx result = if idx >= len_darr then result else ( if chk_darr.(idx) then get_len_loop_sum (idx + 1) result else let len_loop = get_len_loop idx idx 0 in get_len_loop_sum (idx + 1) (result + len_loop) ) in let len_loop = get_len_loop_sum 0 0 |> num_of_int in k >=/ len_loop && mod_num (k -/ len_loop) (Int 2) = (Int 0) let () = let k = read_line () |> fun l -> Scanf.sscanf l "%s %s" (fun s1 s2 -> num_of_string s2) and darr = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string |> List.map (( + ) (-1)) |> Array.of_list in solve k darr |> (function | true -> "YES" | false -> "NO") |> print_endline