main = do
  n <- readLn
  p <- map read . words <$> getLine
  putStrLn (if (f p [1,2..n]) <= 2 then "YES" else "NO")

f :: [Int] -> [Int] -> Int
f a b
  | a == [] = 0
  | head a == head b = 0 + f (tail a) (tail b)
  | otherwise = 1 + f (tail a) (tail b)
