'use strict';

function main(input) {
  const lines = input.split('\n');
  lines.pop();
  const numberOfElements = parseInt(lines[0], 10);
  const array = lines[1].split(' ').map(x => {
    return parseInt(x, 10);
  });
  console.log(fn(array));
}

function fn(raw) {
  let c = 0;
  raw.sort((a, b) => {
    if (a > b) {
      c++
    }
  });
  if (c < 2) {
    return 'YES';
  }
  return 'NO';
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
