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