import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] p = new int[N];
        int[] q = new int[N];

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

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

    }
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] p = new int[N];
        int[] q = new int[N];

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

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

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] p = new int[N];
        int[] q = new int[N];

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

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

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

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

        if(c > 2){
            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 int[] p = new int[N]; p new int[N] N int[] q = new int[N]; q new int[N] N int c = 0; c 0 for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
            p[i] = sc.nextInt();
            q[i] = p[i];
        } {
            p[i] = sc.nextInt();
            q[i] = p[i];
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc q[i] = p[i] q[i] q i p[i] p i Arrays.sort(q) Arrays.sort Arrays q for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(p[i] != q[i]){
                c++;
            }
        } {
            if(p[i] != q[i]){
                c++;
            }
        } if(p[i] != q[i]){
                c++;
            } p[i] != q[i] p[i] p i q[i] q i {
                c++;
            } c++ c if(c > 2){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        } c > 2 c 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 sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] p = new int[N];
        int[] q = new int[N];

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

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

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] p = new int[N];
        int[] q = new int[N];

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

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

    }
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] p = new int[N];
        int[] q = new int[N];

        int c = 0;

        for(int i = 0; i<N; i++){
            p[i] = sc.nextInt();
            q[i] = p[i];
        }
        Arrays.sort(q);

        for(int i = 0; i < N; i++){
            if(p[i] != q[i]){
                c++;
            }
        }

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

    }
}