import 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];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    }
} 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[] p = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    } 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 for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        } {
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc if(p[i] - 1 != i){
                p[i] = -1;
            } p[i] - 1 != i p[i] - 1 p[i] p i 1 i {
                p[i] = -1;
            } p[i] = -1 p[i] p i -1 1 if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        } n < 3 n 3 {
            System.out.println("YES");
        } System.out.println("YES") System.out.println System.out System System.out "YES" {
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        } Arrays.sort(p) Arrays.sort Arrays p if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            } p[2] == -1 p[2] p 2 -1 1 {
                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" sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    }
} Main
import 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];
        for(int i = 0 ; i < n ; i++ ){
            p[i] = sc.nextInt();
            if(p[i] - 1 != i){
                p[i] = -1;
            }
        }
        if(n < 3){
            System.out.println("YES");
        }else{
            Arrays.sort(p);
            if(p[2] == -1){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        sc.close();

    }
}