let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let prr = Array.init n @@ fun i -> Scanf.scanf "%d " @@ fun d -> (i+1,d) in
  let ans = Array.fold_left (fun ans (i,d) -> if i <> d then ans+1 else ans) 0 prr in
  Printf.printf "%s\n" (if ans <= 2 then "YES" else "NO")