import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    }
} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    } main {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int in = Integer.parseInt(s.nextLine()); in Integer.parseInt(s.nextLine()) Integer.parseInt Integer s.nextLine() s.nextLine s String[] in2  = s.nextLine().split(" "); in2 s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " List<Integer> l = new ArrayList<Integer>(); l new ArrayList<Integer>() for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        } int i = 0; int i = 0; i 0 i<in i in i++ i++ i {
            l.add(Integer.parseInt(in2[i]));
        } {
            l.add(Integer.parseInt(in2[i]));
        } l.add(Integer.parseInt(in2[i])) l.add l Integer.parseInt(in2[i]) Integer.parseInt Integer in2[i] in2 i List<Integer> sorted = new ArrayList<Integer>(l); sorted new ArrayList<Integer>(l) Collections.sort(sorted) Collections.sort Collections sorted int count = 0; count 0 for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        } int i = 0; int i = 0; i 0 i<l.size() i l.size() l.size l i++ i++ i {
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        } {
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        } int prev = l.get(i); prev l.get(i) l.get l i int curr = sorted.get(i); curr sorted.get(i) sorted.get sorted i if(prev != curr){
                count++;
            } prev != curr prev curr {
                count++;
            } count++ count System.out.println(count == 0 || count == 2 ? "YES" : "NO") System.out.println System.out System System.out count == 0 || count == 2 ? "YES" : "NO" count == 0 || count == 2 count == 0 count 0 count == 2 count 2 "YES" "NO" String[] args args public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    }
} public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    }
}