
import java.util.Arrays;
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[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

	}
} import java.util.Arrays; Arrays java.util 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[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int p[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int p[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int p[] = new int[N]; p new int[N] N int psort[] = new int[N]; psort new int[N] N int count = 0; count 0 for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		} {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc psort[i] = p[i] psort[i] psort i p[i] p i Arrays.sort(psort) Arrays.sort Arrays psort for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (!(p[i] == psort[i])) {
				count++;
			}
		} {
			if (!(p[i] == psort[i])) {
				count++;
			}
		} if (!(p[i] == psort[i])) {
				count++;
			} !(p[i] == psort[i]) (p[i] == psort[i]) p[i] p i psort[i] psort i {
				count++;
			} count++ count if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		} count ==2 || count == 0 count ==2 count 2 count == 0 count 0 {
			System.out.print("YES");
		} System.out.print("YES") System.out.print System.out System System.out "YES" {
			System.out.print("NO");
		} System.out.print("NO") System.out.print 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 p[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int p[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

	}
} Main

import java.util.Arrays;
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[] = new int[N];
		int psort[] = new int[N];
		int count = 0;

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			psort[i] = p[i];
		}

		Arrays.sort(psort);

		for (int i = 0; i < N; i++) {
			if (!(p[i] == psort[i])) {
				count++;
			}
		}

		if (count ==2 || count == 0) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}

	}
}