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