#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int c[MAXN];
int d[MAXN];
vector<int> b;
int main() {
  int i, j, n;
  scanf("%d", &n);
  b.push_back(0);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b.push_back(a[i]);
  }
  a[n + 1] = 1000000009;
  b.push_back(a[n + 1]);
  sort(b.begin(), b.end());
  for (i = 1; i <= n; i++) {
    c[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    d[i] = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
  }
  int flag = 0;
  for (i = 1; i <= n; i++) {
    if (c[i] <= i && i < d[i]) continue;
    flag++;
  }
  if (flag < 3)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
