import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int n[] = new int[N]; n new int[N] N int p[] = new int[N]; p new int[N] N int a = 0; a 0 for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		} {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		} n[i] = i + 1 n[i] n i i + 1 i 1 p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc if (n[i] != p[i]) {
				a++;
			} n[i] != p[i] n[i] n i p[i] p i {
				a++;
			} a++ a sc.close() sc.close sc if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		} a <= 2 a 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" String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n[] = new int[N];
		int p[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			n[i] = i + 1;
			p[i] = sc.nextInt();
			if (n[i] != p[i]) {
				a++;
			}
		}
		sc.close();
		if (a <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
