import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    ps <- getIntList
    putStrLn $ if solve ps <= 2 then "YES" else "NO"

solve ps = sum $ zipWith check ps (sort ps)
    where check p q | p == q = 0
                    | otherwise = 1