#include <bits/stdc++.h>
using namespace std;
const int32_t INFint = 1e9;
const long long INFll = 1e18;
const long long INF = 1LL << 60;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> ar(n);
  for (long long i = 0; i < n; i++) cin >> ar[i];
  long long l = -1, r = -1;
  for (long long i = 0; i < n - 1; i++) {
    if (ar[i] > ar[i + 1]) {
      while (i - 1 >= 0 && ar[i] == ar[i - 1]) {
        i--;
      }
      l = i;
      break;
    }
  }
  for (long long i = n - 1; i >= 1; i--) {
    if (ar[i] < ar[i - 1]) {
      while (i + 1 < n && ar[i] == ar[i + 1]) {
        i++;
      }
      r = i;
      break;
    }
  }
  if (l == -1 || r == -1) {
    cout << "YES" << '\n';
    return 0;
  }
  bool flag = true;
  long long temp = ar[l];
  ar[l] = ar[r];
  ar[r] = temp;
  for (long long i = 0; i < n - 1; i++) {
    if (ar[i] > ar[i + 1]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
}
