import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  }
}
     import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n int[] arr1 = new int[n]; arr1 new int[n] n for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    } {
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    } arr[i]=sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc arr1[i]=arr[i] arr1[i] arr1 i arr[i] arr i Arrays.sort(arr1) Arrays.sort Arrays arr1 int count=0; count 0 for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      if(arr1[i]!=arr[i]){
        count++;
      }
    } {
      if(arr1[i]!=arr[i]){
        count++;
      }
    } if(arr1[i]!=arr[i]){
        count++;
      } arr1[i]!=arr[i] arr1[i] arr1 i arr[i] arr i {
        count++;
      } count++ count if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    } count>2 count 2 {
      System.out.println("NO");
    } System.out.println("NO") System.out.println System.out System System.out "NO" {
      System.out.println("YES");
    } System.out.println("YES") System.out.println System.out System System.out "YES" String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    int[] arr1 = new int[n];
    for(int i=0;i<n;i++){
       arr[i]=sc.nextInt();
       arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int count=0;
    for(int i=0;i<n;i++){
      if(arr1[i]!=arr[i]){
        count++;
      }
    }
    if(count>2){
      System.out.println("NO");
    }
    else{
      System.out.println("YES");
    }
  }
}
    