#include <bits/stdc++.h>
using namespace std;
const int maxn = 100011;
const int maxm = 100000;
const int INF = 1 << 30;
int num[maxn];
int main() {
  int n;
  cin >> n;
  bool flg = true;
  int cnt = 0;
  int frot = -1;
  int idf = -1;
  int last = -1;
  int idlast = -1;
  bool f = true;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (f) {
      if (i == 0)
        num[0] = a;
      else if (a >= num[i - 1])
        num[i] = a;
      else {
        f = false;
        num[i] = a;
        frot = num[i - 1];
        idf = i - 1;
        last = a;
        idlast = i;
      }
    } else {
      num[i] = a;
      if (a < frot) {
        last = a;
        idlast = i;
      }
    }
  }
  if (f)
    cout << "YES" << endl;
  else {
    while (idf && num[idf] == num[idf - 1]) --idf;
    num[idf] = last;
    num[idlast] = frot;
    flg = true;
    for (int i = 1; i < n; ++i) {
      if (num[i] < num[i - 1]) {
        flg = false;
        break;
      }
    }
    if (flg)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
