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