import java.util.Scanner;

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

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