main = do
  getLine
  li <- getLine
  let ps = map read $ words li
  let ans = compute ps
  putStrLn $ if ans then "YES" else "NO"

compute :: [Int] -> Bool
compute ps = n <= 2
  where
    n = length $ filter id $ zipWith (/=) ps [1..]
