#include <bits/stdc++.h>
using namespace std;
using vl = vector<long long>;
using vpl = vector<pair<long long, long long>>;
using vs = vector<string>;
using pl = pair<long long, long long>;
using ll = long long int;
using vb = vector<bool>;
void printcase(ll x) { cout << "Case #" << x << ": "; }
void read(vector<ll> &v, ll &n) {
  for (ll i = 0; i < n; ++i) cin >> v[i];
}
void read(ll a[], ll &n) {
  for (ll i = 0; i < n; ++i) cin >> a[i];
}
void print() { cout << endl; }
void write(vector<ll> &v, ll &n) {
  for (ll i = 0; i < n; ++i) cout << v[i] << " ";
  cout << endl;
}
void write(vector<ll> &v) {
  ll n = v.size();
  for (ll i = 0; i < n; ++i) cout << v[i] << " ";
  cout << endl;
}
void write(ll a[], ll &n) {
  for (ll i = 0; i < n; ++i) cout << a[i] << " ";
  cout << endl;
}
bool sorted(vl &v) {
  ll n = v.size();
  for (int i = 0; i < n - 1; i++) {
    if (v[i] > v[i + 1]) return 0;
  }
  return 1;
}
bool solve() {
  ll n;
  cin >> n;
  vl v(n);
  read(v, n);
  if (n <= 2) return 1;
  vl suff(n), suffind(n), preind(n);
  suff[n - 1] = v[n - 1];
  suffind[n - 1] = n - 1;
  preind[0] = 0;
  for (int i = 1; i < n; i++) {
    if (v[i] == v[i - 1])
      preind[i] = preind[i - 1];
    else
      preind[i] = i;
  }
  for (int i = n - 2; i >= 0; i--) {
    if (v[i] < suff[i + 1])
      suffind[i] = i;
    else
      suffind[i] = suffind[i + 1];
    suff[i] = min(v[i], suff[i + 1]);
  }
  for (int i = 0; i < n - 1; i++) {
    if (v[i] > v[i + 1]) {
      swap(v[preind[i]], v[suffind[i + 1]]);
      if (sorted(v))
        return 1;
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  if (solve())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
