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