import java.util.Scanner
import java.util.ArrayList

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()

    var arraylist = ArrayList<Int>()
    for(i in 0 until N){
       arraylist.add(sc.nextInt())
    }

    var mani_flag = false
    var mani_index : Int
    var imp_flag = false
    for(i in 0 until N-1){
       if(arraylist.elementAt(i) > arraylist.elementAt(i+1)){
           if(mani_flag){
               imp_flag = true
               break
           }else{
               var nowmin = arraylist.elementAt(i+1)
               mani_index = i+1
                for(j in i+2 until N){
                    if(arraylist.elementAt(j) < nowmin){
                        nowmin = arraylist.elementAt(j)
                        mani_index = j
                    }
                }
               val tmp = arraylist.elementAt(i)
               arraylist.removeAt(i)
               arraylist.add(i, nowmin)
               arraylist.removeAt(mani_index)
               arraylist.add(mani_index, tmp)
               mani_flag = true
           }
       }
    }
    for(i in 0 until N - 1){
        if(arraylist.elementAt(i) > arraylist.elementAt(i+1)){
            imp_flag = true
        }
    }
    if(imp_flag){
        println("NO")
    }else{
        println("YES")
    }
}