

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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner input = new Scanner(System.in);
		
		int n = input.nextInt();
		
		int[] arr = new int[n];
		
		int[] b = new int[n];
		
		for(int i=0;i<n;i++) {
			arr[i] = input.nextInt();
			b[i] = arr[i];
		}
		
		Arrays.sort(b);
		
		int token = 0;
		
		for(int i=0;i<n;i++) {
			if(b[i]!=arr[i])
				token++;
		}
		
		if(token==0 || token==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) {
		// TODO Auto-generated method stub
		
		Scanner input = new Scanner(System.in);
		
		int n = input.nextInt();
		
		int[] arr = new int[n];
		
		int[] b = new int[n];
		
		for(int i=0;i<n;i++) {
			arr[i] = input.nextInt();
			b[i] = arr[i];
		}
		
		Arrays.sort(b);
		
		int token = 0;
		
		for(int i=0;i<n;i++) {
			if(b[i]!=arr[i])
				token++;
		}
		
		if(token==0 || token==2)
			System.out.println("YES");
		else
			System.out.println("NO");
		
	}

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

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner input = new Scanner(System.in);
		
		int n = input.nextInt();
		
		int[] arr = new int[n];
		
		int[] b = new int[n];
		
		for(int i=0;i<n;i++) {
			arr[i] = input.nextInt();
			b[i] = arr[i];
		}
		
		Arrays.sort(b);
		
		int token = 0;
		
		for(int i=0;i<n;i++) {
			if(b[i]!=arr[i])
				token++;
		}
		
		if(token==0 || token==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) {
		// TODO Auto-generated method stub
		
		Scanner input = new Scanner(System.in);
		
		int n = input.nextInt();
		
		int[] arr = new int[n];
		
		int[] b = new int[n];
		
		for(int i=0;i<n;i++) {
			arr[i] = input.nextInt();
			b[i] = arr[i];
		}
		
		Arrays.sort(b);
		
		int token = 0;
		
		for(int i=0;i<n;i++) {
			if(b[i]!=arr[i])
				token++;
		}
		
		if(token==0 || token==2)
			System.out.println("YES");
		else
			System.out.println("NO");
		
	}

}
