import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    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[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
} Main public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  } main {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int p[] = new int[N]; p new int[N] N int check = 0; check 0 for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    } {
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    } p[i] = scan.nextInt() p[i] p i scan.nextInt() scan.nextInt scan 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[] arg arg public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
} public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    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[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int p[] = new int[N];
    int check = 0;

    for (int i = 0; i < N; i++){
      p[i] = scan.nextInt();
      if(p[i] != i+1){
        check++;
      }
    }
    
    if(check == 0 || check == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}