
import java.util.Scanner;


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

import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
         int n = input.nextInt();
    int[] array = new int[n];
    int count =0;
    for(int i=0;i<n;i++){
      array[i] = input.nextInt();
    }
    for(int j=0;j<n;j++){
      if(array [j] != j+1){
        count++;
      }
    }
    if(count == 2 || count == 0){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    }
          
}
