import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val pl = List.fill(n)(sc.nextInt)

  val illegals = pl.zipWithIndex.map(t => (t._1, t._2 + 1)).filter{t => t._1 != t._2}

  val res = if( illegals.size == 0 || illegals.size == 2 ) "YES" else "NO"

  println(res)

}