#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt = 0;
  cin >> n;
  vector<int> matr(n), ind;
  for (int i = 0; i < n; i++) cin >> matr[i];
  for (int i = 0; i < n - 1 && cnt <= 2; i++)
    if (matr[i] > matr[i + 1]) cnt++, ind.push_back(i);
  bool ent = false;
  if (cnt == 2) {
    swap(matr[ind[0]], matr[ind[1] + 1]);
    for (int i = 0; i < n - 1; i++)
      if (matr[i] > matr[i + 1]) {
        ent = true;
        break;
      }
  } else if (cnt == 1) {
    int j = ind[0] + 1, st = j, k = st - 1;
    for (; k >= 0 && matr[k] == matr[st - 1]; k--)
      ;
    k++;
    for (; j < n && matr[j] == matr[st]; j++)
      ;
    j--;
    swap(matr[k], matr[j]);
    for (int i = 0; i < n - 1; i++)
      if (matr[i] > matr[i + 1]) {
        ent = true;
        break;
      }
  }
  cout << (cnt <= 2 && !ent ? "YES" : "NO") << endl;
  return 0;
}
