import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p = new int[n]; p new int[n] n for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            p[i] = Integer.parseInt(sc.next());
        } {
            p[i] = Integer.parseInt(sc.next());
        } p[i] = Integer.parseInt(sc.next()) p[i] p i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p2 = p.clone(); p2 p.clone() p.clone p Arrays.sort(p2) Arrays.sort Arrays p2 int tmp = 0; tmp 0 boolean flag = true; flag true for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        } {
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        } if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            } p[i] != p2[i] p[i] p i p2[i] p2 i {
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            } if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                } tmp == 0 tmp 0 {
                    tmp = p[i];
                } tmp = p[i] tmp p[i] p i {
                    if(tmp != p2[i]){
                        flag = false;
                    }
                } if(tmp != p2[i]){
                        flag = false;
                    } tmp != p2[i] tmp p2[i] p2 i {
                        flag = false;
                    } flag = false flag false if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        } flag == true flag true {
            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 = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            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 = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        int[] p2 = p.clone();
        Arrays.sort(p2);
        int tmp = 0;
        boolean flag = true;
        for(int i = 0;i<n;i++){
            if(p[i] != p2[i]){
                if(tmp == 0){
                    tmp = p[i];
                }else{
                    if(tmp != p2[i]){
                        flag = false;
                    }
                }
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}