import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("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 in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		

	}

} Main public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		

	} main {
	
		Scanner in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int counter= 0; counter 0 int n = in.nextInt(); n in.nextInt() in.nextInt in int[] ara = new int[n]; ara new int[n] n int[] temp_array = new int[n]; temp_array new int[n] n for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		} int i = 0; int i = 0; i 0 i<ara.length i ara.length ara ara.length i++ i++ i {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		} {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		} ara[i] = in.nextInt() ara[i] ara i in.nextInt() in.nextInt in temp_array[i] = ara[i] temp_array[i] temp_array i ara[i] ara i Arrays.sort(temp_array) Arrays.sort Arrays temp_array for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		} int i = 0; int i = 0; i 0 i<ara.length i ara.length ara ara.length i++ i++ i {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		} {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		} if(temp_array[i] != ara[i]) {
			 counter++;
			} temp_array[i] != ara[i] temp_array[i] temp_array i ara[i] ara i {
			 counter++;
			} counter++ counter if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		} counter<=2 counter 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 in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		

	}

} public class Main {

	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		

	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);
		int counter= 0;
		int n = in.nextInt();
		int[] ara = new int[n];
		int[] temp_array = new int[n];
		
		for(int i = 0;i<ara.length;i++) {
			ara[i] = in.nextInt();
			temp_array[i] = ara[i];
		}
		Arrays.sort(temp_array);
		
		
		for(int i = 0;i<ara.length;i++) {
			if(temp_array[i] != ara[i]) {
			 counter++;
			}
		}
	
		
		if(counter<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		

	}

}
