import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      }
} Main public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      } main {
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[]P = new int[N]; P new int[N] N int[]sin = new int[N]; sin new int[N] N int cou = 0; cou 0 for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    } {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    } P[i] = sc.nextInt() P[i] P i sc.nextInt() sc.nextInt sc sin[i] = P[i] sin[i] sin i P[i] P i Arrays.sort(sin) Arrays.sort Arrays sin for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    } {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    } if(P[i]!=sin[i]) {
    		cou++;
    	} P[i]!=sin[i] P[i] P i sin[i] sin i {
    		cou++;
    	} cou++ cou if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      } cou<=2 cou 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 sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      }
} public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]P = new int[N];
    int[]sin = new int[N];
    
    int cou = 0;
    for(int i=0; i<N; i++) {		
    	P[i] = sc.nextInt();
    	sin[i] = P[i]; 
    }
    Arrays.sort(sin);
    
    for(int i=0; i<N; i++) {
    if(P[i]!=sin[i]) {
    		cou++;
    	}
    }
      if(cou<=2){
        System.out.println("YES");
      }else{
        System.out.println("NO");        
      }
      }
}