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[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            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[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            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[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            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[] nums = new int[N]; nums new int[N] N for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            nums[i]=sc.nextInt();
        } {
            nums[i]=sc.nextInt();
        } nums[i]=sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc int[] nums2 = Arrays.copyOf(nums,nums.length); nums2 Arrays.copyOf(nums,nums.length) Arrays.copyOf Arrays nums nums.length nums nums.length Arrays.sort(nums) Arrays.sort Arrays nums int diff=0; diff 0 for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        } {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        } if(nums2[i]!=nums[i]){
                diff++;
            } nums2[i]!=nums[i] nums2[i] nums2 i nums[i] nums i {
                diff++;
            } diff++ diff if(diff<=2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        } diff<=2 diff 2 {
            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[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            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[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            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[] nums = new int[N];

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}
