[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let ps = reads int
    let qs = List.sort ps
    let count = List.fold2 (fun s p q -> if p <> q then s + 1 else s) 0 ps qs
    match count with
    | 0 | 2 -> "YES"
    | _ -> "NO"
    |> printfn "%s"
    0