#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  long long n;
  scanf("%lld", &n);
  vector<long long> a(n + 2);
  a[0] = -1LL;
  long long prev[n + 1];
  long long fow[n + 1];
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == a[i - 1])
      prev[i] = prev[i - 1];
    else
      prev[i] = i;
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == a[i + 1])
      fow[i] = fow[i + 1];
    else
      fow[i] = i;
  }
  a[n + 1] = 1e9 + 10;
  vector<long long> inc, dec;
  for (int i = 1; i <= n; i++)
    if (a[i] > a[i + 1]) {
      inc.push_back(i);
      dec.push_back(i + 1);
    }
  if (inc.size() > 2)
    printf("NO");
  else if (inc.size() == 0) {
    printf("YES");
  } else {
    long long m = inc.size();
    for (int i = 0; i <= m - 1; i++)
      for (int j = 0; j <= m - 1; j++) {
        long long in = inc[i];
        long long de = dec[j];
        if (in == de) continue;
        vector<long long> b(a);
        b[prev[in]] = a[fow[de]];
        b[fow[de]] = a[prev[in]];
        long long c = 0;
        for (int i = 1; i <= n; i++)
          if (b[i - 1] <= b[i]) c++;
        if (c == n) {
          cout << "YES";
          return 0;
        }
      }
    cout << "NO";
  }
  return 0;
}
