
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- r' :: IO [Int]
    let ss = sort ps
    let eqs = zipWith (==) ps ss
    putStrLn $ case findIndices (== False) eqs of
        [] -> "YES"
        [i,j] -> if ps!!i == ss!!j && ps!!j == ss!!i then "YES" else "No"
        _ -> "NO"





