#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)(1e9 + 1e6);
const long long LINF = (long long)(4e18);
const double EPS = 1e-12;
const int MOD = (int)(1e9 + 7);
mt19937 ggen;
void solve();
int n;
vector<int> a, b;
map<int, int> f;
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  ggen = mt19937(1337);
  solve();
  return 0;
}
void solve() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    f[a[i]]++;
  }
  b = a;
  sort((b).begin(), (b).end());
  vector<int> pos;
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[i]) {
      pos.push_back(i);
    }
  }
  if ((int)(pos).size() == 2) {
    if (a[pos[0]] == b[pos[1]] && a[pos[1]] == b[pos[0]]) {
      cout << "YES";
      return;
    }
  } else if ((int)(pos).size() == 0) {
    cout << "YES";
    return;
  }
  cout << "NO";
}
