import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    }
} import java.util.*; util.* java import java.lang.*; lang.* java import java.util.stream.*; stream.* java.util public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    }
} Main public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    } main {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Integer n = Integer.parseInt(scanner.next()); n Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner Integer[] num_seq = new Integer[n]; num_seq new Integer[n] n for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            num_seq[i] = Integer.parseInt(scanner.next());
        } {
            num_seq[i] = Integer.parseInt(scanner.next());
        } num_seq[i] = Integer.parseInt(scanner.next()) num_seq[i] num_seq i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int count = 0; count 0 boolean[] total = new boolean[n-1]; total new boolean[n-1] n-1 n 1 for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        } int i = 0; int i = 0; i 0 i < num_seq.length -1 i num_seq.length -1 num_seq.length num_seq num_seq.length 1 i++ i++ i {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        } {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        } if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            } num_seq[i] < num_seq[i+1] num_seq[i] num_seq i num_seq[i+1] num_seq i+1 i 1 {
                total[i] = true;
            } total[i] = true total[i] total i true {
                total[i] = false;
                count++;
            } total[i] = false total[i] total i false count++ count if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        } count > 2 count 2 {
            System.out.println("NO");
            System.exit(0);
        } System.out.println("NO") System.out.println System.out System System.out "NO" System.exit(0) System.exit System 0 int tmp = -1; tmp -1 1 int hoge = 0; hoge 0 boolean is_first = true; is_first true for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        } int i = 0; int i = 0; i 0 i < total.length i total.length total total.length i++ i++ i {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        } {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        } if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            } total[i] == false total[i] total i false {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            } if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                } is_first {
                    tmp = i;
                    is_first = false;
                } tmp = i tmp i is_first = false is_first false {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                } hoge = num_seq[tmp] hoge num_seq[tmp] num_seq tmp num_seq[tmp] = num_seq[i+1] num_seq[tmp] num_seq tmp num_seq[i+1] num_seq i+1 i 1 num_seq[i+1] = hoge num_seq[i+1] num_seq i+1 i 1 hoge for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        } int i = 0; int i = 0; i 0 i < num_seq.length -1 i num_seq.length -1 num_seq.length num_seq num_seq.length 1 i++ i++ i {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        } {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        } if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            } !(num_seq[i] < num_seq[i+1]) (num_seq[i] < num_seq[i+1]) num_seq[i] num_seq i num_seq[i+1] num_seq i+1 i 1 {
                System.out.println("NO");
                System.exit(0);
            } System.out.println("NO") System.out.println System.out System System.out "NO" System.exit(0) System.exit System 0 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 scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    }
} public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    }
} Main
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer[] num_seq = new Integer[n];

        for(int i = 0; i < n; i++) {
            num_seq[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        boolean[] total = new boolean[n-1];
        for(int i = 0; i < num_seq.length -1; i++) {
            if(num_seq[i] < num_seq[i+1]) {
                total[i] = true;
            } else {
                total[i] = false;
                count++;
            }
        }

        if(count > 2) {
            System.out.println("NO");
            System.exit(0);
        }

        int tmp = -1;
        int hoge = 0;
        boolean is_first = true;
        for(int i = 0; i < total.length; i++) {
            if (total[i] == false) {
                if(is_first) {
                    tmp = i;
                    is_first = false;
                } else {
                    hoge = num_seq[tmp];
                    num_seq[tmp] = num_seq[i+1];
                    num_seq[i+1] = hoge;
                }
            }
        }

        for(int i = 0; i < num_seq.length -1; i++) {
            if( !(num_seq[i] < num_seq[i+1])) {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
    }
}
