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

public class Main {

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

	}

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

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

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

	}

}
