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[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {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 input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {count++;}
			
		}
		if(count==0||count==2)
		System.out.println("YES");
		else {
			System.out.println("NO");
		}
			
			
		
		}

	} Main public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {count++;}
			
		}
		if(count==0||count==2)
		System.out.println("YES");
		else {
			System.out.println("NO");
		}
			
			
		
		} main {

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {count++;}
			
		}
		if(count==0||count==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[] num = new int[n]; num new int[n] n int[] numSorted = new int[n]; numSorted new int[n] n int count = 0; count 0 for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		} int i =0; int i =0; i 0 i<n i n i++ i++ i {
			num[i] = input.nextInt();
		} {
			num[i] = input.nextInt();
		} num[i] = input.nextInt() num[i] num i input.nextInt() input.nextInt input for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		} int i =0; int i =0; i 0 i<n i n i++ i++ i {
			numSorted[i]= num[i];
		} {
			numSorted[i]= num[i];
		} numSorted[i]= num[i] numSorted[i] numSorted i num[i] num i Arrays.sort(numSorted) Arrays.sort Arrays numSorted for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {count++;}
			
		} int i =0; int i =0; i 0 i<n i n i++ i++ i {
			if(num[i]!=numSorted[i]) {count++;}
			
		} {
			if(num[i]!=numSorted[i]) {count++;}
			
		} if(num[i]!=numSorted[i]) {count++;} num[i]!=numSorted[i] num[i] num i numSorted[i] numSorted 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 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 input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {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 input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {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 input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {count++;}
			
		}
		if(count==0||count==2)
		System.out.println("YES");
		else {
			System.out.println("NO");
		}
			
			
		
		}

	}


