#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  for (int tc = 0; tc < t; tc++) {
    int n;
    cin >> n;
    vector<long long int> arr(n), brr(n);
    for (int i1 = 0; i1 < n; i1++) cin >> arr[i1];
    brr = arr;
    sort(brr.begin(), brr.end());
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (arr[i] != brr[i]) v.push_back(i);
    }
    if (v.size() > 2) {
      cout << "NO"
           << "\n";
      continue;
    }
    if (v.size() == 0) {
      cout << "YES"
           << "\n";
      continue;
    }
    swap(arr[v[0]], arr[v[1]]);
    cout << (arr == brr ? "YES" : "NO") << "\n";
  }
  return 0;
}
