kr :: [Int] -> [Int] -> Int
kr [] _ = 0
kr _ [] = 0
kr (x:xs) (y:ys) = if x /= y
                      then 1 + kr xs ys
                      else kr xs ys

main = do
    _ <- getLine
    p <- map read . words <$> getLine :: IO [Int]
    putStrLn $ if kr p [1..] <= 2
                then "YES"
                else "NO"
