import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	} main {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] in = new int[N]; in new int[N] N int diff =0; diff 0 for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		} int i =0; int i =0; i 0 i<N i N i++ i++ i {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		} {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		} in[i] = scan.nextInt() in[i] in i scan.nextInt() scan.nextInt scan if (i+1 == in[i]) {
				continue;
			} i+1 == in[i] i+1 i 1 in[i] in i {
				continue;
			} continue; diff++ diff if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		} diff ==0 || diff ==2 diff ==0 diff 0 diff ==2 diff 2 {
			System.out.println("YES");
		} System.out.println("YES") System.out.println System.out System System.out "YES" {
			System.out.println("NO");
		} System.out.println("NO") System.out.println System.out System System.out "NO" scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] in = new int[N];

		int diff =0;
		for(int i =0;i<N;i++) {
			in[i] = scan.nextInt();
			if (i+1 == in[i]) {
				continue;
			}
			diff++;
		}
		if(diff ==0 || diff ==2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		scan.close();
	}

}