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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n String ans = "YES"; ans "YES" int cnt = 0; cnt 0 for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int[] b = Arrays.copyOf(a, n); b Arrays.copyOf(a, n) Arrays.copyOf Arrays a n Arrays.sort(b) Arrays.sort Arrays b for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        } {
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        } if (a[i] != b[i]) cnt++; a[i] != b[i] a[i] a i b[i] b i cnt++ cnt if (cnt > 2) {
                ans = "NO";
                break;
            } cnt > 2 cnt 2 {
                ans = "NO";
                break;
            } ans = "NO" ans "NO" break; System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    }
} Main
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    }
}