import java.util.*;
public class Main {
	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	}

} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	}

} Main public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	} main {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

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

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	}

} public class Main {
	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	}

} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	}

}
