import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    }
} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    } main {
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int NUM = scan.nextInt(); NUM scan.nextInt() scan.nextInt scan int[] nums = new int[NUM]; nums new int[NUM] NUM for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < NUM i NUM i++ i++ i {
            nums[i] = scan.nextInt();
        } {
            nums[i] = scan.nextInt();
        } nums[i] = scan.nextInt() nums[i] nums i scan.nextInt() scan.nextInt scan int count = 0; count 0 int leftIntex = -1; leftIntex -1 1 int rightIndex = -1; rightIndex -1 1 for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        } int i = 0; int i = 0; i 0 i < NUM - 1 i NUM - 1 NUM 1 i++ i++ i {
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        } {
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        } if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            } nums[i] > nums[i + 1] nums[i] nums i nums[i + 1] nums i + 1 i 1 {
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            } if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                } count == 1 count 1 {
                    rightIndex = i;
                } rightIndex = i rightIndex i {
                    leftIntex = i;
                } leftIntex = i leftIntex i count++ count if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        } count == 0 count 0 {
            System.out.println("YES");
        } System.out.println("YES") System.out.println System.out System System.out "YES" if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        } count == 1 || count == 2 count == 1 count 1 count == 2 count 2 {
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } String answer = "NO"; answer "NO" for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            } int i = leftIntex + 1; int i = leftIntex + 1; i leftIntex + 1 leftIntex 1 i < NUM i NUM i++ i++ i {
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            } {
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            } if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                } NUM == 2 NUM 2 {
                    answer = "YES";
                } answer = "YES" answer "YES" if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                } nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex] nums[leftIntex+1] > nums[i] nums[leftIntex+1] nums leftIntex+1 leftIntex 1 nums[i] nums i nums[i - 1] < nums[leftIntex] nums[i - 1] nums i - 1 i 1 nums[leftIntex] nums leftIntex {
                    answer = "YES";
                    break;
                } answer = "YES" answer "YES" break; System.out.println(answer) System.out.println System.out System System.out answer if (count >= 3){
            System.out.println("NO");
        } count >= 3 count 3 {
            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 scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    }
} public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    }
} Main
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        int leftIntex = -1;
        int rightIndex = -1;
        for(int i = 0; i < NUM - 1; i++){
            if(nums[i] > nums[i + 1]){
                if(count == 1){
                    rightIndex = i;
                } else {
                    leftIntex = i;
                }
                count++;
            }
        }

        // answer
        if(count == 0){
            System.out.println("YES");
        } else if (count == 1 || count == 2){
            String answer = "NO";
            for(int i = leftIntex + 1; i < NUM; i++){
                if(NUM == 2){
                    answer = "YES";
                } else if(nums[leftIntex+1] > nums[i] && nums[i - 1] < nums[leftIntex]){
                    answer = "YES";
                    break;
                }
            }
            System.out.println(answer);
        } else if (count >= 3){
            System.out.println("NO");
        }


    }
}