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


