import java.util.Scanner;
import java.util.Arrays;
// Arrays.toString(array) 配列arrayの中身を出力する

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.nextLine()); N Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] p = new int[N]; p new int[N] N int cnt = 0; cnt 0 int temp1 = 0; temp1 0 int temp2 = 0; temp2 0 for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    } {
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    } p[i-1] = Integer.parseInt(sc.next()) p[i-1] p i-1 i 1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      } p[i-1] != i p[i-1] p i-1 i 1 i {
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      } cnt += 1 cnt 1 if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        } cnt == 1 cnt 1 {
          temp1 = i-1;
        } temp1 = i-1 temp1 i-1 i 1 if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        } cnt == 2 cnt 2 {
          temp2 = i-1;
        } temp2 = i-1 temp2 i-1 i 1 {
          break;
        } break; if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    } cnt == 0 cnt 0 {
      System.out.println("YES");
    } System.out.println("YES") System.out.println System.out System System.out "YES" if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    } cnt == 2 cnt 2 {
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    } if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      } p[temp2] == temp1+1 && p[temp1] == temp2+1 p[temp2] == temp1+1 p[temp2] p temp2 temp1+1 temp1 1 p[temp1] == temp2+1 p[temp1] p temp1 temp2+1 temp2 1 {
        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" {
      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 = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  }
} Main
import java.util.Scanner;
import java.util.Arrays;
// Arrays.toString(array) 配列arrayの中身を出力する

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  }
}
