import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
      a[i]=sc.nextInt();
    int wrong=0;
    for(int i=0;i<n;i++)
      if(a[i]!=(i+1))
        wrong++;
    if(wrong==0||wrong==2)
      System.out.print("YES");
    else
      System.out.print("NO");
  }
} import java.util.*; util.* java class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
      a[i]=sc.nextInt();
    int wrong=0;
    for(int i=0;i<n;i++)
      if(a[i]!=(i+1))
        wrong++;
    if(wrong==0||wrong==2)
      System.out.print("YES");
    else
      System.out.print("NO");
  }
} Main public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
      a[i]=sc.nextInt();
    int wrong=0;
    for(int i=0;i<n;i++)
      if(a[i]!=(i+1))
        wrong++;
    if(wrong==0||wrong==2)
      System.out.print("YES");
    else
      System.out.print("NO");
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
      a[i]=sc.nextInt();
    int wrong=0;
    for(int i=0;i<n;i++)
      if(a[i]!=(i+1))
        wrong++;
    if(wrong==0||wrong==2)
      System.out.print("YES");
    else
      System.out.print("NO");
  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int a[]=new int[n]; a new int[n] n for(int i=0;i<n;i++)
      a[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int wrong=0; wrong 0 for(int i=0;i<n;i++)
      if(a[i]!=(i+1))
        wrong++; int i=0; int i=0; i 0 i<n i n i++ i++ i if(a[i]!=(i+1))
        wrong++; if(a[i]!=(i+1))
        wrong++; a[i]!=(i+1) a[i] a i (i+1) i 1 wrong++ wrong if(wrong==0||wrong==2)
      System.out.print("YES");
    else
      System.out.print("NO"); wrong==0||wrong==2 wrong==0 wrong 0 wrong==2 wrong 2 System.out.print("YES") System.out.print System.out System System.out "YES" System.out.print("NO") System.out.print System.out System System.out "NO" String args[] args
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
      a[i]=sc.nextInt();
    int wrong=0;
    for(int i=0;i<n;i++)
      if(a[i]!=(i+1))
        wrong++;
    if(wrong==0||wrong==2)
      System.out.print("YES");
    else
      System.out.print("NO");
  }
}