fun main(args: Array<String>) {
    readLine()!!
    val numList = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var canChange = true
    var ans = "YES"

    for (i in numList.indices) {
        if (numList[i] != i + 1) {
            val where = numList.indexOf(i + 1)
            if (where == -1) {
                ans = "NO"
                break
            }
            if (canChange) {
                numList[where] = numList[i]
                numList[i] = i + 1
                canChange = false
            }else{
                ans = "NO"
                break
            }
        }
    }
    print(ans)
}