#include <bits/stdc++.h>
using namespace std;
int a[300000];
int b[300000];
int cmp(const void *x, const void *y) { return *(int *)x - *(int *)y; }
int main() {
  int n, i;
  cin >> n;
  int ok = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
    if (a[i] < a[i - 1]) ok = 1;
  }
  if (n == 2 || !ok) {
    cout << "YES" << endl;
    return 0;
  }
  qsort(a, n + 1, sizeof(a[0]), cmp);
  int c[3], t = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] != b[i]) {
      t++;
      if (t > 2) break;
      c[t] = i;
    }
  }
  if (t > 2)
    cout << "NO" << endl;
  else {
    if (a[c[1]] == b[c[2]] && b[c[1]] == a[c[2]])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
