import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer[] list = new Integer[n]; list new Integer[n] n for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            list[i] = sc.nextInt();
        } {
            list[i] = sc.nextInt();
        } list[i] = sc.nextInt() list[i] list i sc.nextInt() sc.nextInt sc Integer[] sorted = Arrays.copyOf(list, n); sorted Arrays.copyOf(list, n) Arrays.copyOf Arrays list n Arrays.sort(sorted) Arrays.sort Arrays sorted String ans = "YES"; ans "YES" int count = 0; count 0 for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        } {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        } if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            } !sorted[i].equals(list[i]) sorted[i].equals(list[i]) sorted[i].equals sorted[i] sorted i list[i] list i {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            } 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) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Integer[] list = new Integer[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Integer[] sorted = Arrays.copyOf(list, n);
        Arrays.sort(sorted);

        String ans = "YES";

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (!sorted[i].equals(list[i])) {
                count++;
                if (count > 2) {
                    ans = "NO";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
}
