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

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 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 input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }

} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    } main {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int[] array = new int[n]; array new int[n] n int[] ar = new int[n]; ar new int[n] n for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = input.nextInt();
            ar[i] = array[i];
        } {
            array[i] = input.nextInt();
            ar[i] = array[i];
        } array[i] = input.nextInt() array[i] array i input.nextInt() input.nextInt input ar[i] = array[i] ar[i] ar i array[i] array i Arrays.sort(array) Arrays.sort Arrays array int i = 0 i 0 j = 0; j 0 int count = 0; count 0 while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        } i < array.length && j < array.length i < array.length i array.length array array.length j < array.length j array.length array array.length {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        } if (array[i] != ar[j]) {
                count++;
            } array[i] != ar[j] array[i] array i ar[j] ar j {
                count++;
            } count++ count i++ i j++ j if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        } count > 2 count 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 input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }

} public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 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 input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n];
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = input.nextInt();
            ar[i] = array[i];
        }
        Arrays.sort(array);

        int i = 0, j = 0;
        int count = 0;
        while (i < array.length && j < array.length) {

            if (array[i] != ar[j]) {
                count++;
            }

            i++;
            j++;
        }
        if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }

}