#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-7;
int n;
vector<pair<int, int> > a;
int b[100047];
int c[100047];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    c[i] = b[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; ++i) {
    if (c[i] != b[i]) {
      a.push_back(make_pair(c[i], b[i]));
    }
  }
  if (a.size() == 2) {
    if (a[0].first == a[1].second && a[1].first == a[0].second) {
      cout << "YES\n";
      return 0;
    }
  } else if (!a.size()) {
    cout << "YES\n";
    return 0;
  }
  cout << "NO\n";
  return 0;
}
