import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p;
		int count = 0;

		for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
} 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 p;
		int count = 0;

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

		for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p;
		int count = 0;

		for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int p; p int count = 0; count 0 for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		} int i = 1; int i = 1; i 1 i < n+1 i n+1 n 1 i++ i++ i {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		} {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		} p = sc.nextInt() p sc.nextInt() sc.nextInt sc if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			} p != i p i {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			} count++ count if (count > 2) {
					System.out.println("NO");
					return;
				} count > 2 count 2 {
					System.out.println("NO");
					return;
				} System.out.println("NO") System.out.println System.out System System.out "NO" return; System.out.println("YES") System.out.println System.out System System.out "YES" String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p;
		int count = 0;

		for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p;
		int count = 0;

		for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
} 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 p;
		int count = 0;

		for (int i = 1; i < n+1; i++) {
			p = sc.nextInt();
			if (p != i) {
				count++;
				if (count > 2) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
}
