#include <bits/stdc++.h>
using namespace std;
int arr[222222], tmp[222222];
vector<int> t;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", arr + i), tmp[i] = arr[i];
  sort(tmp, tmp + n);
  for (int i = 0; i < n; ++i)
    if (arr[i] != tmp[i]) t.push_back(i);
  if ((t.size() == 2 && tmp[t[0]] == arr[t[1]] && tmp[t[1]] == arr[t[0]]) ||
      t.empty()) {
    puts("YES");
    return 0;
  }
  puts("NO");
  return 0;
}
