#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  int idx1, idx2;
  idx1 = n - 1;
  idx2 = 0;
  bool flag1, flag2;
  flag1 = flag2 = false;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      idx1 = i;
      flag1 = true;
      break;
    }
  }
  for (int i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1]) {
      idx2 = i;
      flag2 = true;
      break;
    }
  }
  if (!flag1 && !flag2) {
    cout << "YES" << endl;
    return 0;
  }
  while (idx1 > 0 && a[idx1] == a[idx1 - 1]) {
    idx1--;
  }
  while (idx2 < n - 1 && a[idx2] == a[idx2 + 1]) {
    idx2++;
  }
  int tmp = a[idx1];
  a[idx1] = a[idx2];
  a[idx2] = tmp;
  int c1, c2;
  c1 = c2 = 0;
  for (int i = 0; i < n; i++) {
    if (i < n - 1 && a[i] > a[i + 1]) c1++;
    if (i > 0 && a[i] < a[i - 1]) c2++;
  }
  if (c1 > 0 || c2 > 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}
