#include <bits/stdc++.h>
using namespace std;
int a[200010] = {0};
inline void swap(int &a, int &b) {
  int t = b;
  b = a;
  a = t;
}
int main() {
  int n, i, j, c = 0, l, f;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  i = 1;
  j = n;
  while (i < j) {
    if (a[i] <= a[i + 1])
      i++;
    else if (a[j] >= a[j - 1])
      j--;
    else {
      f = i;
      l = j;
      while (a[f] == a[f - 1]) f--;
      while (a[l] == a[l + 1]) l++;
      swap(a[f], a[l]);
      break;
    }
  }
  for (i = 1; i < n; i++) {
    if (a[i] > a[i + 1]) return !(cout << "NO\n");
  }
  cout << "YES\n";
  return 0;
}
