import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    }

}
 import java.awt.*; awt.* java import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java import java.util.List; List java.util public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    }

} Main public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer arr[]=new Integer[n]; arr new Integer[n] n Integer arrToSort[]=new Integer[n]; arrToSort new Integer[n] n for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        } {
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        } arr[i]=sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc arrToSort[i]=arr[i] arrToSort[i] arrToSort i arr[i] arr i Arrays.sort(arr) Arrays.sort Arrays arr int cnt=0; cnt 0 for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        } {
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        } if (!arr[i].equals(arrToSort[i])){
                cnt++;
            } !arr[i].equals(arrToSort[i]) arr[i].equals(arrToSort[i]) arr[i].equals arr[i] arr i arrToSort[i] arrToSort i {
                cnt++;
            } cnt++ cnt if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES"); cnt!=2 && cnt!=0 cnt!=2 cnt 2 cnt!=0 cnt 0 {
            System.out.println("NO");
        } System.out.println("NO") System.out.println System.out System System.out "NO" 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[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    }

} public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    }

} Main
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[]=new Integer[n];
        Integer arrToSort[]=new Integer[n];
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            arrToSort[i]=arr[i];
        }
        Arrays.sort(arr);
        int cnt=0;
        for (int i=0;i<n;i++){
            if (!arr[i].equals(arrToSort[i])){
                cnt++;
            }
        }
        if (cnt!=2 && cnt!=0) {
            System.out.println("NO");
        }else System.out.println("YES");

    }

}

