import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    }
} import java.util.Arrays; Arrays java.util 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();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    }
} Main public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    } main {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer[] p = new Integer[n]; p new Integer[n] n Integer[] x = new Integer[n]; x new Integer[n] n for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = sc.nextInt();
            x[i] = p[i];
        } {
            p[i] = sc.nextInt();
            x[i] = p[i];
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc x[i] = p[i] x[i] x i p[i] p i Arrays.sort(x) Arrays.sort Arrays x int result = 0; result 0 for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        } int i = 0; int i = 0; i 0 i < n && result <= 2 i < n i n result <= 2 result 2 i++ i++ i {
            if (p[i] != x[i]) {
                result++;
            }
        } {
            if (p[i] != x[i]) {
                result++;
            }
        } if (p[i] != x[i]) {
                result++;
            } p[i] != x[i] p[i] p i x[i] x i {
                result++;
            } result++ result System.out.println(result == 2 || result == 0 ? "YES" : "NO") System.out.println System.out System System.out result == 2 || result == 0 ? "YES" : "NO" result == 2 || result == 0 result == 2 result 2 result == 0 result 0 "YES" "NO" String args[] args public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    }
} public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] x = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }

        Arrays.sort(x);
        int result = 0;
        for (int i = 0; i < n && result <= 2; i++) {
            if (p[i] != x[i]) {
                result++;
            }
        }

        System.out.println(result == 2 || result == 0 ? "YES" : "NO");
    }
}
