"use strict"

function isSortable(args, sorted_args){
  let not_match_cnt = 0
  sorted_args.map((item, key)=>{
    if(sorted_args[key] != args[key]){
      not_match_cnt++
    }
  })
  if(not_match_cnt == 0 || not_match_cnt == 2){
    return true
  }else{
    return false
  }
}

const YES = 'YES'
const NO = 'NO'

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const args_lines = arg_str.split('\n')
const n = args_lines[0]
const target = args_lines[1].split(' ')

if(target.length != n){
  console.log(NO)
  return
}

if(n < 2 ||  50 < n){
  console.log(NO)
  return
}

const args_asc = target.slice().sort((a,b)=>a-b)
const args_desc = target.slice().sort((a,b)=>b-a)

const is_sortable_asc = isSortable(target, args_asc)
const is_sortable_desc = isSortable(target, args_desc)

if(is_sortable_asc || is_sortable_desc){
  console.log(YES)
}else{
  console.log(NO)
}
