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