import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	}
} import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	} main {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	} Scanner sc = new Scanner(in); sc new Scanner(in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int p[] = new int[N]; p new int[N] N int org[] = new int[N]; org new int[N] N for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			p[i] = sc.nextInt();
			org[i] = p[i];
		} {
			p[i] = sc.nextInt();
			org[i] = p[i];
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc org[i] = p[i] org[i] org i p[i] p i Arrays.sort(p) Arrays.sort Arrays p int check = 0; check 0 for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		} {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		} if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			} p[i]!=org[i] p[i] p i org[i] org i {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			} if(check==2) {
					out.println("NO");
					return;
				} check==2 check 2 {
					out.println("NO");
					return;
				} out.println("NO") out.println out "NO" return; check++ check out.println("YES") out.println out "YES" sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	}
} Main
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		
		int p[] = new int[N];
		int org[] = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
			org[i] = p[i];
		}
		Arrays.sort(p);
		
		int check = 0;
		for(int i=0;i<N;i++) {
			if(p[i]!=org[i]) {
				if(check==2) {
					out.println("NO");
					return;
				}
				check++;
			}
		}
		out.println("YES");
		sc.close();
	}
}