#include <bits/stdc++.h>
using namespace std;
int mark[111111];
int a[111111];
int b[111111];
int n;
int noEle, cnt;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n + 1);
  for (int i = 1; i <= n; i++) {
    if (b[i] != a[i]) {
      noEle++;
      if (noEle % 2 != 0) cnt++;
      if (cnt > 1) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
