#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  int b[n];
  for (i = 0; i < n; i++) b[i] = a[i];
  sort(b, b + n);
  int count = 0;
  int id1, id2;
  for (i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      count++;
      if (count == 1) id1 = i;
      if (count == 2) id2 = i;
    }
  }
  if (count == 0)
    cout << "YES\n";
  else if (count > 2)
    cout << "NO\n";
  else if (count == 1)
    cout << "YES\n";
  else if (count == 2 && a[id1] == b[id2] && b[id1] == a[id2]) {
    cout << "YES\n";
  } else
    cout << "NO\n";
}
