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();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("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();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        }





    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        }





    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        }





    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] input = new int[n]; input new int[n] n for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            input[i] = sc.nextInt();
        } {
            input[i] = sc.nextInt();
        } input[i] = sc.nextInt() input[i] input i sc.nextInt() sc.nextInt sc int[] sorted = Arrays.copyOf(input,input.length); sorted Arrays.copyOf(input,input.length) Arrays.copyOf Arrays input input.length input input.length Arrays.sort(sorted) Arrays.sort Arrays sorted int count = 0; count 0 int[] different = new int[2]; different new int[2] 2 for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        } {
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        } if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            } input[i] != sorted[i] input[i] input i sorted[i] sorted i {
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                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; different[count]=i different[count] different count i count++ count if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        } count ==0 count 0 {
            System.out.println("YES");
        } System.out.println("YES") System.out.println System.out System System.out "YES" if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        } count == 1 count 1 {
            System.out.println("NO");
        } System.out.println("NO") System.out.println System.out System System.out "NO" {
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        } if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            } input[different[0]] == sorted[different[1]] input[different[0]] input different[0] different 0 sorted[different[1]] sorted different[1] different 1 {
                System.out.println("YES");
            } System.out.println("YES") System.out.println System.out System System.out "YES" {
                System.out.println("NO");
            } System.out.println("NO") System.out.println System.out System System.out "NO" String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        }





    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("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();

        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] sorted = Arrays.copyOf(input,input.length);
        Arrays.sort(sorted);

        int count = 0;
        int[] different = new int[2];
        for(int i=0;i<n;i++){
            if(input[i] != sorted[i]){
                if(count ==2){
                    System.out.println("NO");
                    return;
                }
                different[count]=i;
                count++;
            }
        }

        if(count ==0){
            System.out.println("YES");
        }else if(count == 1){
            System.out.println("NO");
        }else{
            if(input[different[0]] == sorted[different[1]]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }


        }





    }
}