import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    }

    public static void println(Object o){
        System.out.println(o);
    }
    public static void print(Object o){
        System.out.print(o);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    }

    public static void println(Object o){
        System.out.println(o);
    }
    public static void print(Object o){
        System.out.print(o);
    }
} Main public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    } main {
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    } Scanner sc  = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] p = new int[N]; p new int[N] N int[] pp = new int[N]; pp new int[N] N for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            p[i] = sc.nextInt();
            pp[i] = i+1;
        } {
            p[i] = sc.nextInt();
            pp[i] = i+1;
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc pp[i] = i+1 pp[i] pp i i+1 i 1 int count = 0; count 0 for(int i=0; i<N; i++){
            if(p[i] != pp[i]) count++;
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(p[i] != pp[i]) count++;
        } {
            if(p[i] != pp[i]) count++;
        } if(p[i] != pp[i]) count++; p[i] != pp[i] p[i] p i pp[i] pp i count++ count println(count==2 || count==0 ? "YES" : "NO") println count==2 || count==0 ? "YES" : "NO" count==2 || count==0 count==2 count 2 count==0 count 0 "YES" "NO" String[] args args public static void println(Object o){
        System.out.println(o);
    } println {
        System.out.println(o);
    } System.out.println(o) System.out.println System.out System System.out o Object o o public static void print(Object o){
        System.out.print(o);
    } print {
        System.out.print(o);
    } System.out.print(o) System.out.print System.out System System.out o Object o o public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    }

    public static void println(Object o){
        System.out.println(o);
    }
    public static void print(Object o){
        System.out.print(o);
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    }

    public static void println(Object o){
        System.out.println(o);
    }
    public static void print(Object o){
        System.out.print(o);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        int[] p = new int[N];
        int[] pp = new int[N];

        for(int i=0; i<N; i++){
            p[i] = sc.nextInt();
            pp[i] = i+1;
        }

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

        println(count==2 || count==0 ? "YES" : "NO");
    }

    public static void println(Object o){
        System.out.println(o);
    }
    public static void print(Object o){
        System.out.print(o);
    }
}
