#include <bits/stdc++.h>
using namespace std;
int g[100100];
int g2[100100];
int st[100100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &g[i]), g2[i] = g[i];
  sort(g, g + n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (g[i] != g2[i]) st[cnt] = i, cnt++;
  }
  if (cnt == 0)
    printf("YES\n");
  else if (cnt == 2) {
    if (g[st[0]] == g2[st[1]] && g[st[1]] == g2[st[0]])
      printf("YES\n");
    else
      printf("NO\n");
  } else
    printf("NO\n");
  return 0;
}
