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[] sei = new int[n];
		int count = 0;

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	}
} 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[] sei = new int[n];
		int count = 0;

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

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

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] p = new int[n];
		int[] sei = new int[n];
		int count = 0;

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	} main {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] p = new int[n];
		int[] sei = new int[n];
		int count = 0;

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

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

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	}
} 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[] sei = new int[n];
		int count = 0;

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	}
} 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[] sei = new int[n];
		int count = 0;

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

		Arrays.sort(sei);

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

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	}
}