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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    }
} import java.util.Arrays; Arrays java.util 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[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

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

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    } main {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n int[] sorted_arr = new int[n]; sorted_arr new int[n] n for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        } {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        } arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in sorted_arr[i] = arr[i] sorted_arr[i] sorted_arr i arr[i] arr i Arrays.sort(sorted_arr) Arrays.sort Arrays sorted_arr int cnt = 0; cnt 0 for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        } {
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        } if(arr[i] != sorted_arr[i]){
                cnt++;

            } arr[i] != sorted_arr[i] arr[i] arr i sorted_arr[i] sorted_arr i {
                cnt++;

            } cnt++ cnt if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        } cnt> 2 cnt 2 {
            System.out.println("NO");
        } System.out.println("NO") System.out.println System.out System System.out "NO" {
            System.out.println("YES");
        } System.out.println("YES") System.out.println System.out System System.out "YES" String[] args args public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    }
} public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    }
}
