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

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "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 sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] target = new int[n]; target new int[n] n int[] sample = new int[n]; sample new int[n] n for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		} {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		} int input=sc.nextInt(); input sc.nextInt() sc.nextInt sc target[i]=input target[i] target i input sample[i]=input sample[i] sample i input Arrays.sort(sample) Arrays.sort Arrays sample int count=0; count 0 for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(target[i]!=sample[i]) {
				count++;
			}
		} {
			if(target[i]!=sample[i]) {
				count++;
			}
		} if(target[i]!=sample[i]) {
				count++;
			} target[i]!=sample[i] target[i] target i sample[i] sample i {
				count++;
			} count++ count System.out.println(count<=2? "YES": "NO") System.out.println System.out System System.out count<=2? "YES": "NO" count<=2 count 2 "YES" "NO" String args[] args public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	}
} public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	}
}
