#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const double eps = (1e-10);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  int n, arr[100005], arr2[100005], cnt = 0;
  map<int, pair<int, int> > f;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) cin >> arr[i], arr2[i] = arr[i];
  sort(arr2, arr2 + n);
  int curr = arr2[0];
  f[arr2[0]].first = 0;
  for (int i = 0; i < (int)(n); ++i) {
    if (arr2[i] != curr) {
      f[curr].second = i - 1;
      curr = arr2[i];
      f[curr].first = i;
    }
    if (i == n - 1) {
      f[curr].second = i;
    }
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (i < f[arr[i]].first || i > f[arr[i]].second) cnt++;
  }
  if (cnt > 2)
    puts("NO");
  else
    puts("yes");
  return 0;
}
