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

public class Main {

	public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} 
	
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} 
	
} Main public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} main {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} Scanner input = new Scanner (System.in); input new Scanner (System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int []  arr = new int [n]; arr new int [n] n int []  arr2 = new int [n]; arr2 new int [n] n for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		} {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		} arr[i] = input.nextInt() arr[i] arr i input.nextInt() input.nextInt input arr2[i] = arr[i] arr2[i] arr2 i arr[i] arr i Arrays.sort(arr2) Arrays.sort Arrays arr2 int c =0 ; c 0 for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		} int i =0 ; int i =0 ; i 0 i < n i n i++ i++ i {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		} {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		} if (arr[i]!= arr2[i]) {
				c++;
			} arr[i]!= arr2[i] arr[i] arr i arr2[i] arr2 i {
				c++;
			} c++ c if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		} c<=2 c 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" input.close() input.close input String[] args args public class Main {

	public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} 
	
} public class Main {

	public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} 
	
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} 
	
}