import java.util.Scanner;

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