#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), diff;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; ++i)
    if (a[i] != b[i]) diff.push_back(i);
  if (diff.size() == 0) {
    cout << "YES" << endl;
    return 0;
  }
  if (diff.size() > 2 || diff.size() == 1) {
    cout << "NO" << endl;
    return 0;
  }
  if (a[diff[0]] == b[diff[1]] && a[diff[1]] == b[diff[0]]) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}
