import java.util.Scanner;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  }
} Main public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  } main {
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int count=0; count 0 int a=0; a 0 int b=0; b 0 int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int syo[]=new int[n]; syo new int[n] n for(int i=0;i<n;i++){
      syo[i]=i+1;
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      syo[i]=i+1;
    } {
      syo[i]=i+1;
    } syo[i]=i+1 syo[i] syo i i+1 i 1 int p[]=new int[n]; p new int[n] n for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      p[i]=sc.nextInt();
    } {
      p[i]=sc.nextInt();
    } p[i]=sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      if(syo[i]!=p[i]){
        count++;
      }
    } {
      if(syo[i]!=p[i]){
        count++;
      }
    } if(syo[i]!=p[i]){
        count++;
      } syo[i]!=p[i] syo[i] syo i p[i] p i {
        count++;
      } count++ count if(count==0){
      System.out.println("YES");
    } count==0 count 0 {
      System.out.println("YES");
    } System.out.println("YES") System.out.println System.out System System.out "YES" if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    } count==2 count 2 {
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    } for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      } {
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      } if(syo[i]!=p[i]){
          a=i;
          break;
        } syo[i]!=p[i] syo[i] syo i p[i] p i {
          a=i;
          break;
        } a=i a i break; for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      } int i=a; int i=a; i a i<n i n i++ i++ i {
        if(syo[i]!=p[i]){
          b=i;
        }
      } {
        if(syo[i]!=p[i]){
          b=i;
        }
      } if(syo[i]!=p[i]){
          b=i;
        } syo[i]!=p[i] syo[i] syo i p[i] p i {
          b=i;
        } b=i b i if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      } p[a]==syo[b] && p[b]==syo[a] p[a]==syo[b] p[a] p a syo[b] syo b p[b]==syo[a] p[b] p b syo[a] syo a {
        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" if(count!=0 && count!=2){
      System.out.println("NO");
    } count!=0 && count!=2 count!=0 count 0 count!=2 count 2 {
      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 count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  }
} public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  }
}