import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		
		
		sc.close();
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			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 count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			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 count=0; count 0 int[] p = new int[N]; p new int[N] N int[] q = new int[N]; q new int[N] N for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		} {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		} int s=sc.nextInt(); s sc.nextInt() sc.nextInt sc p[i]=s p[i] p i s q[i]=s q[i] q i s Arrays.sort(q) Arrays.sort Arrays q for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(p[i]!=q[i]) {
				count++;
			}
		} {
			if(p[i]!=q[i]) {
				count++;
			}
		} if(p[i]!=q[i]) {
				count++;
			} p[i]!=q[i] p[i] p i q[i] q i {
				count++;
			} count++ count if(count<3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		} count<3 count 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" 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 count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			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 count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		
		
		sc.close();
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int count=0;
		int[] p = new int[N];
		int[] q = new int[N];
		
		for(int i=0;i<N;i++) {
			int s=sc.nextInt();
			p[i]=s;
			q[i]=s;
		}
		Arrays.sort(q);
		
		for(int i=0;i<N;i++) {
			if(p[i]!=q[i]) {
				count++;
			}
		}
		
		if(count<3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		
		
		sc.close();
	}
}
