4
90 91 90 91
 4
54 54 54 55
 10
55 39 93 42 97 40 36 38 11 97
 3
90 39 98
 5
21 57 40 94 17
 8
46 4 30 85 52 6 84 13
 6
47 100 96 2 96 43
 4
61 28 3 81
 5
14 91 91 91 84
 3
22 23 24
 1
13
 9
13 80 13 38 98 85 11 73 74
 10
95 51 52 8 44 39 77 17 96 88
 3
40 40 40
 4
16 17 17 18
 3
68 67 67
 4
83 100 81 75
 9
71 71 70 70 71 70 69 70 71
 10
9 9 9 10 10 9 8 8 9 9
 6
87 86 86 86 85 86
 5
64 63 63 62 61
 3
76 9 12
 4
61 60 60 60
 7
23 37 39 8 72 31 85
 10
67 67 67 67 67 67 67 67 67 67
 4
92 18 29 93
 4
14 15 15 16
 10
79 84 22 38 23 22 33 42 13 96
 7
20 21 95 73 49 98 53
 10
28 61 23 73 61 33 45 55 18 43
 9
15 14 14 13 13 12 13 13 14
 5
46 46 47 46 45
 7
35 91 87 78 17 71 63
 3
69 26 73
 10
16 17 16 15 14 15 16 17 16 15
 9
95 7 97 61 90 7 30 65 39
 10
2 83 18 65 58 95 37 51 86 47
 6
59 59 60 60 59 58

YES YES NO NO NO NO NO NO NO YES YES NO NO YES YES YES NO YES YES YES YES NO YES NO YES NO YES NO NO NO YES YES NO NO YES NO NO YES
import java.io.*;
import java.util.*;


public class Solution
{

    static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];

    private int curChar;

    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new RuntimeException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new RuntimeException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public String readString() {
        final StringBuilder stringBuilder = new StringBuilder();
        int c = read();
        while (isSpaceChar(c))
            c = read();
        do {
            stringBuilder.append(c);
            c = read();
        } while (!isSpaceChar(c));
        return stringBuilder.toString();
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    }


    public static void main(String[] args) throws Exception{
        InputReader reader = new InputReader(System.in);

        int n  =reader.readInt();
        int[] arr = new int[n];
        int[] sorted_array = new int[n];
        for(int i = 0;i<n;i++){
            arr[i] = reader.readInt();
            sorted_array[i] = arr[i];
        }
        Arrays.sort(sorted_array);
        int sorted_pointer =n-1;
        Set<Integer> set = new HashSet();
        boolean flag = false;
        while(sorted_pointer>= 0){
            int top_most  = sorted_array[sorted_pointer];
            int index = search(arr, top_most, set);
            if(index == -1){
                System.out.println("NO");
                flag = true;
                break;
            }
            if(index == 0)
            {

                if(n > 1 && top_most - arr[index+1] >= 2)
                {
                    System.out.println("NO");
                    flag = true;
                    break;
                }
                else
                {
                    set.add(index);
                    if(top_most  == sorted_array[sorted_pointer]){
                        sorted_pointer--;
                        continue;
                    }
                    else {
                        System.out.println("NO");
                    }
                }
            }

            else if(index == n-1)
            {
                if(top_most - arr[index-1] >= 2)
                {
                    System.out.println("NO");
                    flag = true;
                    break;
                }
                else
                {
                    set.add(index);
                    if(top_most  == sorted_array[sorted_pointer]){
                        sorted_pointer--;
                        continue;
                    }
                    else {
                        System.out.println("NO");
                    }

                }
            }
            else
            {
                if(top_most - arr[index-1] >= 2)
                {
                    System.out.println("NO");
                    flag = true;
                    break;
                }
                else if(top_most - arr[index+1] >= 2)
                {
                    System.out.println("NO");
                    flag = true;
                    break;
                }
                else
                {
                    set.add(index);
                    if(top_most  == sorted_array[sorted_pointer]){
                        sorted_pointer--;
                        continue;
                    }
                    else {
                        System.out.println("NO");
                        flag = true;
                        break;
                    }
                }
            }
        }
        if(!flag)
            System.out.println("YES");

    }

    public static int search(int[] array, int key, Set<Integer> set)
    {
        for(int i = 0;i<array.length;i++){
            if(array[i] == key)
            {
                if(!set.contains(i))
                    return i;
                else
                   continue;
            }
        }
        return -1;
    }

}