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

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  _ <- BS.readInt <$> BS.getLine
  nums <- readInts
  putStrLn $ solve nums

solve :: [Int] -> String
solve nums
  | ans < 3 = "YES"
  | otherwise = "NO"
  where
    nums' = sort nums
    zipped = zip nums nums'
    ans = sum $ map f zipped
    f (x, y)
      | x == y = 0
      | otherwise = 1
