#include <bits/stdc++.h>
using namespace std;

bool solve(vector<int> datos) {
	bool found;
	for (int i = 0; i < datos.size(); i++) {
		if (datos[i] != i+1) {
			found = 0;
			for (int j = i+1; j < datos.size(); j++) {
				if (j == i+1) {
					swap(datos[i],datos[j]);
					found = 1;
				}
			}
			if (!found) return 0;
		} 
	}
	for (int i = 0; i < datos.size(); i++)
		if (datos[i] != i+1) return 0;
	return 1;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> datos(n);
	for (int &i : datos) cin >> i;
	cout << (solve(datos) ? "YES\n" : "NO\n");
	return 0;
}