import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 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 scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    }
  }
} Main public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    }
  } main {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    }
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int check = 0; check 0 int[] P = new int[N]; P new int[N] N for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    } {
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    } P[i] = scanner.nextInt() P[i] P i scanner.nextInt() scanner.nextInt scanner if(P[i] != i+1){
        check++;
      } P[i] != i+1 P[i] P i i+1 i 1 {
        check++;
      } check++ check if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    } check == 0 || check == 2 check == 0 check 0 check == 2 check 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 scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    }
  }
} public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    }
  }
} Main
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int check = 0;
    
    int[] P = new int[N];
    for(int i = 0; i < N; i++){
      P[i] = scanner.nextInt();
      
      if(P[i] != i+1){
        check++;
      }
    }
    
    //異なる箇所が なし もしくは 2か所 ならばYESとなる
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else{
      System.out.println("NO");
    }
  }
}