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[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=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 sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	} main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] array = new int[N]; array new int[N] N int[] buff = new int[N]; buff new int[N] N for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			array[i] = sc.nextInt();
		} {
			array[i] = sc.nextInt();
		} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc buff = array.clone() buff array.clone() array.clone array Arrays.sort(buff) Arrays.sort Arrays buff int flg=0; flg 0 for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(array[i]!=buff[i]) {
				flg++;
			}
		} {
			if(array[i]!=buff[i]) {
				flg++;
			}
		} if(array[i]!=buff[i]) {
				flg++;
			} array[i]!=buff[i] array[i] array i buff[i] buff i {
				flg++;
			} flg++ flg if(flg<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		} flg<=2 flg 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 sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=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 sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int[] array = new int[N];
		int[] buff = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		buff = array.clone();
		Arrays.sort(buff);
		int flg=0;
		for(int i=0;i<N;i++) {
			if(array[i]!=buff[i]) {
				flg++;
			}
		}
		if(flg<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}
