import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    } main {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int count = 0; count 0 String ans = "YES"; ans "YES" for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        } {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        } int a = in.nextInt(); a in.nextInt() in.nextInt in if (i != a) {
                count++;
            } i != a i a {
                count++;
            } count++ count if (count > 2) {
                ans = "NO";
                break;
            } count > 2 count 2 {
                ans = "NO";
                break;
            } ans = "NO" ans "NO" break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
}
