import java.util.*

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val arr = IntArray(n)
    repeat(n) {
        arr[it] = scanner.nextInt()
    }
    // 1 7 4 5 6 2 9
    val indexes = LinkedList<Int>()
    var p = 0
    for (i in 0 until n) {
        val a = arr[i]
        if (a < p) {
            if (indexes.isEmpty()) {
                indexes.add(i - 1)
            } else {
                indexes.add(i)
            }
        }
        p = a
    }
    if (indexes.isEmpty()) {
        println("YES")
        return
    }
    if (indexes.size != 2) {
        println("NO")
        return
    }
    val left = arr[indexes[0]]
    val leftSmaller = arr.getOrElse(indexes[0] - 1) { 0 }
    val leftBigger = arr.getOrElse(indexes[0] + 1) { 51 }
    val right = arr[indexes[1]]
    val rightSmaller = arr.getOrElse(indexes[1] - 1) { 0 }
    val rightBigger = arr.getOrElse(indexes[1] + 1) { 51 }
    if (right in leftSmaller..leftBigger && left in rightSmaller..rightBigger) {
        println("YES")
    } else {
//        println("NO, $right !in $leftSmaller..$leftBigger nor $left !in $rightSmaller..$rightBigger")
        println("NO")
    }
}
