import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();
            int tab[] = new int[n];
            for (int i = 0; i < n; i++) {
                tab[i] = in.nextInt();
            }

            boolean nope = false;
            for (int i = 1; i < n; i++) {
                if (Math.abs(tab[i] - tab[i - 1]) >= 2) {
                    nope = true;
                    break;
                }
            }

            if (nope) System.out.println("NO");
            else System.out.println("YES");
        }
    }
}

//package March16;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws java.lang.Exception{
		InputStream inputstream = System.in;
		OutputStream outputstream = System.out;
		InputReader in = new InputReader(inputstream);
		PrintWriter out = new PrintWriter(outputstream);
		Call one = new Call();
		one.solve(in,out);
		out.close();
	}
	static class Call {
		/*
		 	there must have been
		 	sugar in her tears
		 	because
		 	with every heartache
		 	she stayed soft
		 	and made the world a little sweeter

		 */
		public void solve(InputReader in,PrintWriter out) {
			int n = in.nextInt();
			int a[] = new int[n];
			for (int i = 0; i < a.length; i++) {
				a[i] = in.nextInt();
			}
			for(int i=0;i<a.length-1;i++) {
				if(Math.abs(a[i]-a[i+1])>=2) {
					out.println("NO");
					return;
				}
			}
			out.println("YES");
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader (stream),32768);
			tokenizer = null;
		}
		public String next() {
				while(tokenizer == null || !tokenizer.hasMoreElements()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					}
					catch(IOException e) {
						throw new RuntimeException(e);
					}
				}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}

import java.io.IOException;
import java.util.*;

public class Main2 {

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

        List<Integer> raviolli = new ArrayList<>();
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            raviolli.add(in.nextInt());
        }

        while (!raviolli.isEmpty()) {
            int max = raviolli.get(0);
            for (int i = 1; i < raviolli.size(); i++) {
                int current = raviolli.get(i);
                if (current > max) {
                    max = current;
                }
            }

            for (int i = 0; i < raviolli.size(); i++) {
                int item = raviolli.get(i);
                if (item == max) {
                    if (i > 0 && (item - raviolli.get(i - 1)) > 1) {
                        System.out.println("NO");
                        in.close();
                        return;
                    }

                    if (i < raviolli.size() - 1 && (item - raviolli.get(i + 1)) > 1) {
                        System.out.println("NO");
                        in.close();
                        return;
                    }
                }
            }

            int finalMax = max;
            raviolli.removeIf(i -> i == finalMax);
        }

        System.out.println("YES");
    }
}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];

		for (int i = 0; i < arr.length; i++) {
		   arr[i] = sc.nextInt();
		}
		for (int i = 0; i < arr.length-1; i++) {
		   if (Math.abs(arr[i] - arr[i+1]) > 1) {
		       System.out.println("NO");
		       return;
		   }

		}
		System.out.println("YES");
	}

}

import java.util.*;
public class a {
    public static void main (String [] args){
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt();
        int a= sc.nextInt();
        int t = 0;
        for (int i = 1 ;i <n; i++ ){
            int b = sc.nextInt();
            if (Math.abs (a-b)>= 2){
                System.out.println("NO");

                t +=1;
                break;

            }
            a = b;

        }
        if (t == 0)
            System.out.println("YES");
    }

}

import java.util.Scanner;
public class Prob2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner scan=new Scanner(System.in);
int c=0,b,a=scan.nextInt();
int list[] = new int[a];
for(int i=0;i<a;i++) {
b=scan.nextInt();
list[i]=b;
	}
for(int j=0;j<(a-1);j++) {
	if((list[j]-list[j+1])>1) {c++;}
}
if(c>0) {System.out.print("NO");}
else {System.out.print("YES");}
}
}

/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> arr = new ArrayList<>();
		for(int i=0; i<n; i++)
		arr.add(sc.nextInt());
		boolean flag = true;
		for(int i=0; i<n; i++)
		{
		    ListIterator<Integer> li = arr.listIterator();
		    int a=159, max = -150;
		    int index=0, qwerty=0;
		    if(li.hasNext()){
		    a = li.next();
		    max = a;
		        qwerty++;
		    }
		    while(li.hasNext())
		    {
		        int q = li.next();

		        if(Math.abs(a-q)>=2)
		        {
		            flag = false;
		            System.out.println("NO");
		            break;
		        }
		        if(max<q)
		        {
		            max=q;
		            index = qwerty;
		        }
		        a = q;
		        qwerty++;
		    }
		    if(!flag)
		    break;
		    arr.remove(index);
		}
		if(flag)
		System.out.println("YES");

	}
}

import java.util.Scanner;

public class APRILFOOLB {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i<n;i++){
            arr[i] = s.nextInt();
        }
        boolean bool =false;
        for(int i = 0;i<n-1;i++){
            if(Math.abs(arr[i] - arr[i+1]) >= 2){
                bool = true;
                break;
            }
        }
        if(bool){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        }
    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class C0418 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<n; i++)
            a.add(in.nextInt());
        //LinkedList<Integer> b = new LinkedList<>();
        while (!a.isEmpty()) {
            for (int i = 0; i < a.size() - 1; i++)
                if (Math.abs(a.get(i) - a.get(i + 1)) >= 2) {
                    System.out.println("NO");
                    System.exit(0);
                }
            a.remove(a.indexOf(Collections.max(a)));

        }
        System.out.println("YES");
    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arr = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arr.add(scanner.nextInt());
        }
        do{
            for (int i = 1; i < arr.size(); i++) {
                if (Math.abs(arr.get(i) - arr.get(i - 1)) >= 2){
                    System.out.println("NO");
                    return;
                }
            }
            int max = 0;
            int imax = 0;
            for (int i = 0; i < arr.size(); i++) {
                if (arr.get(i) > max){
                    max = arr.get(i);
                    imax = i;
                }
            }

            arr.remove(imax);

        } while (arr.size() > 0);

        System.out.println("YES");

    }
}

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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.Solve(in, out);
        out.close();
    }

    static class TaskC {

        void Solve(InputReader in, PrintWriter out) {
            int n = in.NextInt();
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(in.NextInt());
            for (int j = 0; j < n; j++) {
                for (int i = 0; i < n - 1; i++) {
                    if (Math.abs(a.get(i) - a.get(i + 1)) > 1) {
                        out.println("NO");
                        return;
                    }
                }
                int max = 0;
                int ind = 0;
                for (int i = 0; i < n; i++)
                    if (a.get(i) > max) {
                        ind = i;
                        max = a.get(i);
                    }
                a.remove(ind);
                n--;
            }
            out.println("YES");
        }
    }

    static int GetMax(int[] ar) {
        int max = Integer.MIN_VALUE;
        for (int a : ar) {
            max = Math.max(max, a);
        }
        return max;
    }

    static int GetMin(int[] ar) {
        int min = Integer.MAX_VALUE;
        for (int a : ar) {
            min = Math.min(min, a);
        }
        return min;
    }

    static long GetSum(int[] ar) {
        long s = 0;
        for (int a : ar) s += a;
        return s;
    }

    static int[] GetCount(int[] ar) {
        return GetCount(ar, GetMax(ar));
    }

    static int[] GetCount(int[] ar, int maxValue) {
        int[] dp = new int[maxValue + 1];
        for (int a : ar) {
            dp[a]++;
        }
        return dp;
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String Next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int NextInt() {
            return Integer.parseInt(Next());
        }

        long NextLong() {
            return Long.parseLong(Next());
        }

        double NextDouble() {
            return Double.parseDouble(Next());
        }

        int[] NextIntArray(int n) {
            return NextIntArray(n, 0);
        }

        int[] NextIntArray(int n, int offset) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = NextInt() - offset;
            }
            return a;
        }

        int[][] NextIntMatrix(int n, int m) {
            return NextIntMatrix(n, m, 0);
        }

        int[][] NextIntMatrix(int n, int m, int offset) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = NextInt() - offset;
                }
            }
            return a;
        }

        public long[] NextLongArray(int n) {
            return NextLongArray(n, 0);
        }

        long[] NextLongArray(int n, int offset) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = NextLong() - offset;
            }
            return a;
        }

        long[][] NextLongMatrix(int n, int m) {
            return NextLongMatrix(n, m, 0);
        }

        long[][] NextLongMatrix(int n, int m, int offset) {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = NextLong() - offset;
                }
            }
            return a;
        }
    }
}

import java.util.*;
import java.io.*;
import java.math.*;
public class cf
{
    static int n;
    static int k;
    static String s;
    static int arr[];
    static int brr[];
    public static void main(String args[])throws IOException
    {
        PrintWriter out=new PrintWriter(System.out);
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[]=new int[n];
        for(int i = 0 ;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        int mark[]=new int[n];
        int taken=0;

        while(taken!=n)
        {
            int maxpos=0;
            int max=arr[0];
            int st=0;
            for(int i = 1 ;i<n;i++)
            {
                if(mark[i]==1)
                {
                    st++;
                    continue;
                }
                if(Math.abs(arr[i]-arr[i-st-1])>1)
                {
                    System.out.println("NO");
                    st=0;
                    System.exit(0);
                }
                else
                st=0;
                if(max<arr[i])
                {
                    max=arr[i];
                    maxpos=i;
                }

            }
            mark[maxpos]=1;

            taken++;
        }
        System.out.println("YES");
    }

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE];bufferPointer = bytesRead = 0;
        }
        public int nextInt() throws IOException
        {
            int ret = 0;byte c = read();
            while (c <= ' ')c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do{ret = ret * 10 + c - '0';}  while ((c = read()) >= '0' && c <= '9');
            if (neg)return -ret;
            return ret;
        }
        public String next() throws IOException
        {
            byte[] buf = new byte[500000];int cnt = 0, c;
            while ((c = read()) != -1){ if (c == '\n') break; buf[cnt++] = (byte) c;}
            return new String(buf, 0, cnt);
        }
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class CF952C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean slid = false;
		int l = sc.nextInt();
		ArrayList<Integer> arr = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for(int i=0; i<l; i++) arr.add(sc.nextInt());
		for(int x=0; x<l; x++) {
			if(hasDiff(arr) || hasDiff(sorted)) {
				slid = true;
				break;
			}
			int index = getMax(arr);
			sorted.add(arr.get(index));
			arr.remove(index);
		}
		System.out.println(slid ? "NO" : "YES");
	}

	static int getMax(ArrayList<Integer> arr) {
		int index = -1;
		int max = -1;
		for(int i=0; i<arr.size(); i++)
			if(arr.get(i)>max) {
				max = arr.get(i);
				index = i;
			}
		return index;
	}

	static boolean hasDiff(ArrayList<Integer> arr) {
		for(int i=1; i<arr.size(); i++)
			if(Math.abs(arr.get(i)-arr.get(i-1))>=2) return true;
		return false;
	}
}

import java.util.Scanner;

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

	int n=s.nextInt();
	int[] a=new int[n];
	int t=0;
	while(n-->0)
	{
		a[t]=s.nextInt();
		t++;
	}
	for (int i = 0; i < a.length-1; i++)
	{
		if(Math.abs(a[i]-a[i+1])>=2)
		{
			System.out.println("NO");
			return;
		}
	}
	System.out.println("YES");
}
}

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

/* Name of the class has to be "Main" only if the class is public. */
public class Question1
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int h = s.nextInt();
		int a[]=new int[h];
		for(int i=0;i<h;i++)
		{a[i] = s.nextInt();

		}

		int k=0;
		for(int i=1;i<h;i++){
			if(Math.abs(a[i]-a[i-1])>=2)
				k=1;
		}
		if(k == 1)
			System.out.println("No");
		else
		System.out.println("Yes");
	}
}

import java.util.ArrayList;
import java.util.Scanner;

public class C2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        ArrayList<Integer> a = new ArrayList();
        for(int i = 0; i < n; i++){
            a.add(in.nextInt());
        }
        while(a.size() > 0){
            for(int i = 0; i < n - 1; i++){
               if (Math.abs(a.get(i + 1) - a.get(i)) > 1){
                   System.out.println("NO");
                   return;
               }
            }
            int max = -1;
            for(int i = 0; i < n; i++){
               if(a.get(i) > max) {
                   max = a.get(i);
               }
            }
            for(int i = 0; i< n; i++){
                if(a.get(i) == max){
                    a.remove(i);
                    n--;
                }
            }
        }
        System.out.println("YES");
    }
}

import java.util.*;
public class C952 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), inArr[] = new int[n], outArr[] = new int[n];

		for(int i=0; i<n; i++)
		{
			inArr[i] = in.nextInt();
			outArr[i] = inArr[i];
		}

		Arrays.sort(outArr);

		for(int i=1; i<n; i++)
		{
			if(Math.abs(outArr[i]-outArr[i-1]) > 1)
			{
				System.out.println("NO");
				return;
			}
			if(Math.abs(inArr[i]-inArr[i-1]) > 1)
			{
				System.out.println("NO");
				return;
			}
		}

		System.out.println("YES");
	}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class RavioliSort {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int n = r.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = r.nextInt();
		}
		int k = arr.length;
		while (k > 0) {
			for (int i = 0; i < k - 1; i++) {
				if (Math.abs(arr[i] - arr[i + 1]) >= 2) {
					System.out.println("NO");
					System.exit(0);
				}
			}
			int max = -1;
			int index = -1;
			for (int i = 0; i < k; i++) {
				if (arr[i] > max) {
					max = arr[i];
					index = i;
				}
			}
			for (int i = index; i < k - 1; i++) {
				arr[i] = arr[i + 1];
			}
			arr[k - 1] = max;
			k--;
		}
		System.out.println("YES");
	}

	private static boolean isSorted(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i] > arr[i + 1])
				return false;
		}
		return true;
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

import java.util.*;

public class rav {

	public static void main(String[] args) {

		Scanner qwe = new Scanner(System.in);

		int n = qwe.nextInt();
		int[] nums = new int[n];
		for(int i =0; i < n; i++){
			nums[i] = qwe.nextInt();
		}

		String ans = "YES";
		for(int i =0; i < n-1; i++){
			if(Math.abs(nums[i+1] - nums[i] ) > 1) ans = "NO";
		}

		System.out.println(ans);

		qwe.close();
	}

}

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

public class Task3 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        String[] s = in.readLine().split(" ");
        ArrayList<Integer> x = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            x.add(Integer.parseInt(s[i]));
        }
        for (int j = 0; j < n; j++) {
            for (int i = 0; i < n - j - 1; i++) {
                int a = x.get(i);
                int b = x.get(i + 1);
                if (a - b >= 2) {
                    System.out.print("NO");
                    System.exit(0);
                }
            }
        }
        System.out.print("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;
    }

}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class Problem1 {
	public static void main(String[] arg) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new Solver();
		solver.solve(1, in, out);
		out.close();

	}

	static int[] getIntegerArray(int n, InputReader in) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static class Solver {

		private void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int[] num = getIntegerArray(n, in);

			boolean res = true;
			for (int i = 0; i < n - 1; i++) {
				if (Math.abs(num[i] - num[i + 1]) >= 2) {
					res = false;
				}
			}

			if (res) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}

		}
	}

	static class InputReader {
		private StringTokenizer tokenizer;
		private BufferedReader reader;

		public InputReader(InputStream inputStream) {
			reader = new BufferedReader(new InputStreamReader(inputStream));
		}

		private void fillTokenizer() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (Exception e) {
					throw new RuntimeException(e);
				}
			}
		}

		public String next() {
			fillTokenizer();
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}

}

import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner in = new Scanner(System.in);
      int n = in.nextInt();
      int [] arr = new int[n];
      HashSet<Integer> set = new HashSet<>();
      int min = Integer.MAX_VALUE;
      int max = Integer.MIN_VALUE;
      for(int i=0;i<n;i++)
      {
          arr[i] = in.nextInt();
          set.add(arr[i]);
          if(max<arr[i])
          {
              max = arr[i];
          }
          if(arr[i]<min)
          {
              min = arr[i];
          }
      }

      for(int i=0;i<n-1;i++)
      {
         if(Math.abs(arr[i]-arr[i+1])>=2)
         {
            System.out.println("NO");
            return;
         }
      }

      int i = min;
      for(i=min;i<=max;i++)
      {
          if(!set.contains(i))
            {
                break;
            }

      }

      if(i==max+1)
      {
          System.out.println("YES");
          return;
      }
      System.out.println("NO");

    }
}

import java.util.*;

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

        int n,a,b;
        boolean flag = false;
        n = in.nextInt();
        a = in.nextInt();
        for(int i=1; i <n; ++i){
            b = in.nextInt();
            if(Math.abs(b-a) >=2 )
            {
                flag = true;
                break;
            }
            a=b;
        }
        System.out.println( flag ? "No" : "Yes");
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Try
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

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

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

		public int ni() {
			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 nl() {
			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 int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

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

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}
		static PrintWriter w = new PrintWriter(System.out);
 static char [][]sol;
    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    int x = sc.ni();
    int []a = sc.nia(x);
    int f = 0;
    for(int i=1;i<x;i++)
    {
       if(Math.abs(a[i] - a[i-1]) >=2)
           f = 1;
    }
       if(f == 0)
           w.println("YES");
       else
           w.println("NO");

      w.close();

    }
    static void fill(char s1,char s2,int i,int j,int so2)
    {
        for(int r=0;r<25;r++)
        {
            for(int c=0;c<25;c++)
            {
                if(r%2 == 0 || so2 == 0)
                {
                    sol[r+i][c+j] = s1;

                }
                else if(c%2==0)
                    sol[r+i][c+j] = s1;
                else
                {
                    so2--;
                    sol[r+i][c+j] = s2;
                }
            }
        }
    }
     static long modexp(long x,long n,long M)
{
    long power = n;
    long result=1;
    while(power>0)
    {
        if(power % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        power = power/2;
    }
    return result;
}
     static long modInverse(long A,long M)
{
    return modexp(A,M-2,M);
}

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n,int x)
    {
        as = new ArrayList<>();
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {

            if(sum == x-1)
                break;
            as.add(2);
            //System.out.print(2 + " ");
            n /= 2;
            sum++;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                if(sum == x-1)
                break;
                as.add(i);
                n /= i;
                sum++;

            }

        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n >= 2)
        {
            sum++;
            as.add(n);
        }
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static boolean binarysearch(int []arr,int p,int n)
    {
        //ArrayList<Integer> as = new ArrayList<>();
        //as.addAll(0,at);
        //Collections.sort(as);
        boolean re = false;
        int st = 0;
        int end = n-1;

        while(st <= end)
        {
            int mid = st + (end-st)/2;

            if(p > arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid-1;

            }
            else if(p == arr[mid])
            {

            re = true;
            break;
            }

        }
         return re;

    }

    static class Student
    {

        int position;
        int value;
        Student(int position,int value)
        {
            this.position = position;
            this.value = value;

        }

    }
    /* Java program for Merge Sort */
static class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */

}

    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}

}

import java.util.Scanner;

public class quirky {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int[] arr = new int[a];
		arr[0]=sc.nextInt();
		boolean flag=true;
		for(int i=1;i<a;i++)
		{
			arr[i]=sc.nextInt();
			if(Math.abs(arr[i]-arr[i-1])>=2)
				flag=false;
		}
		if(flag)
			System.out.println("YES");
		else
			System.out.println("NO");

	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = in.nextInt();

            for (int i = 0; i < n - 1; ++i)
                if (a[i] - a[i + 1] > 1) {
                    out.println("NO");
                    return;
                }

            out.println("YES");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;
import java.util.regex.Pattern;

public class ROUGH {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	public static void main(String[] args) {
		 FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;++i) a[i] = sc.nextInt();
		boolean stable =true;
		for(int i=0;i+1<n && stable;++i) {
			if(Math.abs(a[i]-a[i+1])>1) stable = false;
		}

		if(!stable) out.println("NO");
		else out.println("YES");

		 out.close();

	}

}

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @autor Toropin Konstantin (impy.bian@gmail.com)
 */
public class CF952A {
    public static void main(String[] args) {
        try(Scanner scanner = new Scanner(System.in)) {
            int n = scanner.nextInt();
            List<Integer> arr = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int a = scanner.nextInt();
                arr.add(a);
            }
            while (!arr.isEmpty()) {
                int max = 0;
                for (int i = 1; i < arr.size(); i++) {
                    if (arr.get(i) > arr.get(i - 1) + 1 || arr.get(i - 1) > arr.get(i) + 1) {
                        System.out.println("NO");
                        return;
                    }
                    if (arr.get(i) > arr.get(max)) {
                        max = i;
                    }
                }
                arr.remove(max);
            }
            System.out.println("YES");
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int prev = in.nextInt();
            for (int i = 1; i < n; i++) {
                int cur = in.nextInt();
                if (prev - cur > 1) {
                    out.println("NO");
                    return;
                }
                prev = cur;
            }
            out.println("YES");
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.Function;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println(solve() ? "YES" : "NO");
    }

    static boolean solve() {
        for (int i = 1; i < N; i++) {
            if( Math.abs(A[i]-A[i-1]) > 1 ) {
                return false;
            }
        }
        return true;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        int[] nextIntArray(int n, int delta) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt() + delta;
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

    static <A> void writeLines(A[] as, Function<A, String> f) {
        PrintWriter pw = new PrintWriter(System.out);
        for (A a : as) {
            pw.println(f.apply(a));
        }
        pw.flush();
    }

    static void writeLines(int[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int a : as) pw.println(a);
        pw.flush();
    }

    static void writeLines(long[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (long a : as) pw.println(a);
        pw.flush();
    }

    static int max(int... as) {
        int max = Integer.MIN_VALUE;
        for (int a : as) max = Math.max(a, max);
        return max;
    }

    static int min(int... as) {
        int min = Integer.MAX_VALUE;
        for (int a : as) min = Math.min(a, min);
        return min;
    }

    static void debug(Object... args) {
        StringJoiner j = new StringJoiner(" ");
        for (Object arg : args) {
            if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));
            else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));
            else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));
            else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));
            else j.add(arg.toString());
        }
        System.err.println(j.toString());
    }
}

import java.util.*;

public class main {

    public static void main(String[] args) {

            boolean next = true;

            Scanner input=new Scanner(System.in);

            int size = (int) input.nextLong();
            input.nextLine();
            long[] units = new long[size];
            boolean crash = false;
            units[0] = input.nextLong();

            for (int i = 1; i < size; i++){
                units[i] = input.nextLong();
                if (units[i] - units[i-1] > 1 || units[i] - units[i-1] < -1){
                    crash = true;
                }

            }

            if (crash){
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }

            input.close();
    }

}

//package Codeforces;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

public class RavioliSort {
    public RavioliSort() {
        super();
    }

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

        int n = in.nextInt();
        List<Integer> ar = new ArrayList<Integer>();

        for(int i=0; i<n; i++) {
          int x = in.nextInt();
          ar.add(x);
        }

        boolean ans = true;

        for(int i=0; i<n; i++) {
            int max = 0;
            int limit = ar.size();
            for(int j=0; j<limit; j++) {
                if(j < limit-1 ) {
                    if( (int)Math.abs( ar.get(j).intValue() - ar.get(j+1).intValue() ) >= 2 ) {
                        ans = false;
                        break;
                    }
                }

                if(ar.get(j).intValue() > ar.get(max) ) {
                    max = j;
                }
            }

            if(ans == false) {
                break;
            }

            ar.remove(max);
        }

        System.out.println( (ans?"YES":"NO")  );
    }
}

import java.util.Scanner;

public class ravioliSort {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = scan.nextInt();
		scan.close();
		for (int i = 0; i < n - 1; i++) {
			if (Math.abs(arr[i] - arr[i + 1]) >= 2) {
				System.out.println("no");
				return;
			}
		}
		System.out.println("yes");
	}

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		//Scanner reader = new Scanner(System.in);
		 InputReader reader = new InputReader();
		// PrintWriter out = new PrintWriter(System.out);
		int n = reader.nextInt();
		int[] input = new int[n];
		for (int i = 0; i < input.length; i++) {
			input[i] = reader.nextInt();
		}
		for (int i = 0; i < input.length - 1; i++) {
			if (Math.abs(input[i] - input[i + 1]) >= 2) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

class InputReader {
	BufferedReader buf;
	StringTokenizer tok;

	InputReader() {
		buf = new BufferedReader(new InputStreamReader(System.in));
	}

	boolean hasNext() {
		while (tok == null || !tok.hasMoreElements()) {
			try {
				tok = new StringTokenizer(buf.readLine());
			} catch (Exception e) {
				return false;
			}
		}
		return true;
	}

	String next() {
		if (hasNext())
			return tok.nextToken();
		return null;
	}

	char nextChar() {
		return next().charAt(0);
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	static void deBug(int n, int m, char[][] array) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				System.out.print(array[i][j] + " ");
			}
			System.out.println();
		}
	}

	/*
	 * BigInteger nextBigInteger() { return new BigInteger(next()); }
	 *
	 * BigDecimal nextBigDecimal() { return new BigDecimal(next()); }
	 */
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Ravioli_Sort_1600 {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		br.close();
		int[] a = new int[n];
		for (int i = 0; i<n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}

		int max;
		if (n==1) {
			System.out.println("YES");
		}
		Loop:
		for (int i = n; i>1; i--) {
			max = 0;
			for (int j = 1; j<i; j++) {
				if (Math.abs(a[j]-a[j-1])>1) {
					System.out.println("NO");
					break Loop;
				}
				if (a[j]>max) {
					max = j;
				}
			}
			for (int j = max; j<i-1; j++) {
				a[j] = a[j+1];
			}
			if (i == 2) {
				System.out.println("YES");
			}
		}
	}
}

import java.io.*;
import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class April1C {

    private static BufferedReader in;
    private static BufferedWriter out;

    public static void main(String[] args) throws IOException {
        open();

        int n = readInt();
        int[] x = readInts();
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = x[i];
        }

        Arrays.sort(c);

        if (n == 1) {
            System.out.println("YES");
        } else {
            int last = n - 1;
            while (last >= 0) {
                boolean changed = false;
                while (!changed) {
                    changed = true;
                    for (int i = 0; i < last; i++) {
                        if (x[i] - 2 >= x[i + 1]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i + 1] = sum / 2;
                            x[i] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        } else if (x[i + 1] - 2 >= x[i]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i] = sum / 2;
                            x[i + 1] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        }
                    }
                }

                int max = x[last];
                for (int i = last - 1; i >= 0; i--) {
                    if (max <= x[i]) {
                        max = x[i];
                        int t = x[last];
                        x[last] = x[i];
                        x[i] = t;
                    }
                }

                last--;
            }

            boolean yes = true;
            for (int i = 0; i < n; i++) {
                if (x[i] != c[i]) {
                    yes = false;
                    break;
                }
            }

            if (yes) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }

        }
        close();
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(in.readLine());
    }

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

    private static long readLong() throws IOException {
        return Long.parseLong(in.readLine());
    }

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

    private static double readDouble() throws IOException {
        return Double.parseDouble(in.readLine());
    }

    private static String readString() throws IOException {
        return in.readLine();
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}

import java.util.*;

public class JavaApplication63 {

    public static void main(String[] args) {
        Scanner Sc=new Scanner(System.in);
        int n=Sc.nextInt();
        int maxn=-1;
        int a[]=new int[n];
        int d[]=new int[n-1];
        int k,temp=0;
        ArrayList<Integer> al=new ArrayList<>();

        for(int i=0;i<n;i++)
        {
            a[i]=Sc.nextInt();
            al.add(a[i]);
            if(maxn<a[i])
            {
                maxn=a[i];
                temp=i;
            }
        }

        for(int i=0;i<n-1;i++)
        {
            d[i]=Math.abs(a[i+1]-a[i]);
        }

        k=n-1;

        while(k!=0)
        {
            for(int i=0;i<k;i++)
            {
                if(d[i]>=2)
                {
                  System.out.println("No");
                  System.exit(0);
                }
            }
            al.remove(temp);
            k--;
            maxn=-1;
            for(int i=0;i<al.size();i++)
            {
                if(maxn<al.get(i))
                {
                    maxn=al.get(i);
                    temp=i;

                }
            }
            for(int i=0;i<k-1;i++)
            {
                d[i]=Math.abs(a[i+1]-a[i]);
            }

        }

        System.out.println("Yes");

    }

}

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = s.nextInt();
        }
        boolean flag = false;
        for(int i=1;i<n;i++){
            if(a[i-1]-a[i]>=2 || a[i]-a[i-1]>=2){
                System.out.println("NO");
                flag = true;
                break;
            }

        }
         if(!flag){
                System.out.println("YES");
            }
    }
}

import java.util.*;
import java.io.*;
public class Cprob {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int num = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		int prev = Integer.parseInt(st.nextToken());
		boolean ok = true;
		while(st.hasMoreTokens()) {
			int x = Integer.parseInt(st.nextToken());
			if(Math.abs(x - prev) >= 2) {
				ok = false;
				break;
			}
			prev = x;
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		br.close();
	}
}

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> ar = new ArrayList<Integer>();
        for (int i = 0; i < n; i++)
            ar.add(scanner.nextInt());
        for (int i = 1; i < n; i++)
            if (Math.abs(ar.get(i) - ar.get(i - 1)) >= 2)
            {
                System.out.println("NO");
                return;
            }

        for (int i = 0; i < n - 1; i++)
        {
            int P = min(ar);
            if (P > 0 && P < ar.size() - 1)
                if (Math.abs(ar.get(P + 1) - ar.get(P - 1)) >= 2)
                {
                    System.out.println("NO");
                    return;
                }
            ar.remove(P);
        }
        System.out.println("YES");
    }

    public static int min(ArrayList<Integer> ar)
    {
        int minV = ar.get(0), minP = 0;
        for (int i = 1; i < ar.size(); i++)
            if (ar.get(i) < minV)
            {
                minV = ar.get(i);
                minP = i;
            }

        return minP;
    }
}

import java.util.*;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int [] arr = new int[n];

		for (int i =0;i<n;i++)
			arr[i] = sc.nextInt();
		boolean sp=true;
		for (int i =1;i<n;i++)
			if (Math.abs(arr[i]-arr[i-1])>=2)
			{
				sp = false;
				break;
			}
		if (sp)
		System.out.println("YES");
		else
			System.out.println("NO");
		sc.close();

	}

}

/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{

	 Scanner sc=new Scanner(System.in);
	 int n=sc.nextInt();

	 int[] a=new int[n];
	 for(int i=0;i<n;i++)a[i]=sc.nextInt();

	 int[] b=new int[n];

	 System.arraycopy(a,0,b,0,n);

	 for(int i=0;i+1<n;i++){
	  if(Math.abs(a[i+1]-a[i])>=2){
	   int temp=(a[i+1]+a[i])/2;
	   a[i+1]=temp;
	   a[i]=temp;
	  }
	 }
	 Arrays.sort(a);
	 Arrays.sort(b);

	 if(Arrays.equals(a,b))System.out.println("YES");
	 else System.out.println("NO");
	}
}

import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
public class Ravioli{
    public static void main(String[] args) {
      MyScanner sc=new MyScanner();
      int n=sc.ni();
      int a[]=new int[n];
      for(int i=0;i<n;i++) a[i]=sc.ni();
      for(int i=0;i<n-1;i++){
        if(Math.abs(a[i]-a[i+1])>=2){
          System.out.println("NO");
          System.exit(0);
        }
      }
      System.out.println("YES");
  }

    private static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int ni() {
          return Integer.parseInt(next());
      }
      float nf() {
        return Float.parseFloat(next());
      }
      long nl() {
          return Long.parseLong(next());
      }

      double nd() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
    try {
       str = br.readLine();
    } catch (IOException e) {
       e.printStackTrace();
    }
    return str;
      }
   }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
import java.util.InputMismatchException;
public class solution{
	public static void main(String args[]) throws Exception
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++)
		{
			a[i] = sc.nextInt();
		}
		boolean flag = true;
		for(int i=1;i<n;i++)
		{
			if(check(a,n-i+1))
			{
				flag = false;
				break;
			}
			int index = max(a,n-i+1);
			int save = a[index];
			for(int j=index;j<n-i;j++)
			{
				a[j] = a[j+1];
			}
			a[n-i] = save;
		}
		if(flag)
		{
			out.println("YES");
		}
		else
		{
			out.println("NO");
		}
		out.close();
	}
	public static int max(int[] a,int n)
	{
		int max = 0;
		int index = 0;
		for(int i=0;i<n;i++)
		{
			if(a[i]>max)
			{
				max = a[i];
				index = i;
			}
		}
		return index;
	}
	public static boolean check(int[] a,int n)
	{
		for(int i=0;i<n-1;i++)
		{
			if(mod(a[i]-a[i+1])>=2)
			{
				return true;
			}
		}
		return false;
	}
	public static int mod(int x)
	{
		if(x>0)
		{
			return x;
		}
		return -x;
	}
	static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int[] readCharCount() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int[] map = new int[256];
            do {
                int val = c ;
                map[val]++;
                c = snext();
            } while (!isSpaceChar(c));
            return map;
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.*;
import java.util.*;
public class Solution
{
    static long seq[]=new long[200001];
    static long p[]=new long[200001];
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)throws IOException
    {
        //BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
        FastReader ob=new FastReader();
        int n=ob.nextInt();
        int a[]=new int[n];
        int l=0;
        for(int i=0;i<n;i++)
        {
            a[i]=ob.nextInt();
            if(i!=0)
                if(a[i]-a[i-1]>=2 || a[i]-a[i-1]<=-2)
                    l=1;
        }
        if(l==1)
            System.out.println("NO");
        else
            System.out.println("YES");

    }
}

import java.util.*;
public class cfRaviolisort {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<Integer> ar= new ArrayList<>();

        for(int i=0;i<n;i++){
            ar.add(i,sc.nextInt());

        }

        boolean flag=false;

            for(int j=0;j<(ar.size()-1);j++){
                if(Math.abs(ar.get(j)-ar.get(j+1))>1){
                    flag=true;
                }

//                System.out.print(" MAXX = "+max + " djd "+ar.get(max)+"\n");
            }

        if(flag) System.out.println("NO");
        else System.out.println("YES");

    }
}

import java.util.*;
public class C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int rav = sc.nextInt();
        ArrayList<Integer> raviolis = new ArrayList<>();
        ArrayList<Integer> clone = new ArrayList<>();
        while(rav-- > 0){
            int n = sc.nextInt();
            raviolis.add(n);
            clone.add(n);
        }
        ArrayList<Integer> sorted = new ArrayList<>();
        while(raviolis.size() > 0){
            for(int i=0;i<raviolis.size()-1;i++){
                int diff = Math.abs(raviolis.get(i)-raviolis.get(i+1));
                if(diff >= 2){
                    if(raviolis.get(i) > raviolis.get(i+1)){
                        raviolis.set(i,raviolis.get(i)-diff/2);
                        raviolis.set(i+1,raviolis.get(i+1)+(diff+1)/2);
                    }
                    else if(raviolis.get(i) < raviolis.get(i+1)){
                        raviolis.set(i+1,raviolis.get(i+1)-diff/2);
                        raviolis.set(i,raviolis.get(i)+(diff+1)/2);
                    }
                }
            }
            int maxindex = -1;
            int maxsize = 0;
            for(int i=0;i<raviolis.size();i++){
                if(raviolis.get(i) > maxsize){
                    maxsize = raviolis.get(i);
                    maxindex = i;
                }
            }
            int k = raviolis.remove(maxindex);
            sorted.add(k);
        }
        Collections.reverse(sorted);
        Collections.sort(clone);
        System.out.println(sorted.equals(clone) ? "YES" : "NO");
    }
}

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

public class Alpha {
    String filename = "subseq";//filename here, System.in/out if no file

    FastScanner in;
    PrintWriter out;

    void pass() {
    }

    int[] rem(int[] a, int x) {
        int[] ans = new int[a.length - 1];
        for (int i = 0; i < x; i++) ans[i] = a[i];
        for (int i = x; i < a.length - 1; i++) ans[i] = a[i + 1];
        return ans;
    }

    void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int[] b = a.clone();
        Arrays.sort(b);
        int[] ans = new int[n];
        for (int i = n-1; i >=0; i--) {
            int max = 0;
            for (int j = 0; j < a.length; j++) {
                while (j != 0 && a[j - 1] - a[j] >= 2) {
                    a[j - 1]--;
                    a[j]++;
                }
                while (j != 0 && a[j] - a[j - 1] >= 2) {
                    a[j - 1]++;
                    a[j]--;
                }
            }
            for (int j = 0; j < a.length; j++) {
                if (a[max] < a[j]) max = j;
            }
            ans[i] = a[max];
            a = rem(a, max);
        }

        if (Arrays.equals(ans,b)) System.out.println("YES");
        else System.out.println("NO");
    }

    void run() throws IOException {
        InputStream input = System.in;
        OutputStream output = System.out;
        try {
            File f = new File(filename + ".in");
            if (f.exists() && f.canRead()) {
                input = new FileInputStream(f);
                output = new FileOutputStream(filename + ".out");
            }
        } catch (IOException e) {
        }
        in = new FastScanner(input);
        out = new PrintWriter(new BufferedOutputStream(output));
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Alpha().run();
    }

    class FastScanner implements Closeable {
        private BufferedReader br;
        private StringTokenizer tokenizer;

        public FastScanner(InputStream stream) throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = br.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.hasMoreTokens();
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        @Override
        public void close() throws IOException {
            br.close();
        }

        public byte nextByte() {
            return Byte.parseByte(next());
        }
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }//s

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }//ss

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CRavioliSort solver = new CRavioliSort();
        solver.solve(1, in, out);
        out.close();
    }

    static class CRavioliSort {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            int[] a = in.nextIntArray(n);

            int[] c = a.clone();

            Arrays.sort(c);

            for (int i = 0; i < n - 1; i++) {
                if (Math.abs(a[i + 1] - a[i]) >= 2) {
                    out.println("NO");
                    return;
                }
            }

            for (int i = 0; i < n - 1; i++) {
                if (c[i + 1] - c[i] >= 2) {
                    out.println("NO");
                    return;
                }
            }
            for (int i = 0; i < n; i++) {
                int maxi = -1;
                int max = 0;
                for (int j = 0; j < n - i; j++) {
                    if (a[j] > max) {
                        max = a[j];
                        maxi = j;
                    }
                }
                if (n - i - 1 > 0) {
                    int[] b = new int[n - i - 1];

                    int k = 0;
                    for (int j = 0; j < n - i; j++) {
                        if (j != maxi) {
                            b[k++] = a[j];
                        }
                    }

                    a = b;

                    for (int j = 0; j < n - i - 2; j++) {
                        if (b[j + 1] - b[j] >= 2) {
                            out.println("NO");
                            return;
                        }
                    }
                }

            }

            out.println("YES");
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.StringTokenizer;

/**
 * @author ayratgdl
 * @date 01.04.18
 */
public class CF20180401C {
    int n;
    int[] a;
    public static void main(String[] args) {
        new CF20180401C().solve(System.in, System.out);
    }

    public void solve(InputStream input, OutputStream output) {
        In in = new In(input);
        Out out = new Out(output);

        n = in.int1();
        a = in.ints(n);
        int size = n;
        while (size > 1) {
            int max = 0;
            int maxI = -1;
            for (int i = 0; i < n; i++) {
                if (a[i] == 0) {
                    continue;
                }
                if (!checkCorrect(i)) {
                    out.write("NO").ln();
                    return;
                }
                if (maxI == -1 || a[i] > max) {
                    maxI = i;
                    max = a[i];
                }
            }
            a[maxI] = 0;
            size--;
        }
        out.write("YES").ln();
    }

    private boolean checkCorrect(int i) {
        for (int j = i+1; j < a.length; j++) {
            if (a[j] != 0) {
                int r = a[i] - a[j];
                return r <= 1 && r >= -1;
            }
        }
        return true;
    }

    public class In {
        private BufferedReader reader;
        StringTokenizer tokener;

        public In(BufferedReader reader) {
            this.reader = reader;
        }

        public In(Reader reader) {
            this.reader = new BufferedReader(reader);
        }

        public In(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public int int1() {
            return Integer.parseInt(word());
        }

        public String word() {
            try {
                if (tokener == null || !tokener.hasMoreTokens())
                    tokener = new StringTokenizer(reader.readLine());
                return tokener.nextToken();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public long long1() {
            return Long.parseLong(word());
        }

        public String[] words(int n) {
            String[] result = new String[n];
            for (int i = 0; i < n; i++)
                result[i] = word();
            return result;
        }

        public int[] ints(int n) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++)
                result[i] = Integer.parseInt(word());
            return result;
        }

        public long[] longs(int n) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++)
                result[i] = Long.parseLong(word());
            return result;
        }
    }

    public class Out {
        private BufferedWriter writer;
        private boolean isEmptyLine = true;

        public Out(BufferedWriter writer) {
            this.writer = writer;
        }

        public Out(Writer writer) {
            this.writer = new BufferedWriter(writer);
        }

        public Out(OutputStream out) {
            this.writer = new BufferedWriter(new OutputStreamWriter(out));
        }

        private Out write(String str) {
            try {
                if (!isEmptyLine)
                    writer.write(" ");
                else
                    isEmptyLine = false;
                writer.write(str);
                return this;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public Out ln() {
            try {
                writer.newLine();
                writer.flush();
                isEmptyLine = true;
                return this;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public Out write(Object obj) {
            return write(obj.toString());
        }

        public Out write(int num) {
            return write(Integer.toString(num));
        }

        public Out write(long num) {
            return write(Long.toString(num));
        }

        public Out write(Object[] objs) {
            for (Object obj : objs)
                write(obj);
            return this;
        }

        public <T> Out write(Iterable<T> iter) {
            for (T obj : iter)
                write(obj);
            return this;
        }

        public Out write(int[] nums) {
            for (int num : nums)
                write(num);
            return this;
        }

        public Out write(long[] nums) {
            for (long num : nums)
                write(num);
            return this;
        }
    }
}

import java.util.*;

public class Main {

		public static void main(String args[] )  {

	        Scanner in = new Scanner (System.in);
	        		int n=in.nextInt();
	        		int[] a = new int[n+1];
	        		int flag=0;
	        		for(int i=0;i<n;i++) {
	        			a[i]=in.nextInt();
	        		}
	        		for(int i=0;i<n-1;i++) {
	        			if(a[i]-a[i+1]>=2) {
	        				flag=1;
	        				break;
	        			}
	        		}
	        		if(flag==0) {
	        			System.out.println("YES");
	        		}
	        		else {
	        			System.out.println("NO");
	        		}
	        in.close();
		}

}

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

public class TaskA {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solve solve = new Solve();
        solve.solve(in, out);
        out.close();
    }

    private static class Solve {

        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            for (int i = 1; i < n; i++) {
                if (StrictMath.abs(a[i] - a[i - 1]) > 1) {
                    out.print("NO");
                    return;
                }
            }
            out.println("YES");
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

import java.util.*;
import java.io.*;
public class CF{
	static double arr[];
	static int U;
	public static void main(String[] args) {
		boolean f = false;
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int arr[] = new int[n];
		for(int i = 0;i < n;i++)
			arr[i] = scan.nextInt();
		for(int i = 1;i<n;i++)
			if (Math.abs(arr[i]-arr[i-1]) >= 2)
				f = true;
		if (f)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Raviolli {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int symbols = Integer.parseInt(reader.readLine());
        int[] numbers = Arrays.stream(reader.readLine().split(" "))
                .mapToInt(Integer::parseInt)
                .toArray();
        for (int i = 1; i < symbols; i++) {
            if (Math.abs(numbers[i] - numbers[i - 1]) >= 2) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i=0;i<arr.length;i++){
                arr[i] = in.nextInt();
            }
            for (int i= 0;i<arr.length-1;i++) {
                if (Math.abs(arr[i+1]-arr[i])>1){
                    System.out.println("NO");
                    return;
                }
            }
            System.out.println("YES");
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestClass {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		String s = br.readLine();
		String[] str = s.split(" ");
		for(int i = 0 ; i < n; i++){
			arr[i] = Integer.parseInt(str[i]);
		}
		solve(arr);
	}

	private static void solve(int[] arr) {
		int temp = arr[0];

		for(int i = 1; i < arr.length; i++){
			if(arr[i] - temp >= 2 || arr[i] - temp <= -2){
				System.out.println("NO");
				return;
			}
			temp = arr[i];
		}

		System.out.println("YES");

	}

}

import java.util.HashSet;
import java.util.Scanner;

public class vk {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=0;
        boolean ans=true;
        for(int i=0;i<n-1;i++){
            b=sc.nextInt();
            if(Math.abs(b-a)>=2){
                System.out.println("NO");
                ans=false;
                break;
            }
            a=b;
        }
        if (ans){
            System.out.println("YES");
        }
    }
}

import java.util.*;
public class probA{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int[] arr=new int[n];
		for (int i=0; i<n;i++) {
			arr[i]=scan.nextInt();
		}
		int flag=0;
		for (int i=0; i<n-1; i++) {
			if(Math.abs(arr[i]-arr[i+1])>=2){
				flag=1;
				break;
			}
		}
		System.out.println(flag==0 ?"YES":"NO");
	}
}

import java.io.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";

	public void solve() throws Exception {

		int n= iread();
		int []a= new int[n+1];
		for(int i=0;i<n;i++)
			a[i]= iread();
		while(n>1) {
			for(int i=0;i<n-1;i++) {
				if(Math.abs(a[i]-a[i+1])>1) {
					out.write("NO");
					return;
				}
			}
			int max=-1;
			int ind=-1;
			for(int i=0;i<n;i++) {
				if(a[i]>max) {
					max=a[i];
					ind=i;
				}
			}
			int x=0;
			for(int i=0;i<n;i++) {
				if(i==ind)
					continue;
				a[x++]=a[i];
			}
			n--;
		}
		out.write("YES");
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}

import java.util.*;

public class fgfd {
	public static void main(String[] args) {
		Scanner scanny = new Scanner(System.in);
		int x = scanny.nextInt();
		int[] arr = new int[x];
		int[] arr2 = new int[x];
		for (int i = 0; i < x; i++) {
			arr[i] = scanny.nextInt();
			arr2[i] = arr[i];
		}
		Arrays.sort(arr2);
		int[] arr3 = new int[x];
		for (int i = 0; i < x; i++) {
			for (int j = 0; j < x-1; j++) {
				if (arr[j]+1<arr[j+1] && arr[j] != 0 && arr[j]+1 != 0 && arr[j+1] != 0) {
					arr[j]++;
					arr[j+1]--;
				}
				else if (arr[j]-1>arr[j+1] && arr[j] != 0 && arr[j]+1 != 0 && arr[j+1] != 0) {
					arr[j]--;
					arr[j+1]++;
				}
			}
			int max = 0;
			int indMax = 0;
			for (int j = 0; j < x; j++) {
				if (arr[j]>=max) {
					max = arr[j];
					indMax = j;
				}
			}
			arr3[x-i-1]=max;
			arr[indMax] = 0;
		}
		boolean yes = true;
		for (int i = 0; i < x; i++) {
			if (arr2[i] != arr3[i]) yes = false;
		}
		if (yes) System.out.println("YES");
		else System.out.println("NO");
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Ravioli {

	public static void main(String args[]) throws NumberFormatException, IOException {

		Scanner input = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		for(int index=0; index < 1; index++) {
			int size = Integer.parseInt(br.readLine());
			String s1[] = br.readLine().split(" ");
			int array[] = new int[size];
			boolean flag=true;
			array[0] = Integer.parseInt(s1[0]);
			for(int index1=1; index1 < size; index1++) {
				array[index1] = Integer.parseInt(s1[index1]);
				if(Math.abs(array[index1] - array[index1-1]) >= 2) {
					System.out.println("NO");
					flag=false;
				}
			}
			if(flag)
				System.out.println("YES");
		}

	}

}

import java.io.*;
import java.util.*;
import java.math.*;

public class main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;

    public static void main(String[] args) throws Exception {
        int N = Integer.parseInt(br.readLine());
        st = new StringTokenizer(br.readLine());
        ArrayList<Integer> A = new ArrayList<Integer>();

        for(int i = 0; i < N; i++){
            A.add(Integer.parseInt(st.nextToken()));
        }

        boolean f = true;
        for(int i = 1; i < N; i++){
            if (A.get(i) != A.get(i-1) + 1){
                f = false;
                break;
            }
        }

        pw.println(f ? "YES" : "NO");

        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int x, y;

    Pair(int _x, int _y){
        x = _x;
        y = _y;
    }

    public String toString(){
        return x + "," + y;
    }

    public int compareTo(Pair p){
        if(x != p.x) return x < p.x ? 1 : -1;
        else if(y != p.y) return y < p.y ? -1 : 1;
        return 0;
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;

    public static void main(String[] args) throws Exception {
        int N = Integer.parseInt(br.readLine());
        st = new StringTokenizer(br.readLine());
        ArrayList<Integer> A = new ArrayList<Integer>();

        for(int i = 0; i < N; i++){
            A.add(Integer.parseInt(st.nextToken()));
        }

        boolean f = true;
        boolean sorted = false;
        while (!sorted && f) {
            sorted = true;
            for(int i = 0; i < N; i++) {
                if (i != 0 && A.get(i) < A.get(i-1)) {
                    sorted = false;
                }

                if (i != 0 && Math.abs(A.get(i) - A.get(i-1)) >= 2) {
                    f = false;
                    break;
                }
            }
            Integer k = Collections.max(A);
            A.remove(k);
            A.add(k);
        }

        pw.println(f ? "YES" : "NO");

        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int x, y;

    Pair(int _x, int _y){
        x = _x;
        y = _y;
    }

    public String toString(){
        return x + "," + y;
    }

    public int compareTo(Pair p){
        if(x != p.x) return x < p.x ? 1 : -1;
        else if(y != p.y) return y < p.y ? -1 : 1;
        return 0;
    }
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[100];
        int n = sc.nextInt();
        for (int i = 0; i<n; i++){
             num[i] = sc.nextInt();
        }
        for (int i = 0; i<n-1; i++){
            if (num[i]>num[i+1]){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
    }

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arr = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arr.add(scanner.nextInt());
        }
        int k = n - 1;
        do{
            for (int i = 1; i < n; i++) {
                if (Math.abs(arr.get(i) - arr.get(i - 1)) >= 2){
                    System.out.println("NO");
                    return;
                }
            }
            int max = 0;
            int imax = 0;
            for (int i = 0; i <= k; i++) {
                if (arr.get(i) > max){
                    max = arr.get(i);
                    imax = i;
                }
            }

            int temp = arr.get(imax);
            arr.remove(imax);
            arr.add(k, temp);
            k--;

        } while (k >= 0);

        System.out.println("YES");

    }
}

import sun.misc.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        int k = n - 1;
        do{
            for (int i = 1; i < n; i++) {
                if (Math.abs(arr[i] - arr[i - 1]) >= 2){
                    System.out.println("NO");
                    return;
                }
            }
            int max = 0;
            int imax = 0;
            for (int i = 0; i <= k; i++) {
                if (arr[i] > max){
                    max = arr[i];
                    imax = i;
                }
            }
            int temp = arr[k];
            arr[k] = arr[imax];
            arr[imax] = temp;
            k--;

        } while (k > 0);
        System.out.println("YES");

    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        int k = n - 1;
        do{
            for (int i = 1; i < n; i++) {
                if (Math.abs(arr[i] - arr[i - 1]) >= 2){
                    System.out.println("NO");
                    return;
                }
            }
            int max = 0;
            int imax = 0;
            for (int i = 0; i <= k; i++) {
                if (arr[i] > max){
                    max = arr[i];
                    imax = i;
                }
            }
            int temp = arr[k];
            arr[k] = arr[imax];
            arr[imax] = temp;
            k--;

        } while (k >= 0);

        System.out.println("YES");

    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arr = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arr.add(scanner.nextInt());
        }
        int k = n - 1;
        do{
            for (int i = 1; i < n; i++) {
                if (Math.abs(arr.get(i) - arr.get(i - 1)) >= 2){
                    System.out.println("NO");
                    return;
                }
            }
            int max = 0;
            int imax = 0;
            for (int i = 0; i <= k; i++) {
                if (arr.get(i) > max){
                    max = arr.get(i);
                    imax = i;
                }
            }

            int temp = arr.get(imax);
            arr.remove(imax);
            arr.add(temp);
            k--;

        } while (k >= 0);

        System.out.println("YES");

    }
}

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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.Solve(in, out);
        out.close();
    }

    static class TaskC {

        void Solve(InputReader in, PrintWriter out) {
            int n = in.NextInt();
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(in.NextInt());
            for (int j = 0; j < n; j++) {
                for (int i = 0; i < n - 1; i++) {
                    if (Math.abs(a.get(i) - a.get(i + 1)) == 2) {
                        out.println("NO");
                        return;
                    }
                }
                int max = 0;
                int ind = 0;
                for (int i = 0; i < n; i++)
                    if (a.get(i) > max) {
                        ind = i;
                        max = a.get(i);
                    }
                a.remove(ind);
                n--;
            }
            out.println("YES");
        }
    }

    static int GetMax(int[] ar) {
        int max = Integer.MIN_VALUE;
        for (int a : ar) {
            max = Math.max(max, a);
        }
        return max;
    }

    static int GetMin(int[] ar) {
        int min = Integer.MAX_VALUE;
        for (int a : ar) {
            min = Math.min(min, a);
        }
        return min;
    }

    static long GetSum(int[] ar) {
        long s = 0;
        for (int a : ar) s += a;
        return s;
    }

    static int[] GetCount(int[] ar) {
        return GetCount(ar, GetMax(ar));
    }

    static int[] GetCount(int[] ar, int maxValue) {
        int[] dp = new int[maxValue + 1];
        for (int a : ar) {
            dp[a]++;
        }
        return dp;
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String Next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int NextInt() {
            return Integer.parseInt(Next());
        }

        long NextLong() {
            return Long.parseLong(Next());
        }

        double NextDouble() {
            return Double.parseDouble(Next());
        }

        int[] NextIntArray(int n) {
            return NextIntArray(n, 0);
        }

        int[] NextIntArray(int n, int offset) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = NextInt() - offset;
            }
            return a;
        }

        int[][] NextIntMatrix(int n, int m) {
            return NextIntMatrix(n, m, 0);
        }

        int[][] NextIntMatrix(int n, int m, int offset) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = NextInt() - offset;
                }
            }
            return a;
        }

        public long[] NextLongArray(int n) {
            return NextLongArray(n, 0);
        }

        long[] NextLongArray(int n, int offset) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = NextLong() - offset;
            }
            return a;
        }

        long[][] NextLongMatrix(int n, int m) {
            return NextLongMatrix(n, m, 0);
        }

        long[][] NextLongMatrix(int n, int m, int offset) {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = NextLong() - offset;
                }
            }
            return a;
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class CForces3 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int staticArr[] = new int[101];

        for (int i=0;i<101;i++) {
            staticArr[i]=0;
        }
        int n = in.nextInt();
        int input[] = new int[n];
        int copy[] = new int[n];
        for (int i=0;i<n;i++) {
            input[i] = in.nextInt();
            staticArr[input[i]]=1;
            //copy[i] = input[i];
        }
        boolean flag=true;
        //Sort the array and find the difference between the elements.

        for (int i=0;i<n-1;i++) {
            //Difference between adjacent elements in less than 2
            if (Math.abs(input[i] - input[i+1])<2) {

            } else {
                //Check if +-2 there are any elements present in the array
                //check for i first and then i+1
                if (input[i]>input[i+1]) {

                    if ((checkFor(input[i] - 1, 101) && staticArr[input[i] - 1] == 1) ||
                            (checkFor(input[i + 1] + 1, 101) && staticArr[input[i + 1] + 1] == 1)) {
                        flag = false;
                        break;
                    }
                } else {
                    if ((checkFor(input[i+1] - 1, 101) && staticArr[input[i+1] - 1] == 1) ||
                            (checkFor(input[i] + 1, 101) && staticArr[input[i] + 1] == 1)) {
                        flag = false;
                        break;
                    }

                }

            }
        }

        if (flag) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

        /*
        Arrays.sort(copy);

        for (int i=0;i<n;i++) {

        }

        */
    }

     static boolean checkFor(int a,int n) {
        if (a>=0 && a<n) {
            return true;
        }

        return false;
     }
}

import java.util.Scanner;

public class C1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (Math.abs(a[i] - a[i + 1]) > 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class RavioliSort {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int n = r.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = r.nextInt();
		}
		int k = arr.length;
		while (!isSorted(arr)) {
			for (int i = 0; i < arr.length - 1; i++) {
				if (Math.abs(arr[i] - arr[i + 1]) >= 2) {
					System.out.println("NO");
					System.exit(0);
				}
			}
			int max = -1;
			int index = -1;
			for(int i=0;i<k;i++){
				if(arr[i]>max){
					max = arr[i];
					index = i;
				}
			}
			for (int i = index; i < k-1; i++) {
				arr[i] = arr[i+1];
			}
			arr[k-1] = max;
			k--;
		}
		System.out.println("YES");
	}

	private static boolean isSorted(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i] > arr[i + 1])
				return false;
		}
		return true;
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class RavioliSort {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int n = r.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = r.nextInt();
		}
		if(isSorted(arr))
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	private static boolean isSorted(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			if (arr[i] > arr[i + 1])
				return false;
		}
		return true;
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

import java.util.Scanner;

public class quirky {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		if(a==1)
			System.out.println("YES");
		int[] arr = new int[a];
		arr[0]=sc.nextInt();
		boolean flag=true;
		for(int i=1;i<a;i++)
		{
			arr[i]=sc.nextInt();
			if(arr[i]-arr[i-1]>=2)
				flag=false;
		}
		if(flag)
			System.out.println("YES");
		else
			System.out.println("NO");

	}

}

import java.util.Scanner;

public class quirky {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		if(a==1)
			System.out.println("YES");
		int[] arr = new int[a];
		arr[0]=sc.nextInt();
		boolean flag=true;
		for(int i=1;i<a;i++)
		{
			arr[i]=sc.nextInt();
			if(Math.abs(arr[i]-arr[i-1])>=2)
				flag=false;
		}
		if(flag)
			System.out.println("YES");
		else
			System.out.println("NO");

	}

}

import java.util.Random;

public class d {
	public static void main(String[] args) {
		Random r = new Random();
		System.out.println(r.nextInt(36) + 1);
	}//adding comment
}

import java.util.*;
public class cfRaviolisort {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<Integer> ar= new ArrayList<>();

        for(int i=0;i<n;i++){
            ar.add(i,sc.nextInt());

        }
        boolean flag=false;
        for(int i=0;i<n;i++){
            int max=0;
            for(int j=1;j<(ar.size());j++){
//                System.out.print(ar);
                if((ar.get(j-1)==ar.get(j)-2) ||(ar.get(j-1)==ar.get(j)+2)){
                    flag=true;
                }

                if(ar.get(j-1)>ar.get(max)){
                    max=j-1;
                }
                if(ar.get(j)>ar.get(max)){
                    max=j;
                }
//                System.out.print(" MAXX = "+max + " djd "+ar.get(max)+"\n");
            }
            ar.remove(max);
        }
        if(flag) System.out.println("NO");
        else System.out.println("YES");

    }
}

import java.util.*;
public class cfRaviolisort {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<Integer> ar= new ArrayList<>();

        for(int i=0;i<n;i++){
            ar.add(i,sc.nextInt());

        }
        boolean flag=false;
        for(int i=0;i<n;i++){
            int max=0;
            for(int j=1;j<(ar.size());j++){
//                System.out.print(ar);
                if((ar.get(j-1)==ar.get(j)-2) ||(ar.get(j-1)==ar.get(j)+2)){
                    flag=true;
                }
//                System.out.print(" MAXX = "+max + " djd "+ar.get(max)+"\n");
                if(ar.get(j-1)>ar.get(max)){
                    max=j-1;
                }
            }
            ar.remove(max);
        }
        if(flag) System.out.println("NO");
        else System.out.println("YES");

    }
}

import java.util.*;
public class cfRaviolisort {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<Integer> ar= new ArrayList<>();

        for(int i=0;i<n;i++){
            ar.add(i,sc.nextInt());

        }
        boolean flag=false;
        for(int i=0;i<ar.size();i++){
            int max=0;
            for(int j=1;j<(ar.size()-1);j++){

                if((ar.get(j-1)==ar.get(j)-2) ||(ar.get(j-1)==ar.get(j)+2)){
                    flag=true;
                }
                if(ar.get(j)>max){
                    max=j;
                }
            }
            ar.remove(max);
        }
        if(flag) System.out.println("NO");
        else System.out.println("YES");

    }
}

        import java.io.*;
        import java.util.StringTokenizer;
        import java.util.*;
        import java.math.*;
        import java.lang.Integer;

        public class Solution {

        	public static String sort(Integer[] arr) {
        		Integer n= arr.length;
        		Integer[] narr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    narr[i]=arr[i];
        		}
        		Integer[] oarr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    oarr[i]=arr[i];
        		}

        		Integer res;
        		Integer resindex;
        		Boolean check;

        		for (int i = 0; i < n; i++) {

        		    check=true;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n-i; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        	    //System.out.println("here");
        			    res=0;
        			    resindex=0;
        			    for (int j = 0; j < n-i; j++) {
        			        if(narr[j]>res){
        			            res=narr[j];
        			            resindex=j;
        			        }
        			        //System.out.println(resindex);
        			    }

        			    narr[resindex]=narr[n-i-1];

        			    narr[n-i-1]=res;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n-i-1; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        		 //System.out.println("here");

        		}

        		Arrays.sort(oarr);
        		//for (int j = 0; j < n; j++) {
        	    //System.out.println(oarr[j]);
        	    //}

        		if(Arrays.equals(narr, oarr)){
        		    return "YES";
        		}else{
        		    return "NO";
        		}

        	}

        	public static void main(String[] args) throws Exception {
        		FastScanner cin = new FastScanner(System.in);
        		Integer n =cin.nextInt();

        		Integer[] arr= new Integer[n];

        		for (int i = 0; i < n; i++) {
        			arr[i]=cin.nextInt();

        		}

        		System.out.println(sort(arr));

        	}

        	static class FastScanner {
        		private BufferedReader reader = null;
        		private StringTokenizer tokenizer = null;

        		public FastScanner(InputStream in) {
        			reader = new BufferedReader(new InputStreamReader(in));
        			tokenizer = null;
        		}

        		public String next() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					tokenizer = new StringTokenizer(reader.readLine());
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}
        			return tokenizer.nextToken();
        		}

        		public String nextLine() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					return reader.readLine();
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}

        			return tokenizer.nextToken("\n");
        		}

        		public long nextLong() {
        			return Long.parseLong(next());
        		}

        		public int nextInt() {
        			return Integer.parseInt(next());
        		}

        	}
        }

        import java.io.*;
        import java.util.StringTokenizer;
        import java.util.*;
        import java.math.*;
        import java.lang.Integer;

        public class Solution {

        	public static String sort(Integer[] arr) {
        		Integer n= arr.length;
        		Integer[] narr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    narr[i]=arr[i];
        		}
        		Integer[] oarr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    oarr[i]=arr[i];
        		}

        		Integer res;
        		Integer resindex;
        		Boolean check;

        		for (int i = 0; i < n; i++) {

        		    check=true;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n-i; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        	    //System.out.println("here");
        			    res=0;
        			    resindex=0;
        			    for (int j = 0; j < n; j++) {
        			        if(narr[j]>res){
        			            res=narr[j];
        			            resindex=j;
        			        }
        			        //System.out.println(resindex);
        			    }

        			    narr[resindex]=narr[n-i-1];

        			    narr[n-i-1]=res;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        		 //System.out.println("here");

        		}

        		Arrays.sort(oarr);
        		//for (int j = 0; j < n; j++) {
        	    //System.out.println(oarr[j]);
        	    //}

        		if(Arrays.equals(narr, oarr)){
        		    return "YES";
        		}else{
        		    return "NO";
        		}

        	}

        	public static void main(String[] args) throws Exception {
        		FastScanner cin = new FastScanner(System.in);
        		Integer n =cin.nextInt();

        		Integer[] arr= new Integer[n];

        		for (int i = 0; i < n; i++) {
        			arr[i]=cin.nextInt();

        		}

        		System.out.println(sort(arr));

        	}

        	static class FastScanner {
        		private BufferedReader reader = null;
        		private StringTokenizer tokenizer = null;

        		public FastScanner(InputStream in) {
        			reader = new BufferedReader(new InputStreamReader(in));
        			tokenizer = null;
        		}

        		public String next() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					tokenizer = new StringTokenizer(reader.readLine());
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}
        			return tokenizer.nextToken();
        		}

        		public String nextLine() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					return reader.readLine();
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}

        			return tokenizer.nextToken("\n");
        		}

        		public long nextLong() {
        			return Long.parseLong(next());
        		}

        		public int nextInt() {
        			return Integer.parseInt(next());
        		}

        	}
        }

        import java.io.*;
        import java.util.StringTokenizer;
        import java.util.*;
        import java.math.*;
        import java.lang.Integer;

        public class Solution {

        	public static String sort(Integer[] arr) {
        		Integer n= arr.length;
        		Integer[] narr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    narr[i]=arr[i];
        		}
        		Integer[] oarr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    oarr[i]=arr[i];
        		}

        		Integer res;
        		Integer resindex;
        		Boolean check;

        		for (int i = 0; i < n; i++) {

        		    check=true;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n-i; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        	    //System.out.println("here");
        			    res=0;
        			    resindex=0;
        			    for (int j = 0; j < n-i; j++) {
        			        if(narr[j]>res){
        			            res=narr[j];
        			            resindex=j;
        			        }
        			        //System.out.println(resindex);
        			    }

        			    narr[resindex]=narr[n-i-1];

        			    narr[n-i-1]=res;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n-i; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        		 //System.out.println("here");

        		}

        		Arrays.sort(oarr);
        		//for (int j = 0; j < n; j++) {
        	    //System.out.println(oarr[j]);
        	    //}

        		if(Arrays.equals(narr, oarr)){
        		    return "YES";
        		}else{
        		    return "NO";
        		}

        	}

        	public static void main(String[] args) throws Exception {
        		FastScanner cin = new FastScanner(System.in);
        		Integer n =cin.nextInt();

        		Integer[] arr= new Integer[n];

        		for (int i = 0; i < n; i++) {
        			arr[i]=cin.nextInt();

        		}

        		System.out.println(sort(arr));

        	}

        	static class FastScanner {
        		private BufferedReader reader = null;
        		private StringTokenizer tokenizer = null;

        		public FastScanner(InputStream in) {
        			reader = new BufferedReader(new InputStreamReader(in));
        			tokenizer = null;
        		}

        		public String next() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					tokenizer = new StringTokenizer(reader.readLine());
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}
        			return tokenizer.nextToken();
        		}

        		public String nextLine() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					return reader.readLine();
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}

        			return tokenizer.nextToken("\n");
        		}

        		public long nextLong() {
        			return Long.parseLong(next());
        		}

        		public int nextInt() {
        			return Integer.parseInt(next());
        		}

        	}
        }

        import java.io.*;
        import java.util.StringTokenizer;
        import java.util.*;
        import java.math.*;
        import java.lang.Integer;

        public class Solution {

        	public static String sort(Integer[] arr) {
        		Integer n= arr.length;
        		Integer[] narr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    narr[i]=arr[i];
        		}
        		Integer[] oarr=  new Integer[n];
        		for (int i = 0; i < n; i++) {
        		    oarr[i]=arr[i];
        		}

        		Integer res;
        		Integer resindex;
        		Boolean check;

        		for (int i = 0; i < n; i++) {

        		    check=true;

        	    while(check){
        	        check=false;
        		for (int j = 1; j < n-i; j++) {
        		    //System.out.println(narr[j]);
        		    if(narr[j]>=narr[j-1]+2){
        		        check=true;
        		        narr[j]=narr[j]-1;
        		        narr[j-1]=narr[j-1]+1;
        		    }
        		    if(narr[j-1]>=narr[j]+2){
        		        check=true;
        		        narr[j]=narr[j]+1;
        		        narr[j-1]=narr[j-1]-1;
        		    }
        		}
        	    }

        	    //System.out.println("here");
        			    res=0;
        			    resindex=0;
        			    for (int j = 0; j < n-i; j++) {
        			        if(narr[j]>res){
        			            res=narr[j];
        			            resindex=j;
        			        }
        			        //System.out.println(resindex);
        			    }

        			    narr[resindex]=narr[n-i-1];

        			    narr[n-i-1]=res;

        		 //System.out.println("here");

        		}

        		Arrays.sort(oarr);
        		//for (int j = 0; j < n; j++) {
        	    //System.out.println(oarr[j]);
        	    //}

        		if(Arrays.equals(narr, oarr)){
        		    return "YES";
        		}else{
        		    return "NO";
        		}

        	}

        	public static void main(String[] args) throws Exception {
        		FastScanner cin = new FastScanner(System.in);
        		Integer n =cin.nextInt();

        		Integer[] arr= new Integer[n];

        		for (int i = 0; i < n; i++) {
        			arr[i]=cin.nextInt();

        		}

        		System.out.println(sort(arr));

        	}

        	static class FastScanner {
        		private BufferedReader reader = null;
        		private StringTokenizer tokenizer = null;

        		public FastScanner(InputStream in) {
        			reader = new BufferedReader(new InputStreamReader(in));
        			tokenizer = null;
        		}

        		public String next() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					tokenizer = new StringTokenizer(reader.readLine());
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}
        			return tokenizer.nextToken();
        		}

        		public String nextLine() {
        			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        				try {
        					return reader.readLine();
        				} catch (IOException e) {
        					throw new RuntimeException(e);
        				}
        			}

        			return tokenizer.nextToken("\n");
        		}

        		public long nextLong() {
        			return Long.parseLong(next());
        		}

        		public int nextInt() {
        			return Integer.parseInt(next());
        		}

        	}
        }

import java.util.*;
import java.io.*;
import java.math.*;
public class cf
{
    static int n;
    static int k;
    static String s;
    static int arr[];
    static int brr[];
    public static void main(String args[])throws IOException
    {
        PrintWriter out=new PrintWriter(System.out);
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[]=new int[n];
        for(int i = 0 ;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        int mark[]=new int[n];
        int taken=0;

        while(taken!=n)
        {
            int maxpos=0;
            int max=-1;
            int st=0;
            for(int i = 1 ;i<n;i++)
            {
                if(mark[i]==1)
                {
                    st++;
                    continue;
                }
                if(Math.abs(arr[i]-arr[i-st-1])>1)
                {
                    System.out.println("NO");
                    st=0;
                    System.exit(0);
                }
                if(max<arr[i])
                {
                    max=arr[i];
                    maxpos=i;
                }

            }
            mark[maxpos]=1;

            taken++;
        }
        System.out.println("YES");
    }

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE];bufferPointer = bytesRead = 0;
        }
        public int nextInt() throws IOException
        {
            int ret = 0;byte c = read();
            while (c <= ' ')c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do{ret = ret * 10 + c - '0';}  while ((c = read()) >= '0' && c <= '9');
            if (neg)return -ret;
            return ret;
        }
        public String next() throws IOException
        {
            byte[] buf = new byte[500000];int cnt = 0, c;
            while ((c = read()) != -1){ if (c == '\n') break; buf[cnt++] = (byte) c;}
            return new String(buf, 0, cnt);
        }
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

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

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

		public int ni() {
			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 nl() {
			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 int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

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

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}

    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        //prime  = new boolean[n + 1];
		//sieve();
		//prime[1] = false;
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));

            */
          int x = sc.ni();
          int []arr = new int[x];
          int flag = 0;
          HashMap<Integer,Integer> hs = new HashMap<>();
          for(int i=0;i<x;i++)
          {
              arr[i] = sc.ni();
              hs.put(arr[i],i);

          }
          int []b = new int[x+1];
          for(int i=0;i<x;i++)
          {
              b[i] = arr[i];
          }
          b[x] = 0;
          for(int i=1;i<x;i++)
          {
             if(Math.abs(arr[i]-arr[i-1])>=2)
             {
                 flag = 1;
                 break;

             }
          }
          if(flag == 0)
          {
          Arrays.sort(arr);
          for(int i=x-1;i>=0;i--)
          {
              int fe = 0;
              for(int j=0;j<x;j++)
              {
                  if(arr[i]==b[j])
                  {
                      fe = j;
                      for(int k=j;k<=x-1;k++)
                      {
                          if(b[k]!=0)
                          {
                          if(b[k+1]==0)
                          b[k] = 0;
                          else
                          b[k] = b[k+1];
                          }
                      }
                      break;
                  }
              }
              if(fe!=0 && fe!= x-1)
              {
                  if((Math.abs(b[fe-1]-b[fe+1])>=2))
                  {
                      flag = 1;
                      break;
                  }
              }

          }

          }
          if(flag == 0)
          w.println("YES");
          else
          w.println("NO");

w.close();

    }

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n)
    {
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            sum = 1;
            //System.out.print(2 + " ");
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                n /= i;
            }
            sum++;
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            sum++;
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static int log2(int value) {
    return Integer.SIZE-Integer.numberOfLeadingZeros(value);
}

    static int binarysearch(int []arr,int p,int n)
    {

        int st = 0;
        int end = n-1;
        int mid = (st + end)/2;
        int temp = 0;
        while(st < end)
        {
            mid = (st + end)/2;

            if(p > arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid;

            }
            else if(p == arr[mid])
            {
            temp = mid;
            break;
            }

        }
        if(st == end)
        temp = st;

        return temp;
    }

    static class Student
    {

        int floor;
        int time;
        Student(int floor,int time)
        {
            this.floor = floor;
            this.time = time;

        }

    }

    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}

}

import java.util.Scanner;

public class Source {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        if (a % 2 == 0) {
            System.out.println(0);
        }
        else {
            System.out.println(1);
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Ravioli_Sort_1600 {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		br.close();
		int[] a = new int[n];
		for (int i = 0; i<n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}

		int max;
		Loop:
		for (int i = n; i>1; i--) {
			max = 0;
			for (int j = 1; j<i; j++) {
				if (Math.abs(a[j]-a[j-1])>1) {
					System.out.println("NO");
					break Loop;
				}
				if (a[j]>max) {
					max = j;
				}
			}
			for (int j = max; j<i-1; j++) {
				a[j] = a[j+1];
			}
			if (i == 2) {
				System.out.println("YES");
			}
		}
	}
}

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		int a = kb.nextInt();
		int b[] = new int[a];
		int max = -1;
		int min = 1000000;
		boolean pd = false;
		for (int i = 0; i < a; i++) {
			b[i] = kb.nextInt();
			if (b[i] > max)
				max = b[i];
			if (b[i] < min)
				min = b[i];
		}
		if (max - min > a - 1||max-b[a-1]>=2) {
			pd = true;
		} else {
			for (int i = 0; i < a - 1; i++) {
				if (b[i + 1] - b[i] >= 2 || b[i] - b[i + 1] >= 2) {
					pd = true;
					break;
				}
			}
		}
		if(pd){
			System.out.println("NO");
		}else{
			System.out.println("YES");
		}
	}
}

import java.io.*;
import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class April1C {

    private static BufferedReader in;
    private static BufferedWriter out;

    public static void main(String[] args) throws IOException {
        open();

        int n = readInt();
        int[] x = readInts();
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = x[i];
        }

        Arrays.sort(c);

        if (n == 1) {
            System.out.println("YES");
        } else {
            int last = n - 1;
            while (last >= 0) {
                boolean changed = false;
                while (!changed) {
                    changed = true;
                    for (int i = 0; i < n - 1; i++) {
                        if (x[i] - 2 >= x[i + 1]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i + 1] = sum / 2;
                            x[i] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        } else if (x[i + 1] - 2 >= x[i]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i] = sum / 2;
                            x[i + 1] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        }
                    }
                }

                int max = x[last];
                for (int i = last - 1; i >= 0; i--) {
                    if (max <= x[i]) {
                        max = x[i];
                        int t = x[last];
                        x[last] = x[i];
                        x[i] = t;
                    }
                }

                last--;
            }

            boolean yes = true;
            for (int i = 0; i < n; i++) {
                if (x[i] != c[i]) {
                    yes = false;
                    break;
                }
            }

            if (yes) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }

        }
        close();
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(in.readLine());
    }

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

    private static long readLong() throws IOException {
        return Long.parseLong(in.readLine());
    }

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

    private static double readDouble() throws IOException {
        return Double.parseDouble(in.readLine());
    }

    private static String readString() throws IOException {
        return in.readLine();
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}

import java.io.*;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class April1C {

    private static BufferedReader in;
    private static BufferedWriter out;

    public static void main(String[] args) throws IOException {
        open();

        int n = readInt();
        int[] x = readInts();

        if (n == 1) {
            System.out.println("YES");
        } else {
            int iter = 0;
            while (iter < 15) {
                boolean changed = false;
                while (!changed) {
                    changed = true;
                    for (int i = 0; i < n - 1; i++) {
                        if (x[i] - 2 >= x[i + 1]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i + 1] = sum / 2;
                            x[i] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        } else if (x[i + 1] - 2 >= x[i]) {
                            int sum = (x[i] + x[i + 1]) / 2;
                            x[i] = sum / 2;
                            x[i + 1] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        }
                    }
                }

                int max = x[n - 1];
                for (int i = n - 2; i >= 0; i--) {
                    if (max <= x[i]) {
                        max = x[i];
                        int t = x[n - 1];
                        x[n - 1] = x[i];
                        x[i] = t;
                    }
                }

                iter++;
            }

            if (x[n - 1] == x[n - 2]) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
        close();
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(in.readLine());
    }

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

    private static long readLong() throws IOException {
        return Long.parseLong(in.readLine());
    }

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

    private static double readDouble() throws IOException {
        return Double.parseDouble(in.readLine());
    }

    private static String readString() throws IOException {
        return in.readLine();
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}

import java.io.*;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class April1C {

    private static BufferedReader in;
    private static BufferedWriter out;

    public static void main(String[] args) throws IOException {
        open();

        int n = readInt();
        int[] x = readInts();

        if (n == 1) {
            System.out.println("YES");
        } else {
            int iter = 0;
            int last = n - 1;
            while (iter < 15) {
                boolean changed = false;
                while (!changed) {
                    changed = true;
                    for (int i = 0; i < n - 1; i++) {
                        if (x[i] - 2 >= x[i + 1]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i + 1] = sum / 2;
                            x[i] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        } else if (x[i + 1] - 2 >= x[i]) {
                            int sum = (x[i] + x[i + 1]) / 2;
                            x[i] = sum / 2;
                            x[i + 1] = sum / 2 + sum % 2;
                            changed = false;
                            break;
                        }
                    }
                }

                int max = x[last];
                for (int i = last - 1; i >= 0; i--) {
                    if (max <= x[i]) {
                        max = x[i];
                        int t = x[last];
                        x[last] = x[i];
                        x[i] = t;
                    }
                }

                iter++;
            }

            if (x[n - 1] == x[n - 2]) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
        close();
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(in.readLine());
    }

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

    private static long readLong() throws IOException {
        return Long.parseLong(in.readLine());
    }

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

    private static double readDouble() throws IOException {
        return Double.parseDouble(in.readLine());
    }

    private static String readString() throws IOException {
        return in.readLine();
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}

import java.io.*;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class April1C {

    private static BufferedReader in;
    private static BufferedWriter out;

    public static void main(String[] args) throws IOException {
        open();

        int n = readInt();
        int[] x = readInts();

        if (n == 1) {
            System.out.println("YES");
        } else {
            int iter = 0;
            while (iter < 15) {
                boolean changed = false;
                while (!changed) {
                    changed = true;
                    for (int i = 0; i < n - 1; i++) {
                        if (x[i] - 2 >= x[i + 1]) {
                            int sum = (x[i] + x[i + 1]);
                            x[i + 1] = sum / 2;
                            x[i] = sum / 2 + sum % 2;
                            changed = false;
                        } else if (x[i + 1] - 2 >= x[i]) {
                            int sum = (x[i] + x[i + 1]) / 2;
                            x[i] = sum / 2;
                            x[i + 1] = sum / 2 + sum % 2;
                            changed = false;
                        }
                    }
                }

                int max = x[n - 1];
                for (int i = n - 2; i >= 0; i--) {
                    if (max <= x[i]) {
                        int t = x[n - 1];
                        x[n - 1] = x[i];
                        x[i] = t;
                    }
                }

                iter++;
            }

            if (x[n - 1] == x[n - 2]) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
        close();
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

    private static int readInt() throws IOException {
        return Integer.parseInt(in.readLine());
    }

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

    private static long readLong() throws IOException {
        return Long.parseLong(in.readLine());
    }

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

    private static double readDouble() throws IOException {
        return Double.parseDouble(in.readLine());
    }

    private static String readString() throws IOException {
        return in.readLine();
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}

import java.util.*;
import java.io.*;
public class Solution{

    public static void main(String[] args){
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int x = sc.nextInt();
        int k;
        for(int i=1;i<n;i++){
            k = sc.nextInt();
            if(Math.abs(x-k)>1){
                System.out.println("NO");
                break;
            }
            x = k;
            if(i==n-1) System.out.println("YES");
        }
    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class RaviolliSort {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int size = sc.nextInt();
		ArrayList<Integer> a = new ArrayList<Integer>();
		for (int i = 0; i < size; i++) {
			a.add(sc.nextInt());
		}
		sc.close();
		for (int i = 0; i < a.size() - 1; i++) {
			if (Math.abs(a.get(i)- a.get(i+1)) > 1) {
				System.out.println("NO");
				return;
			}
		}
		while (!a.isEmpty()) {
			int max = a.get(0);
			int ind = 0;
			for (int i = 0; i < a.size(); i++) {
				if (a.get(i)> max) {
					ind = i;
					max = a.get(i);
				}
			}
			if(max-a.get(a.size()-1)>1) {
				System.out.println("NO");
				return;
			}
			a.remove(ind);
		}
		System.out.println("YES");
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class RaviolliSort {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		int[] a = Arrays.stream(sc.nextLine().split(" ")).mapToInt(x -> Integer.parseInt(x)).toArray();
		for (int i = 0; i < a.length - 1; i++) {
			for (int j = i + 1; j < a.length; j++) {
				if (Math.abs(a[i] - a[j]) > 1) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
		sc.close();
	}
}

import java.util.*;
import java.io.*;
public class Cprob {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int num = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		int prev = Integer.parseInt(st.nextToken());
		boolean ok = true;
		while(st.hasMoreTokens()) {
			int x = Integer.parseInt(st.nextToken());
			if(Math.abs(x - prev) >= 2) {
				ok = false;
				break;
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		br.close();
	}
}

import java.util.*;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int [] arr = new int[n];

		for (int i =0;i<n;i++)
			arr[i] = sc.nextInt();
		boolean sp=true;
		for (int i =1;i<n;i++)
			if (arr[i]-arr[i-1]>=2)
			{
				sp = false;
				break;
			}
		if (sp)
		System.out.println("YES");
		else
			System.out.println("NO");
		sc.close();

	}

}

import java.util.*;
public class C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int rav = sc.nextInt();
        ArrayList<Integer> raviolis = new ArrayList<>();
        ArrayList<Integer> clone = new ArrayList<>();
        while(rav-- > 0){
            int n = sc.nextInt();
            raviolis.add(n);
            clone.add(n);
        }
        ArrayList<Integer> sorted = new ArrayList<>();
        while(raviolis.size() > 0){
            for(int i=0;i<raviolis.size()-1;i++){
                int diff = Math.abs(raviolis.get(i)-raviolis.get(i+1));
                if(diff >= 2){
                    if(raviolis.get(i) > raviolis.get(i+1)){
                        raviolis.set(i,raviolis.get(i)-diff/2);
                        raviolis.set(i+1,raviolis.get(i+1)+(diff+1)/2);
                    }
                    else if(raviolis.get(i) < raviolis.get(i+1)){
                        raviolis.set(i+1,raviolis.get(i+1)-diff/2);
                        raviolis.set(i,raviolis.get(i)+(diff+1)/2);
                    }
                }
            }
            int maxindex = -1;
            int maxsize = 0;
            for(int i=0;i<raviolis.size();i++){
                if(raviolis.get(i) > maxsize){
                    maxsize = raviolis.get(i);
                    maxindex = i;
                }
            }
            int k = raviolis.remove(maxindex);
            sorted.add(k);
        }
        Collections.reverse(sorted);
        Collections.sort(clone);
        System.out.println(sorted.equals(clone));
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }
//sss
        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }//s
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }//ss

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }//ssss

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return; //s
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? "YES" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }//sss

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? "YES" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}
//sss

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }//ss
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

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

public class Solution2 {

    Random random = new Random();
    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {
            System.out.println("YES");
            return;
        }
        if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {
            System.out.println("NO");
            return;
        }
        for (int i = 1; i < n; i++) {
            if (Math.abs(a[i] - a[i - 1]) >= 2) {
                System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? "YES" : "NO" : "NO" : "NO");
                return;
            }
        }
        System.out.println("YES");
    }

    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Solution2().run();
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.StringTokenizer;

/**
 * @author ayratgdl
 * @date 01.04.18
 */
public class CF20180401C {
    int n;
    int[] a;
    public static void main(String[] args) {
        new CF20180401C().solve(System.in, System.out);
    }

    public void solve(InputStream input, OutputStream output) {
        In in = new In(input);
        Out out = new Out(output);

        n = in.int1();
        a = in.ints(n);
        int size = n;
        while (size > 1) {
            int max = 0;
            int maxI = -1;
            for (int i = 0; i < n; i++) {
                if (!checkCorrect(i)) {
                    out.write("NO").ln();
                    return;
                }
                if (a[i] != 0 && (maxI == -1 || a[i] > max)) {
                    maxI = i;
                    max = a[i];
                }
            }
            a[maxI] = 0;
            size--;
        }
        out.write("YES").ln();
        return;
    }

    private boolean checkCorrect(int i) {
        for (int j = i+1; j < a.length; j++) {
            if (a[j] != 0) {
                int r = a[i] - a[j];
                if (r > 1 || r < -1) {
                    return false;
                } else {
                    return true;
                }
            }
        }
        return true;
    }

    public class In {
        private BufferedReader reader;
        StringTokenizer tokener;

        public In(BufferedReader reader) {
            this.reader = reader;
        }

        public In(Reader reader) {
            this.reader = new BufferedReader(reader);
        }

        public In(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public int int1() {
            return Integer.parseInt(word());
        }

        public String word() {
            try {
                if (tokener == null || !tokener.hasMoreTokens())
                    tokener = new StringTokenizer(reader.readLine());
                return tokener.nextToken();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public long long1() {
            return Long.parseLong(word());
        }

        public String[] words(int n) {
            String[] result = new String[n];
            for (int i = 0; i < n; i++)
                result[i] = word();
            return result;
        }

        public int[] ints(int n) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++)
                result[i] = Integer.parseInt(word());
            return result;
        }

        public long[] longs(int n) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++)
                result[i] = Long.parseLong(word());
            return result;
        }
    }

    public class Out {
        private BufferedWriter writer;
        private boolean isEmptyLine = true;

        public Out(BufferedWriter writer) {
            this.writer = writer;
        }

        public Out(Writer writer) {
            this.writer = new BufferedWriter(writer);
        }

        public Out(OutputStream out) {
            this.writer = new BufferedWriter(new OutputStreamWriter(out));
        }

        private Out write(String str) {
            try {
                if (!isEmptyLine)
                    writer.write(" ");
                else
                    isEmptyLine = false;
                writer.write(str);
                return this;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public Out ln() {
            try {
                writer.newLine();
                writer.flush();
                isEmptyLine = true;
                return this;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public Out write(Object obj) {
            return write(obj.toString());
        }

        public Out write(int num) {
            return write(Integer.toString(num));
        }

        public Out write(long num) {
            return write(Long.toString(num));
        }

        public Out write(Object[] objs) {
            for (Object obj : objs)
                write(obj);
            return this;
        }

        public <T> Out write(Iterable<T> iter) {
            for (T obj : iter)
                write(obj);
            return this;
        }

        public Out write(int[] nums) {
            for (int num : nums)
                write(num);
            return this;
        }

        public Out write(long[] nums) {
            for (long num : nums)
                write(num);
            return this;
        }
    }
}

/*
ЗАПУСКАЕМ ВЫСОКОГО
░ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */

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

public class Main {

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        int[] ind = new int[n];
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> sorted = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int inr = 0; inr < n; inr++) {
            for (int i = 1; i < list.size(); i++) {
                if ((list.get(i) - list.get(i - 1)) > 1) {
                    out.print("NO");
                    return;
                }
            }
            int max = -1;
            for (int i : list) {
                max = maxInt(max, i);
            }
            for (int i = 0; i < n; i++) {
                if (list.get(i) == max) {
                    sorted.add(list.get(i));
                    list.remove(i);
                    break;
                }
            }
        }
        Arrays.parallelSort(a);
        Collections.reverse(sorted);
        for (int i = 0; i < n; i++) {
            if (a[i] != sorted.get(i)) {
                out.print("NO");
                return;
            }
        }
        out.print("YES");
    }

    boolean sorted(int[] a, int n) {
        int[] b = a.clone();
        Arrays.sort(b);
        boolean ans = true;
        for (int i = 0; i < n; i++) ans &= a[i] == b[i];
        return ans;
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        tok = new StringTokenizer("");
    }

    void run() throws IOException {
        solve();
        out.close();
    }

    class Fenwik {
        private long[] t;
        private int length;

        Fenwik(int[] a) {
            this.length = a.length + 100;
            this.t = new long[length];
            for (int i = 0; i < a.length; ++i) this.inc(i, a[i]);
        }

        void inc(int i, int delta) {
            for (; i < this.length; i = i | (i + 1)) t[i] += delta;
        }

        long getSum(int r) {
            long sum = 0;
            for (; r >= 0; r = (r & (r + 1)) - 1) sum += this.t[r];
            return sum;
        }

    }

    String delimiter = " ";

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;
            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++)
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        return a;
    }

    int[] readSortedIntArray(int size) throws IOException {
        Integer[] array = new Integer[size];
        for (int index = 0; index < size; ++index) array[index] = readInt();
        Arrays.sort(array);
        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) sortedArray[index] = array[index];
        return sortedArray;
    }

    int[] sortedIntArray(int size, int[] array) throws IOException {
        for (int index = 0; index < size; ++index) array[index] = readInt();
        Arrays.sort(array);
        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) sortedArray[index] = array[index];
        return sortedArray;
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) min = Math.min(min, value);
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) max = Math.max(max, value);
        return max;
    }

    long minLong(long... values) {
        long min = Long.MAX_VALUE;
        for (long value : values) min = Math.min(min, value);
        return min;
    }

    long maxLong(long... values) {
        long max = Long.MIN_VALUE;
        for (long value : values) max = Math.max(max, value);
        return max;
    }

    boolean checkIndex(int index, int size) {
        return (0 <= index && index < size);
    }

    int abs(int a) {
        if (a < 0) return -a;
        return a;
    }
}

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i=0;i<arr.length;i++){
                arr[i] = in.nextInt();
            }
            for (int i= 0;i<arr.length-1;i++) {
                if (Math.abs(arr[i+1]-arr[i])>1){
                    System.out.println("NO");
                    break;
                }else if (i==(arr.length-2)){
                    System.out.println("YES");
                }
            }
        }
    }
}

import java.util.Scanner;

public class aprilFool1 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean flag = true;
		int[] arr = new int[n];
		for(int i = 0;i<n;i++) {
			arr[i] = in.nextInt();
			if(i!=0&&Math.abs(arr[i]-arr[i-1])>1) {
				System.out.println("NO");
				flag = false;
			}
		}
		if(flag)
			System.out.println("YES");

		}

}