#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

vector<int >ma;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int tp;
        cin >> tp;
        ma.push_back(tp);
    }
    while (ma.size() > 1)
    {
        int max=0;
        for (int i = 1; i < ma.size(); i++)
        {
            if (ma[i] > ma[max])
            max = i;
            if (abs(ma[i] - ma[i-1])>1)
           {
           cout<<"NO";
               return 0;
           }
        }
           ma.erase(ma.begin()+max);
    }
        cout<<"YES";
        return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <cmath>
#include <sstream>
#include <string>
#include <algorithm>
#include <tuple>
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define deb(x) for(auto temp : (x))cout<<temp<<" ";cout<<endl;
#define debs(x) cout<<(x).size()<<": ";for(auto temp : (x))cout<<temp<<" ";cout<<endl;
#define cin_ ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef tuple<int, int, int> t3;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<db> vdb;
typedef vector<vpii> vvpii;
typedef vector<pair<int, pii>> vpipii;

const int inf = 1e9 + 7;
const db eps = 1e-9;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main()
{
    cin_;
    int n;
    cin >> n;
    vi a(n, 0);
    vi a1(n, 0);
    for (int i = 0; i<n; ++i)
    {
        cin >> a[i];
        a1[i] = a[i];
    }
    for (int i = 0; i < n - 1; ++i)
    {
        if (abs(a[i] - a[i + 1]) > 1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define RE register
#define rint RE int
#define rll RE ll
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define req(i, l, r) for (rint i = l; i >= r; i--)
#define Each(i) for (rint i = head[u]; i != -1; i = edge[i].nxt)
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second

template <typename T>
void read(T &x) {
  x = 0; char op = getchar(); int F = 1;
  while (!isdigit(op)) {
    if (op == '-') F *= -1; op = getchar();
  }
  while (isdigit(op)) {
    x = (x << 1) + (x << 3) + op - '0'; op = getchar();
  }
  x *= F;
}

template <typename T, typename ...Args>
void read(T &x, Args &...args) {
  read(x); read(args...);
}

template <typename T1, typename T2>
void ckmax(T1 &x, T2 y) {
  if (x < y) x = y;
}

template <typename T1, typename T2>
void ckmin(T1 &x, T2 y) {
  if (x > y) x = y;
}

int a[1005], n;

int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    if (i > 1 && abs(a[i] - a[i - 1]) > 1) {
      cout << "NO\n";
      exit(0);
    }
  }
  cout << "YES\n";
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
long long n,i,mas[107];

int main()
{
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>mas[i];
    }
    for(i=1; i<n; i++)
        if(abs(mas[i]-mas[i+1])>=2)
        {
            cout<<"No"<<endl;
            return 0;
        }
    cout<<"Yes"<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

struct block {
	int last,nxt;
	bool del;
	int val;
}b[25];

int n;
int head=-1,tail=0x3f3f3f3f;
int st;
int a[25];

bool check() {
	for(int point=st;point!=tail;point=b[point].nxt) {
		int last=b[point].last,nxt=b[point].nxt;
		// printf("point:%d last:%d nxt:%d\n",point,last,nxt);
		if(last!=head) {
			if(abs(b[last].val-b[point].val)>=2) return 0;
			// puts("GG1");
		}
		if(nxt!=tail) {
			if(abs(b[nxt].val-b[point].val)>=2) return 0;
			// puts("GG2");
		}
	}
	// puts("GET");
	return 1;
}

int main() {
	scanf("%d",&n);
	// printf("%d\n",tail);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		b[i].del=0;
		b[i].val=a[i];
		if(i==1) {
			b[i].last=head;
			st=i;
		}
		else b[i].last=i-1;
		if(i==n) {
			b[i].nxt=tail;
		}
		else b[i].nxt=i+1;
	}
	int c=n-1;
	if(!check()) {
		puts("NO");
		return 0;
	}
	while(c--) {
	// puts("GG");
		int pos,maxx=-1;
		for(int i=1;i<=n;i++) {
			if(b[i].del) continue;
			if(b[i].val>maxx){
				maxx=b[i].val;
				pos=i;
			}
		}
		b[pos].del=1;
		if(b[pos].last==head) {
			int nxt=b[pos].nxt;
			b[nxt].last=head;
			st=nxt;
		}
		else if(b[pos].nxt==tail) {
			int last=b[pos].last;
			b[last].nxt=tail;
		}
		else {
			int last=b[pos].last,nxt=b[pos].nxt;
			b[last].nxt=nxt;
			b[nxt].last=last;
		}
		if(!check()) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
//#include<ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector< pair<int,int> >
#define vpll vector< pair<ll,ll> >
#define ppll pair< ll,pll >
#define pllp pair< pll,ll >
#define stll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
#define mppll map<pll,ll>
#define mpii map<int,int>
#define mpll map<ll,ll>
#define mpss map<string,string>
#define mpsll map<string,ll>
#define mplls map<ll,string>
#define umpii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define umpss unordered_map<string,string>
#define umpsll unordered_map<string,ll>
#define umplls unordered_map<ll,string>
#define umap unordered_map
#define uset unordered_set
#define PQ priority_queue

#define rep(i,n) for(i=0;i<n;i++)
#define itfor(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?’\n’:’ ‘)
#define printv(a) printa(a,0,a.size())
#define print2d(a,r,c) for(int i=0;i<r;i++) for(int j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?’\n’:’ ‘)
#define pb push_back
#define MP make_pair
#define UB upper_bound
#define LB lower_bound
#define SQ(x) ((x)*(x))
#define issq(x) (((ll)(sqrt((x))))*((ll)(sqrt((x))))==(x))
#define F first
#define S second
#define mem(a,x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define gamma 0.5772156649
#define nl "\n"
//#define lg(r,n) (int)(log2(n)/log2(r))
//#define sf(a) scanf(“%d”,&a)
//#define sfl(a) scanf(“%lld”,&a)
//#define sfc(a) scanf(“%c”,&a)
//#define sff(a,b) scanf(“%d %d”,&a,&b)
//#define sffl(a,b) scanf(“%lld %lld”,&a,&b)
//#define sfff(a,b,c) scanf(“%d %d %d”,&a,&b,&c)
//#define sfffl(a,b,c) scanf(“%lld %lld %lld”,&a,&b,&c)
//#define pf printf
//#define pfi(a) pf(“%d\n”,&a)
//#define pfl(a) pf(“%lld\n”,&a)
//#define _ccase printf(“Case %d: “,++cs)
//#define _case cout<<“Case “<<++cs<<“: ”
#define debug(x) cout<<#x"="<<(x)<<nl

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define all(v) v.begin(),v.end()
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define toint(a) atoi(a.c_str())
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod=1e9+7;
const int mxn=1e5+9;
const ld eps=1e-9;
//ll qpow(ll n,ll k) {ll ans=1;while(k){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans;}
deque<ll>d;
bool yo(vll v)
{
    for(ll i=1;i<v.size();i++) if(v[i]<v[i-1]) return 0;
    return 1;
}
bool ck()
{
    for(ll i=1;i<d.size();i++) if(abs(d[i]-d[i-1])>=2) return 0;
    return 1;
}
int main()
{
    fast;
    ll i,j,n,m,k;
    cin>>n;
    for(i=0;i<n;i++) cin>>k,d.pb(k);
    vll v;
    while(d.size()>0){
        if(ck()==0) return cout<<"NO\n",0;
        ll mx=d[0];
        auto it=d.begin();
        auto sol=d.begin();
        for(i=1;i<d.size();i++){
            it++;
            if(d[i]>mx){
                mx=d[i];
                sol=it;
            }
        }
        d.erase(sol);
        v.pb(mx);
    }
    rev(v);
    if(yo(v))cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
  int a;
  scanf("%d",&a);
  int test=0;
  int past=0;
  for(int i=0;i<a;i++)
  {
    int temp;
    scanf("%d",&temp);
    if(i==0)
    {
      past=temp;
    }else
    {
      if(temp==past-1 || temp==past+1 || temp==past)
      {
        //ok
      }else
      {
        test=1;
      }
      past=temp;
    }
  }
  if(test==0)
  {
    printf("YES");
  }else
  printf("NO");
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int a[20],b[20];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(int i=1; i<n; i++)
        {
            if(fabs(a[i]-a[i-1])>=2)
            {
                printf("NO\n");
                return 0;
            }
        }
         printf("YES\n");
    }
    return 0;
}

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
int n,a[1010],b[1010],c[1010],l=0,ans,p;
int f(int x)
{
	return x>0?x:-x;
}
void doit(int i)
{     while(1)
        {
        int  pp=1;
	 	for(int j=1;j<=n-i;j++)
		    {
			if(a[j]-a[j+1]>=2)
			   {
			   pp=0;int p=a[j]-a[j+1];
			   a[j]-=p/2;
			   a[j+1]+=p/2;
		       }
		    if(a[j+1]-a[j]>=2){
		    	pp=0;int p=a[j+1]-a[j];
		    	a[j]+=p/2;
			    a[j+1]-=p/2;
			    }
		    }
		if (pp) break;
	    }
	//for(int j=1;j<=n-i+1;j++) printf("%d ",a[j]);
	//printf("\n");
	for(int j=1;j<=n-i+1;j++)
	    	if(a[j]>ans) ans=a[j],p=j;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	   {
	   	scanf("%d",&a[i]);b[i]=a[i];
	   }
	sort(b+1,b+1+n);
	for(int i=1;i<=n-1;i++)
	   {
	   	 ans=0,p=0;
	   	 doit(i);
	   	 {c[++l]=ans;}
	   	 //printf("%d",ans);
	   	for(int j=p;j<=n-i;j++)
	   	   a[j]=a[j+1];
	   }
    for(int i=1;i<=n-1;i++) if(b[n-i+1]!=c[i]) {printf("NO");return 0;}
	printf("YES");
 }

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int>a,b,c;
int n;

bool check(void){
    for(int i=1; i<a.size(); i++){
        if(abs(a[i]-a[i-1])>=2) return 0;
    }
    return 1;
}

bool comp(void){
    for(int i=0; i<n; i++){
        if(b[i]!=c[i]) return 0;
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n;
    int k = n;
    for(int i=0; i<n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
        b.push_back(x);
    }
    sort(b.begin(),b.end());
    int ccc = 0;
    while(1){
        if(!check()){
            cout << "NO" << endl;
            return 0;
        }
        if(a.size()==0){
            cout << "YES" << endl;
            return 0;
        }

        int mx = -1, ind = 0;
        for(int i=0; i<a.size(); i++){
            if(a[i]>mx){
                mx = a[i];
                ind = i;
            }
        }
        a.erase(a.begin()+ind);
        c.push_back(mx);
    }

}

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main () {

	int a,b,c;
	cin >> a >> b;
	for (int i=2; i<=a; ++i) {
		cin >> c;
		if (abs(c-b) >= 2) {cout << "NO";return 0;}
		b = c;
	}
	cout << "YES";

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<double>   vd;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

int main(){

	int n;
	sf1(n);

	vi v;
	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		v.pb(x);
	}

	stack<int> sorted;
	vi mark(n+5,0);
	for (int i = 0; i < n; ++i)
	{
		vi newv;
		for (int j = 0; j < n; ++j)
		{
			if(!mark[j])
				newv.pb(v[j]);
		}
		for (int j = 0; j < newv.size()-1; ++j)
		{
			if(abs(newv[j] - newv[j+1]) >= 2){
				printf("NO\n");
				return 0;
			}
		}
		int mx = -inf;
		int mxi = 0;

		for (int j = 0; j < n; ++j){
			if(!mark[j] and v[j] >= mx){
				mx = v[j];
				mxi = j;
			}
		}

		mark[mxi] = 1;
		if(sorted.size() and (abs(sorted.top() - v[mxi]) >= 2)){
			printf("NO\n");
			return 0;
		}

		sorted.push(v[mxi]);

		newv.clear();

		for (int j = 0; j < n; ++j)
		{
			if(!mark[j])
				newv.pb(v[j]);
		}
		if(!newv.size()) continue;
		for (int j = 0; j < newv.size()-1; ++j)
		{
			if(abs(newv[j] - newv[j+1]) >= 2){
				printf("NO\n");
				return 0;
			}
		}

	}

	vi ans;
	for (int i = 0; i < n; ++i)
	{
		ans.pb(sorted.top());
		sorted.pop();
	}

	for (int i = 0; i < n-1; ++i)
	{
		if(abs(ans[i] - ans[i+1]) >= 2){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

/*input
3
3 1 2
*/
#include <bits/stdc++.h>
using namespace std;

int a[20], n;
bool ok = true;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (a[j - 1] > a[j]) {
                swap(a[i], a[j]);
                if (a[j] - a[i] >= 2) ok = false;
            }
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

vector <int> a;
int n;

bool check(){
    for (int i = 0; i < a.size() - 1; i++)
        if (abs(a[i + 1] - a[i]) > 1) return false;
    return true;
}

bool so(){
    for (int i = 0; i < a.size() - 1; i++)
        if (a[i] > a[i+1]) return false;
    return 1;
}

int main(){
    cin >> n;
    a.resize(n);
    for (int i = 0; i < a.size(); i++)
        cin >> a[i];
    if(!check()) return cout << "NO" << endl, 0;
    while (!so()){
        int t = 0;
        for (int i = 0; i < a.size(); i++)
            if (a[t] < a[i]) t = i;
        int q = a[t];
        a.erase(a.begin() + t);
        if(!check()) return cout << "NO" << endl, 0;
    }
    cout << "YES" << endl;
}

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<deque>
#include<iterator>
#include<assert.h>
#include<bitset>
#include<climits>
#include<ctime>
#include<complex>
#include<bits/stdc++.h>
using namespace std;
//define for shortcut
#define mem(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(A) A.size()
#define clr(a) memset(a,0,sizeof(a))
#define pb push_back
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define vs vector<string>
#define vi vector<int>
#define vc vector<char>
#define sts set<string>
#define sti set<int>
#define stc set<char>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define ull unsigned long long
#define ll long long
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define rfor1(i,a,b) for(int i=a;i>=b;i--)
#define rfor0(i,a,b) for(int i=a-1;i>b;i--)
#define for0(i,a) for(int i=0;i<a;i++)
//read input
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define sfll2(a,b) scanf("%lld%lld",&a,&b)
#define sfll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define ss(a) scanf("%s",&a)
#define sc(a) scanf("%c",&a)
#define sd(a) scanf("%lf",&a)
#define pf(a) printf("%d",a)
#define pfll(a) printf("%lld",a)
#define pfd(a) printf("%.17f",a)
#define pc(a) printf("%c",a)
#define ps(a) printf("%s",a)
#define cs printf("Case %d: ",kk++)
#define cn printf("Case %d:\n",kk++)
///#define c# printf("Case #%d: ",kk++)
#define nl printf("\n")
#define done cout<<"done"<<endl;
#define eps 1e-9
#define mod 1000000007
#define inf INT_MAX
#define MX 100010
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define fast ios_base::sync_with_stdio(false);
template<typename T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline vi parse(T str)
{
    vi res;
    int s;
    istringstream os(str);
    while(os>>s)res.pb(s);
    return res;
}
template< class T > inline T _sqrt(T x)
{
    return (T) sqrt( (double) x);
}
template< class T > inline T _bigmod(T n,T m)
{
    T ans=1,mult=n%mod;
    while(m)
    {
        if(m & 1) ans=(ans*mult)%mod;
        m>>=1;
        mult=(mult*mult)%mod;
    }
    ans%=mod;
    return ans;
}
template< class T > inline T _modinv(T x)
{
    return _bigmod(x,(T) mod-2)%mod;
}
inline int len(string a)
{
    return a.length();
}
inline int len(char a[])
{
    return strlen(a);
}
template<class T> inline T _gcd(T a, T b)
{
    return (b==0) ? a : _gcd(b, a % b);
}
template< class T > inline T _lcm(T x,T y)
{
    return x*y/_gcd(x,y);
}
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//bool compare(const pair<float,string>&i, const pair<float,string>&j)
//{
//    return i.first > j.first;
//}
//int in_c() { int c; for (; (c = getchar()) <= ' '; ) { if (!~c) throw ~0; } return c; }
//int EQ(double d) {
//    if ( fabs(d) < EPS ) return 0;
//    return d > EPS ? 1 : -1 ;
//}
int brr[100];
int arr[100];
int main()
{
//    clock_t begin = clock();
//    //your code goes here
       int n;
       cin>>n;
       map<int,int>mp;
       for(int i=0; i<n; i++)
       {
           cin>>arr[i];
           mp[arr[i]]++;
       }
       arr[n]=1e9;
       for(int i=1; i<n; i++)
       {
           while(arr[i]<arr[i-1] && arr[i]<arr[i+1])
           {
               arr[i]++;
               arr[i-1]--;
           }
       }
       int c=0;
       for(int i=0; i<n; i++)
       {
           if(mp[arr[i]])
           {
               c++;
               mp[arr[i]]--;
           }
       }
       if(c==n)cout<<"Yes\n";
       else cout<<"No\n";
//    //end here
//    clock_t end = clock();
//    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
//    cerr<<"Running Time: "<<time_spent<<" Seconds"<<endl;
//    return 0;
}

#include<iostream>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;
int main(){
 int a[11]={0};
 int b;
 cin>>b;
 for(int i=1;i<=b;i++)
    cin>>a[i];
 int sum=0;
   for(int j=1;j<=b-1;j++)
    if(abs(a[j+1]-a[j])>=2) sum=1;
    if(sum!=0) cout<<"NO"<<"\n";
    else cout<<"YES"<<"\n";
}

#include<iostream>
#include<cmath>
using namespace std;
int a[11];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int flag=0;
    for(int i=0;i<n-1;i++)if(abs(a[i]-a[i+1]>=2))flag=1;
    if(flag)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
long long n,i,a[17],f=0;
int main()
{cin>>n;
for(i=1;i<=n;i++)cin>>a[i];
for(i=2;i<=n;i++)if(abs(a[i]-a[i-1])>=2){f=1;break;}
sort(a+1,a+n+1);
for(i=2;i<=n;i++)if(a[i]-a[i-1]>=2){f=1;break;}
if(f==1)cout<<"NO"<<endl; else cout<<"YES"<<endl;
    return 0;
}

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
  int n;
   int flag=0;
   int i;
   int s[50];
   scanf("%d",&n);
   scanf("%d",&s[0]);
   for(i=1;i<n;i++)
   {
       scanf("%d",&s[i]);
       if(s[i]-s[0]>=2||s[i]-s[0]<=-2)
        flag=1;
       s[0]=s[i];
   }
   if(flag==1)
    printf("NO\n");
   else
    printf("YES\n");
    return 0;
}

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#ifdef DEBUG
# pragma GCC optimize(0)
#endif // DEBUG
#define mem(x,y) memset(x,y,sizeof(x))
#define startcoding ios::sync_with_stdio(false);\
        cin.tie(0);
#define maxn 100005
using namespace std;namespace NYAM{
/*************************************************/
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int>Pll;
const int INF=0x3f3f3f3f;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
/*************************************************/
//StartCoding:
int a[maxn];
void main(){
    startcoding
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        if(abs(a[i]-a[i+1])>=2){
            puts("NO");
            return;
        }
    }
    puts("YES");
}}
int main(){
    #ifndef ONLINE_JUDGE
    //    freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    #endif // ONLINE_JUDGE
    NYAM::main();
    exit(0);
}

#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        arr.push_back(temp);
    }

    while(!arr.empty())
    {
        for(int i=0;i<arr.size()-1;i++)
        {
            if(fabs(arr[i]-arr[i+1])>=2)
            {
                cout << "NO";
                return 0;
            }
        }
        int maximum = 0;
        vector<int>::iterator ttt = arr.begin();
        for(vector<int>::iterator itr=arr.begin();itr!=arr.end();itr++)
        {
            if(*itr>maximum)
            {
                maximum = *itr;
                ttt = itr;
            }
        }
        arr.erase(ttt);
    }
    cout << "YES";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const long N = 10;
long a[N];

int main() {
  ios::sync_with_stdio(0);
  long n;
  cin >> n;
  for (long i = 0; i < n; ++i)
	cin >> a[i];
  bool res = true;
  for (long i = 0; i < n and res; ++i) {
	for (long j = 0; j < n - i - 1; ++j)
	  if (abs(a[j] - a[j + 1]) >= 2)
		res = false;
	for (long j = n - i; j < n - 1; ++j)
	  if (abs(a[j] - a[j + 1]) >= 2)
		res = false;
	if (!res) break;
	long temp = 0;
	for (long j = 1; j < n - i; ++j)
	  if (a[j] > a[temp])
		temp = j;
	long tempval = a[temp];
	for (long j = temp; j < n - i - 1; ++j)
	  a[j] = a[j + 1];
	a[n - i - 1] = tempval;
  }
  if (res)
	cout << "YES" << endl;
  else
	cout << "NO" << endl;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  for(int i=1;i<n;++i){
    if(abs(a[i]-a[i-1])>1){
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i;
    cin >> n;
    ll a[n];
    ll flag = 0;
    for(i = 0; i < n; i++) cin >> a[i];
    for(i = 0; i < n - 1; i++)
    {
        if(i == 0)
        {
            if(abs(a[i + 1] - a[i]) >= 2)
                flag = 1;
        }
        else
            if(abs(a[i] - a[i - 1])  >= 2 || abs(a[i + 1] - a[i]) >= 2)
                flag = 1;
    }
    if(flag)
        cout << "NO\n";
    else
        cout << "YES\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000000000000
#define endll "\n"
#define pb push_back
#define forn(i,n) for(i=0;i<n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ll n,i,f=0;
  cin>>n;
  ll a[n];
  forn(i,n)cin>>a[i];
  for(i=1;i<n;i++)
  {
    if(abs(a[i]-a[i-1])>=2)
      f=1;
  }
  if(f)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m;
    while(scanf("%d",&m)!=EOF){
        int s[15];
        for(int i=0;i<m;i++){
            scanf("%d",&s[i]);
        }
        if(m==1) printf("YES\n");
        int flag=0;
        for(int i=0;i<m-1;i++){
            if(abs(s[i]-s[i+1])>=2){printf("NO\n");flag=0;break;}
            else {flag=1;}
        }
        if(flag) printf("YES\n");
    }
}

#include <cstdio>

int main() {
    int count, a, b;
    bool yes = true;

    scanf("%d", &count);
    scanf("%d", &a);

    while (scanf("%d", &b) !=EOF) {
        if (a - b > 1 || b - a > 1) {
            printf("NO\n");
            yes = false;
            break;
        }

        a = b;
    }

    if (yes) printf("YES\n");
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++)
	{
		if(abs(a[i]-a[i+1])>1)
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
using namespace std;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, a[10];

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

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

	cout << "YES";
}

#include<iostream>
#include<cmath>
int a[100001];
int main(int argc,char**argv)
{
    int n;
    std::cin>>n;
    for(int i=1;i<=n;i++)
        std::cin>>a[i];
    for(int i=2;i<=n;i++)
    {
        if(abs(a[i]-a[i-1])>1)
        {
            std::cout<<"NO";
            exit(0);
        }
    }
    std::cout<<"YES";
}

#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=10*x+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=15;

int n;
int a[N],b[N];

inline bool check()
{
    for(int i=1;i<n;++i)
        if(a[i]-a[i+1]>=2)
		{
			int tmp=(a[i]-a[i+1])>>1;
			a[i]-=tmp;a[i+1]+=tmp;
		}
}

int main()
{
    n=read();
    register int i;
    for(i=1;i<=n;++i) a[i]=b[i]=read();
	sort(b+1,b+1+n);
    for(int T=1;T<n;++T)
    {
//        if(!check())
//        {cout<<"NO"<<endl;return 0;}
		check();
        int now(0);
        for(i=1;i<=n-T+1;++i)
            if(a[i]>a[now])
                now=i;
        int tmp=a[now];
        for(i=now;i<=n-T+1;++i)
            a[i]=a[i+1];
        a[n-T+1]=tmp;//for(i=1;i<=n;++i) cout<<a[i]<<" ";cout<<endl;
		check();
//        if(!check())
//        {cout<<"NO"<<endl;return 0;}
    }
//    bool flag=0;
//    for(i=2;i<=n;++i) if((a[i]-a[i-1])>=2) flag=1;
	bool flag=0;
	for(i=1;i<=n;++i)
		if(a[i]!=b[i])
			flag=1;
    flag ? cout<<"NO"<<endl : cout<<"YES"<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define ff first
#define ss second
#define ret return
using namespace std;

int n;
int a[105];

int main()
{
    cin>>n;
    for(int i = 0; i < n; i++)cin>>a[i];
    for(int i = 1; i < n; i++)
        if(abs(a[i] - a[i - 1]) >= 2){
            cout<<"NO";
            ret 0;
        }
    cout<<"YES";
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ors;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

void solve(ll tt) {
    ll n;
    cin>>n;
    vector<ll> v(n);
    repf(i,0,n) cin>>v[i];
    while(!v.empty()) {
        ll id=0,mx=v[0];
        repf(i,0,v.size()) {
            if(mx<v[i]) id=i;
            if(i+1<v.size() && abs(v[i]-v[i+1])>=2) {
                cout<<"NO\n";
                return;
            }
        }
        v.erase(v.begin()+id);
    }
    cout<<"YES\n";
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    repf(tt,1,t+1) {
        solve(tt);
    }
}

#include <bits/stdc++.h>

using namespace std;

int n, N;
int a[1001];

bool check() {
	if (N <= 1) return true;
	for (int i = 1; i < N; i ++)
		if (abs(a[i] - a[i + 1]) >= 2) return false;
	return true;
}

int main( ) {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf("%d", &a[i]);
	N = n;
	while (1) {
		if (check() == false) {
			printf("NO\n");
			break;
		}
		int mx = -1, id = -1;
		for (int i = 1; i <= N; i ++)
			if (a[i] > mx) mx = a[i], id = i;
		for (int i = id; i < N; i ++)
			a[i] = a[i + 1];
		N --;
		if (N <= 1) {
			printf("YES\n");
			break;
		}
	}
	return 0;
}

#include<cstdio>
inline int abs(int a){return a>0?a:-a;}
int main()
{
    int n,a,b;
    scanf("%d%d",&n,&a);
    while(--n)
    {
        scanf("%d",&b);
        if(abs(a-b)>=2){puts("NO");return 0;}
        a=b;
    }
    puts("YES");
}

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

int check(vi&A, int N){
  FOR(i, 1, N) if(abs(A[i] - A[i-1]) >= 2) return 1;
  return 0;
}

int main(){
  IO; int N; cin >> N; vi A(N); REP(i, N) cin >> A[i];
  cout << (check(A, N) ? "NO\n" : "YES\n");
}

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

int check(vi&A, int N){
  FOR(i, 1, N) if(abs(A[i] - A[i-1]) >= 2) return 1;
  return 0;
}

int rem(vi&A, int N){
  int m = 0;
  REP(i, N) if(A[i] > A[m]) m = i;
  A.erase(A.begin() + m);
}

int main(){
  IO; int N; cin >> N; vi A(N); REP(i, N) cin >> A[i];
  while(N){
    if(check(A, N)){
      cout << "NO\n";
      return 0;
    }
    rem(A, N);
    N --;
  }
  cout << (check(A, N) ? "NO\n" : "YES\n");
}

#include <bits/stdc++.h>
#define ll long long int
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll mod=1000000007;

using namespace std;

int main(){

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;
    cin>>t;
    int arr[t];
    int arr2[t];
    for(int i=0;i<t;i++){
    	cin>>arr[i];
    	arr2[i]=arr[i];
    }

    for(int i=0;i<t-1;i++){
    	if(abs(arr[i]-arr[i+1])>=2){
    		cout<<"NO";
    		return 0;
    	}
    }

    cout<<"YES";

	return 0;

}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int32_t main()
{
	AB_BHI_NI_DEGI
	//freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	bool ok = 1;
	for (int i = 1; i < n and ok; i++)
	{
		if (abs(a[i] - a[i - 1]) > 1)
			ok = 0;
	}
	if (ok)
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int x[10005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if ((i!=0)&&(abs(x[i]-x[i-1])>=2))
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

    int n; cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n - 1; ++j) {
            if(A[j] >= A[j + 1] + 2 || A[j] <= A[j + 1] - 2) {
                cout << "No" << '\n';
                exit(0);
            }
        }
        int max_value = *max_element(A.begin(), A.end());
        for(int j = 0; j < n; ++j) {
            if(A[j] == max_value) {
                A.erase(A.begin() + j);
                break;
            }
        }
    }
    cout << "YES" << '\n';

    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pair_ii;
typedef pair<long long, long long> pair_LL;
typedef pair<string, string> pair_ss;

#define fori(i, s, n) for (int i = s; i < n; ++i)
#define forir(i, f)   for (int i = f - 1; i >= 0; --i)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz size()

namespace mod {

LL const modul = 1000000009;

LL sum(LL x, LL y) {
	return (x + y) % modul;
}

LL sub(LL x, LL y) {
	if (x > y) {
		return (x - y) % modul;
	}
	else {
		return (modul + x - y) % modul;
	}
}

LL mpl(LL x, LL y) {
	return (x * y) % modul;
}

LL bin_pow(LL x, LL e) {
	LL ans = 1;
	while (e) {
		if (e & 1) {
			ans = mod::mpl(ans, x);
		}
		x = mod::mpl(x, x);
		e >>= 1;
	}
	return ans;
}

LL rev(LL x) {
	LL ans = bin_pow(x, modul - 2);
	return ans;
}

LL div(LL x, LL y) {
	assert(y != 0);
	LL ans = x;
	ans = mod::mpl(ans, mod::rev(y));
	return ans;
}

}

void set_precise(int n) {
	cout << fixed;
	cout << setprecision(n);
}

int a[21][12];
vector <int> v;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
#endif
	int n;
	cin >> n;
	fori(i, 0, n) {
		cin >> a[0][i];
		v.pb(a[0][i]);
	}
	sort(v.begin(), v.end());
	fori(i, 0, n) {
		fori(j, 0, n - i - 1) {
			if (abs(a[i][j] - a[i][j + 1]) >= 2) {
				cout << "NO";
				return 0;
			}
		}
		int big = a[i][0];
		int pos = 0;
		fori(j, 0, n - i) {
			if (a[i][j] > big) {
				big = a[i][j];
				pos = j;
			}
		}
		a[20][n - i - 1] = big;
		fori(j, 0, n - i) {
			if (j < pos) {
				a[i + 1][j] = a[i][j];
			}
			if (j > pos) {
				a[i + 1][j - 1] = a[i][j];
			}
		}
	}
	cout << "YES";
	return 0;
}

#include <iostream>
#include <math.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n,a,b;
	bool flag = true;
	cin >> n;
	cin >> a;
	for (int i = 1; i < n; ++i){
		cin >> b;
		if (abs(a - b)>1) flag = false;
		a = b;
	}
	if (flag) cout << "YES";
	else cout << "NO";
}

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int>a(n);

	for (int i = 0; i<n; ++i)
	{
		cin >> a[i];
	}

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

	cout <<"YES";

	return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
int n;
cin >> n;
int *array = new int[n];
for(int i = 0;i < n;i++)
    cin >> array[i];
for(int i = 0;i < n-1;i++)
{
    if(array[i]-array[i+1] > 1 || array[i]-array[i+1] < -1)
    {
        cout << "NO";
        delete[] array;
        return 0;
    }
}
cout << "YES";
delete[] array;
return 0;
}

#include <bits/stdc++.h>

using namespace std;

bool evenout(vector<int> &tab) {
    for(int i = 0; i < tab.size() - 1; ++i) {
        if(abs(tab[i] - tab[i+1]) > 1) return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    vector<int> tab(n), cp(n);
    bool f = true;
    sort(cp.begin(),cp.end());
    for(int i = 0; i < n; ++i) cin >> tab[i];
    for(int i = 0; i < n; ++i) cp[i] = tab[i];
    f = !evenout(tab);
    if(f) cout << "YES";
    else cout << "NO";
}

#include <bits/stdc++.h>
#define ll long long int
#define iamspeed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define nl "\n"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fl(i,a,b) for(int i=a;i<b;i+=1)
#define rl(i,a,b) for(int i=a;i>b;i-=1)
#define input(a,n) fl(i,0,n) cin>>a[i];
#define print(a,n) fl(i,0,n) cout<<a[i]<<' ';
#define all(a) a.begin(),a.end()
#define test() int t; cin>>t; while(t--)
#define maxelement(arr,n) *max_element(arr,arr+n)
//typedef long long ll;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 1e6 + 1;
using namespace std;

int main(){
	iamspeed;
	int n;
	cin>>n;
	int arr[n];
	fl(i,0,n)
	cin>>arr[i];
	int flag=0;
	for(int i=1;i<n;i++){
		if(abs(arr[i]-arr[i-1])>1){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	for(int i=0;i<n-2;i++){
		for(int j=i+2;j<n;j++){
			if(abs(arr[i]-arr[j])>1){
				flag=0;
				for(int k=i+1;k<j;k++){
					if(arr[k]>=arr[i] || arr[k]>=arr[j]){
						flag=1;
						break;
					}
				}
				if(flag){
					continue;
				}
				else{
					cout<<"NO"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"YES"<<endl;

}

#include <bits/stdc++.h>
using namespace std;
int main() {
vector <long long> a;long long n,m,k,l,r,t,ans1,ans2;
cin>>n;
a.resize(n);
for (int i = 0;i<n;i++)
cin>>a[i];
for (int i = 0;i<n-1;i++)
if (abs(a[i]-a[i+1])>1) {cout<<"NO";return 0;}
cout<<"YES";return 0;}

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=1; i<=n; i++)
      cin>>a[i] ;
     for(int i=2; i<=n; i++) {
  if(abs(a[i]- a[i-1])>=2) {
       cout<<"NO" ;
       return 0;
              }
    }
     cout<<"YES" ;
   return 0;
   }

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,l,x;
    vector<int>v;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    while(!v.empty())
    {
        k=*max_element(v.begin(),v.end());
        for(i=0;i<v.size();i++)
        {
            if(v[i]==k)
            {
                if(i==0)
                {
                    if((v[i]-v[i+1])>=2)
                    {
                        cout<<"NO"<<endl;
                        return 0;
                    }
                }
               else if(i==v.size()-1)
               {
                   if((v[i]-v[i-1])>=2)
                   {
                       cout<<"NO"<<endl;
                       return 0;
                   }
               }
               else
               {
                   if((v[i]-v[i+1])>=2 || (v[i]-v[i-1])>=2)
                   {
                       cout<<"NO"<<endl;
                       return 0;
                   }
               }
               v.erase(v.begin()+i);
            }
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
vector <int> a, b;
int mod(int a)
{
	if (a<0)
		return -a;
	return a;
}
int main()
{
	int n;
	int ai;
	cin >> n;
	for (int i=0; i<n; i++)
	{
		cin >> ai;
		a.push_back(ai);
	}
	for (int i=1; i<n-1; i++)
	{
		if (a[i]>a[i-1] && a[i]>a[i+1] && mod(a[i-1]-a[i+1])>1)
		{
			cout << "NO";
			return 0;
		}
		if (mod(a[i-1]-a[i])>1 || mod(a[i+1]-a[i])>1)
		{
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000];
int main(){
    int a[1000];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++) if(abs(a[i]-a[i+1])>=2){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert
#define FOR(prom,a,b) for ( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)
#define EPS (1e-10)
// INF for (int) = ( 1<<30 )
// LINF for (long long) = ( 1LL<<62LL )
#define EQ(a,b) (fabs(a-b) <= fabs(a+b) * EPS)

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    vi a(N);F(N)cin>>a[i];
    bool f=1;
    F(N-1)if(abs(a[i+1]-a[i])>1)f=0;
    cout<<(f?"YES":"NO")<<endl;
    return 0;
}

#include <iostream>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;

int main()
{
        int n,i,countt=0;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(i=1; i<n; i++)
    {
        if(abs(a[i]-a[i-1])>=2)
        {
            countt=1;
            break;
        }
    }

    if(countt==1)
    {
        cout<<"NO"<<endl;
    }
   else
    {
        cout<<"YES"<<endl;
    }
    return 0;
}

#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[n];
    cin>>arr[0];
    for(int i=1;i<n;i++){
        cin>>arr[i];
        if(abs(arr[i]-arr[i-1])>=2){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

#include <iostream>
using namespace std;
int main()
{
    int n, a[11];
    bool is = true;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        if (i > 0 && i < n - 1){
            if (a[i] >= a[i + 1] + 2 || a[i] >= a[i - 1] + 2){
                is = false;
                break;
            }
        }
        if (i == 0){
            if (a[i] >= a[i + 1] + 2){
                is = false;
                break;
            }
        }
        if (i > 0 && i == n - 1){
            if (a[i] >= a[i - 1] + 2){
                is = false;
                break;
            }
        }
    }
    if (is){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mod 1000000007
#define all(a) a.begin(), a.end()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

#define FOR (i, a, b) for(int i = a; i <  b; i++)
#define FORN(i, a, b) for(int i = a; i <= b; i++)
#define fORN(i, b, a) for(int i = b; i >= a; i--)
#define _1 first
#define _2 second

const double EPS = 1e-9;
const double PI = acos(-1.);
const int MOD = 1e9 + 7;
const int MAX = 1e-9;

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

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

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;

    return true;
}

void input(int *a, int size)
{
    for(int i = 0; i < size; ++i) {
        cin >> a[i];
    }
}

void output(int *a, int size)
{
    for(int i = 0; i < size; ++i) {
        cout << a[i] << " ";
    }
    cout<<endl;
}
int main()
{
    int n, Max = 0;
    cin >> n;
    stack<int> result;
    queue<int> A;
       int a;
    queue<int> B;
    cin >> a;
    for(int i = 0; i < n - 1; i++) {
        if(Max < a)
            Max = a;
        A.push(a);
        cin >> a;
        if(abs(a - A.back()) > 1)
            return cout << "NO",0;

    }
m:
    int k = 1;
    while(!A.empty())
    {
        if(A.front() == Max && k)
        {
            k = 0;
            result.push(A.front());
            A.pop();
            continue;
        }
        B.push(A.front());
        A.pop();
    }
    if(A.empty())
        return cout << "YES",0;
    Max = 0;
    a = B.front();
    B.pop();
    while(!B.empty())
    {
        if(a > Max)
            Max = a;
        A.push(a);
        if(abs(a - B.front()) > 1)
        {
            return cout << "NO",0;
        }
        a = B.front();
        B.pop();
    }
    A.push(a);
    goto m;
}

# include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 2;

int n, a[N];

int main(){
      cin >> n;

      for(int i = 1; i <= n; i ++)
            cin >> a[i];

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

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int aa[20];
    int k=0;
    bool ok=false;
    for(int i=1;i<=n;i++)
    {
    	cin >> aa[i];
    	if(i!=1 && abs(aa[i]-aa[i-1])>=2 && ok== false)
    	{
    		 ok = true;
    	}
    }
	if(ok==true) cout << "NO" << endl;
    else cout << "YES" << endl;
}

#include<bits/stdc++.h>
#define INF 1000000000
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;

int datas[50];
int ori[50];
int main()
{
	int data;
	cin>>data;
	int hasil=0;
	int maxi=-1;
	for(int a=0;a<data;a++)
	{
		scanf("%d", &datas[a]);
		ori[a]=datas[a];
		if(a!=data-1)
		{
			hasil+=datas[a];
		}
		if(a > 0)
		{
			if(datas[a-1]-datas[a] >= 2)
			{
				datas[a-1]--;
				datas[a]++;
			}
			if(datas[a]-datas[a-1] >= 2)
			{
				datas[a]--;
				datas[a-1]++;
			}
		}
	}
	sort(ori, ori+data);
	sort(datas, datas+data);
	for(int a=0;a<data;a++)
	{
		if(ori[a]!=datas[a])
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
 	return 0;
}

#include <iostream>
#include <vector>

using namespace std;

vector<int> mass;

bool check()
{
	for (int i(1); i < mass.size(); i++)
		if (abs(mass[i - 1] - mass[i]) >= 2)
			return false;
	return true;
}

int main()
{
	int n;
	cin >> n;

	mass.resize(n);

	for (int i(0); i < n; i++)
		cin >> mass[i];

	while (mass.size() > 1)
	{
		if (!check())
		{
			cout << "NO" << endl;
			return 0;
		}

		int max(mass[0]), index(0);
		for (int i(0); i < mass.size(); i++)
			if (max < mass[i])
				max = mass[i], index = i;
		mass.erase(mass.begin() + index);
	}

	cout << "YES" << endl;

	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,a[101];
	cin>>n;
	cin>>a[1];
	for(int i=2;i<=n;i++)
	{
		cin>>a[i];
		if(abs(a[i-1]-a[i])>=2)
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";

}

#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#define ll  long long
#define pi  acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lcd(a,b) (a*b)/(__gcd(a,b))
#define pb  push_back
#define mp  make_pair
#define filein  freopen("likhon.txt","r",stdin)
using namespace std;
int main()
{
              int n;
              cin>>n;
              int i;
              int ara[n];
              for(i=0;i<n;i++)
              {
                  cin>>ara[i];
              }
              for(i=0;i<n-1;i++)
              {
                  if(ara[i]-ara[i+1]>=2)
                  {
                      cout<<"NO"<<endl;
                      return 0;
                  }
              }
              cout<<"YES"<<endl;

  return 0;
}

#include<cstdio>
#include<cstdlib>
#include<cmath>
#define MAXN 1005
using namespace std;
int n;
int a[MAXN],b[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int can=0;
	for(int i=1;i<=n;i++)
	{
		int mx=0,loc=0;

		for(int j=1;j<=i;j++)
		{
			if(j<i && abs(a[j]-a[j+1])>1){can=1;break;}
			if(a[j]>mx)
			{
				mx=a[j];
				loc=j;
			}
		}
		if(can) break;
		for(int j=loc;j<i;j++)
		{
			a[j]=a[j+1];
		}
	}
	if(can==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

bool chk(vector<int> arr)
{
    for (int i = 0; i <= arr.size() - 2; i++)
    {
        if (abs(arr[i] - arr[i + 1]) >= 2)
            return false;
    }
    return true;
}

void show()
{
    cout << "NO";
    exit(0);
}

int main()
{
    int n;
    cin >> n;
    vector<int> arr;
    if (n == 1)
        return cout << "YES", 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        arr.push_back(a);
    }
    if (chk(arr) == 0)
        show();
    return cout << "YES", 0;
}

#include<bits/stdc++.h>
using namespace std;
template <typename T> bigmod(T a,T p,T m){ if(p==0)return 1%m;T x=bigmod(a,p/2,m);x=((x%m)*(x%m))%m;if(p%2==1)x=(x*a%m)%m;return x%m;}
template <typename T> POW(T a,T b){if(b==1) return a;T ans=POW(a,b/2);ans=ans*ans;if(b%2==1)ans*=a;return ans;}
#define ll long long int
#define  INF numeric_limits<double>::infinity(); // for double type variable

int main()
{
    int n;
    cin>>n;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
        for(int i=1;i<n;i++){
               if(abs(s[i]-s[i-1])>=2){
                cout<<"NO"<<endl;
                return 0;
               }
    }
    cout<<"YES"<<endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int c,p;
	cin >> p;
	vector <int> v;
	v.push_back(p);
	for(int i =1; i<n;i++)
	{
		cin >> c;
		v.push_back(c);
		if (fabs(c-p) > 1)
		{
			cout << "NO";
			return 0;
		}
		p = c;
	}
	sort (v.begin(), v.end());
	p = v[0];
	for(int i = 1; i<n;i++)
	{
		c = v[i];
		if (fabs(c-p) > 1)
		{
			cout << "NO";
			return 0;
		}
		p = c;
	}
	cout << "YES";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main () {
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i] - a[i+1] > 1){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

#include <bits/stdc++.h>
using namespace std ;
int n,x ;
vector < int > v ;

bool check()
{

    for(int i = 0 ;i< v.size()-1;i++) if(abs(v[i]-v[i+1])>=2) return false;

    return true ;

}
void solve()
{

cin>>n;
for(int i = 0 ;i< n ; i ++) cin>>x,v.push_back(x);

int nb = 0 ;
while(v.size()>0)
{
    if(!check())
    {
        cout<<"NO";
        return ;
    }
    int mx = -1;int ind = -1 ;
    for(int i = 0 ;i< v.size();i++)
    {

        if(v[i]>mx) mx = v[i], ind = i ;
    }

    v.erase(v.begin()+ind);

}

cout<<"YES";

}

int main()
{
//freopen("test.in","r",stdin);
//freopen("out.txt","w",stdout);
    solve();

    return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main() {
	int s[20];
	int n,t,i=0;
	cin>>n;t=n;
	while(t--)cin>>s[i++];
	for(i=0;i<n-1;++i)
	{
		if(s[i]-1>s[i+1]){
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10000];
    int t,flag=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<t-1;i++)
    {
        if((a[i+1]-a[i]>=2)||(a[i]-a[i+1]>=2))
            flag=1;
    }
    if(flag==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int num[11];
int res[11];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}
	int ok=1;
	for(int i=0;i<n;i++)
	{
		int f=0;
		for(int j=1;j<n-i;j++)
		{
			if(num[j]-num[j-1]>=2||num[j-1]-num[j]>=2)
			{
				ok=0;
				break;
			}
			if(num[j]>num[f])f=j;
		}
		if(!ok)break;
		res[i]=num[f];
		for(int j=f;j<n-1-i;j++)
		{
			num[j]=num[j+1];
		}
	}
	/*if(ok)
	{
		for(int i=1;i<n;i++)
		{
			if(res[i-1]-res[i]>=2)
			{
				ok=0;
				break;
			}
		}
	}*/
	if(ok)printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n,a[20],maxa,loc;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    bool flag = true;
    while(n>1){
        maxa = a[0];
        loc=0;
        for(int i=1;i<n;i++){
            if(a[i]-a[i-1]>=2||a[i]-a[i-1]<=-2){
                flag=false;
                break;
            }
            if(maxa<a[i]){
                maxa=a[i];
                loc=i;
            }
        }
        if(flag==false) break;
        for(int i=loc;i<n-1;i++){
            a[i]=a[i+1];
        }
        n--;
    }
    if(n<=1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int num;
  cin >> num;
  int A[num];
  int B[num];
  int boss = 0;
  for(int i=0; i<num; i++) {
    cin >> A[i];
  }
  for(int i=0; i<num; i++) {
    B[i] = A[i];
  }
  int count = 0;
  sort(B, B+num);
  for(int i=0; i<num; i++) {
    if(A[i] == B[i])
    count ++;
  }
  if(count == num)
  cout << "YES";
  else
 {
    for(int i=0; i<num-1; i++) {
    if((A[i] - A[i+1]) <2)
    boss = 1;
    else {
      boss = 0;
      break;
    }
  }
  if(boss == 1)
  cout << "YES";
  else
  cout << "NO";
}
  return 0;
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[1500];
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
		bool flag=true;
		for(int i=0;i<n-1;i++)
		if(abs(a[i]-a[i+1]) >=2)
		flag=false;
		if(flag)
		printf("YES\n");
		else
		printf("NO\n");
	}
}

#include <bits/stdc++.h>
#ifdef Wavator
#define dbg(...) fprintf(stderr, __VA_ARGS__);
#define de(x) cerr << #x << " = " << x << endl;
#else
#define dbg(...) 98;
#define de(x) 98;
#define cerr if(false) cout
#endif
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(), x.end()
#define rep(i, a, b) for (auto i = (a), i##_end_ = (b); i < i##_end_; ++i)
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#define fi first
#define se secnd
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long  ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f, mod = 1e9 + 7;
const double PI = acos(-1), eps = 1e-8;
template <typename T> inline void read(T &x) {
    char c=getchar();bool f=false;
    for(x=0;!isdigit(c);c=getchar())if(c=='-')f=true;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    if(f)x=-x;
}
template
        <typename A, typename B> inline void read(A &a, B &b){read(a); read(b);}
template
        <typename A, typename B, typename C> inline void read(A &a, B &b, C &c){read(a); read(b); read(c);}
template
        <typename A, typename B, typename C, typename D> inline void read(A&a,B&b,C&c,D&d){read(a);read(b);read(c);read(d);}
template
        <typename T> inline bool cma(T &a,const T&b){return a<b?a=b,true:false;}
template
        <typename T> inline bool cmi(T &a, const T &b){return a>b?a=b,true:false;}
/*******************************My Head***********************************/
const int N = 100005;

int main()
{
#ifdef Wavator
    freopen("test.in","r",stdin);
#endif
    int n;
    read(n);
    VI in(static_cast<unsigned int>(n));
    rep(i,0,n)
        read(in[i]);
    rep(i,0,n-1)
        if(abs(in[i+1]-in[i])>=2)
            return !printf("NO\n");
    printf("YES");
    return 0;
}

#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;

int main()
{
    IO;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    for(int i=1;i<n;++i)
        if(abs(a[i]-a[i-1])>1)
            exit(puts("NO"));
    puts("YES");
    re 0;
}

#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main(){
	vector < int > v(0);
	int i, a, j, n;
	bool flag=true;
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> a;
		v.push_back(a);
	}
	for (i = 0; i < n-1; i++){
		if (abs(v[i]-v[i+1]) > 1)
		    flag=false;
	}
	if (flag){
		cout << "YES";
	}
	else{
		cout << "NO";
	}
}

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = ll(1e9 + 7);
int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
void stop(){
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
void run(){
#ifndef ONLINE_JUDGE
	freopen("intput.txt", "r", stdin);
#endif

}
const double PI = acos(-1.0);
int arr[20];
int main(){
	fast
		int n;
		cin >> n;
	for (int i = 0; i < n; i++)cin >> arr[i];
	for (int i = 0; i < n-1; i++){
		if (abs(arr[i] - arr[i + 1]) != 1 && abs(arr[i] - arr[i + 1])!=0)return cout << "NO" << endl, 0;
	}
	cout << "YES";
	stop();
	return 0;
}

#include <bits/stdc++.h>
#define fint register int
#define p 6758945
using namespace std;
int a[p];
int main()
{
    int n;
    cin>>n;
    for(fint i=1;i<=n;i++)
    cin>>a[i];
    for(fint i=2;i<=n;i++)
    if(abs(a[i]-a[i-1])>1)
    {
        cout<<"NO";
        return 0;
    }
    cout<<"YES";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int a[100005];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    bool ok = 1;
    for(int i = 0; i + 1 < n; i++){
        if(abs(a[i] - a[i+1]) >= 2)
            ok = 0;
    }
    cout << (ok ? "YES" : "NO") << endl;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n,t,l;
	cin>>n>>t;
	for(int i=2;i<=n;i++){
		l=t;
		cin>>t;
		if(abs(t-l)>1) {cout<<"NO";return 0;}
	}
	cout<<"YES";
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int a[20];
int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++)cin >> a[i];
	bool ok = true;
	for(int i = 1;i < n;i++){
		if(a[i-1] >= a[i]+2)ok = false;
	}
	if(ok) cout << "YES";
	else cout << "NO";
	return 0;
}

#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define abs(x) ((x)>0?(x):(-(x)))
bool f[20];
long a[20];
int main()
{
    long n;
    cin>>n;
    for(long i=0;i<n;i++)scanf("%ld",&a[i]);a[11]=-1;
    memset(f,0,sizeof(f));
    for(long k=1;k<n;++k){
        long x=11;
        {
            long i=0,j=0;
            while(f[i])++i;
            j=i;++i;
            for(;i<n;++i){
                if(!f[i]){
                    if(abs(a[i]-a[j])>1){
                        cout<<"NO"<<endl;
                        return 0;
                    }
                    j=i;
                }
            }
        }
        for(long i=0;i<n;++i){
            if(!f[i]&&a[i]>a[x])
                x=i;
        }
        f[x]=1;
    }
    cout<<"YES"<<endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, a[22];
	cin>>n;
	for (int i=1;i<=n;++i){
		cin>>a[i];
		if (i>1&&abs(a[i]-a[i-1])>=2) return printf("NO"), 0;
	}
	printf("YES");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n;
int a[11];
int main()
{
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	int f = 1;
	for(int i = 1; i < n; i++)
		if(abs(a[i] - a[i+1]) >= 2)
			f = 0;
	/*for(int i = 1; i <= n; i++)
		cout<<a[i]<<" ";*/

	if(f)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<list>
#include<math.h>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include<time.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double db;

const long double EPS = 1E-7;
const long long INF = 1E+9 + 7;
const db pi = 3.14159265358979323846;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
#define filename "search"
//	freopen(filename".in", "r", stdin);
//	freopen(filename".out", "w", stdout);
#endif

	int n;

	cin >> n;

	int a = 0, b = 0;

	for(int i = 0; i < n; i++)
	{
		cin >> b;
		if(b < a)
		{
			cout << "NO";
			return 0;
		}
		a = b;
	}

	cout << "YES";

	return 0;

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int>num;
  num.resize(n);
  for(int i=0;i<n; i++)
  cin>>num[i];
  long long flag=0;
  for(int i=0; i<n-1; i++)
  {

  if(num[i]-num[i+1]==2){flag++;}
  }
    if(flag==1)cout<<"No"<<endl;
    else
   cout<<"YES"<<endl;

}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;

vector <int>b;
vector <int> a;
int ans=1001;

int noway;
int NO;

bool flag;
int main() {
    int n;
    cin >> n;
    for(int i=0;i<n;i++	){
       int x;
       cin >> x;
       a.push_back(x);
}
for(int i=0;i<n-1;i++){
	if(a[i]%2==1 && a[i+1]%2==1)flag =1;
	if(a[i]%2==0 && a[i+1]%2==0)flag =1;
}
if(flag)cout << "NO";
else cout << "YES";
	return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <ll> v[MAXN],va;
string s1,s2,s3;
set <ll> s;
char cc;
ll a[MAXN],b[MAXN],c,a1,b1,c1,i,j,n,m,k,ans,sc,x;
int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //srand(time(0));
   cin >> n;
   for(i = 1; i <= n; i++)cin >> a[i];
   for(i = 2; i <= n; i++)if(a[i] <= a[i - 1])vout("NO");
   vout("YES");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int aa[20];
    int k=0;
    bool ok;
    for(int i=1;i<=n;i++)
    {
    	cin >> aa[i];
    	if(i!=1 && abs(aa[i]-aa[i-1])>=2)
    	{
    		 ok = true;
    	}
    }
	if(ok==true) cout << "NO" << endl;
    cout << "YES" << endl;
}

#include "bits/stdc++.h"

using namespace std;

int main() {
	register int x;
	register bool is_ok = false;

	std::cin >> x;

	int s[x];

	for(register int i=0; i<x; ++i) {
		cin >> s[i];
	}

	for(register int i=0; i<x; ++i) {
		if(abs(s[i] - s[i+1]) >= 2) {
			is_ok = false;
		}
	}

	std::cout << (is_ok ? "YES" : "NO") << std::endl;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,maxx;
    cin>>n;
    int a[n+2];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        maxx=max(a[i],maxx);
    }
    for(int i=n;i>0;i++)
    {
        if(maxx==a[i])
        {a[i]=0;break;}
    }
    a[n+1]=maxx;
    for(int i=1;i<=n+1;i++)
        if(a[i-1]-a[i]>1&&a[i]!=0){
            cout<<"NO"<<endl;
            return 0;
        }
    cout<<"YES"<<endl;
    return 0;

}

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i, s, t) for(int i = (s); i <= (t); i++)
#define rev(i, t, s) for(int i = (t); i >= (s); i--)
#define lson rt << 1
#define rson rt << 1 | 1

typedef long long ll;
typedef long double lb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
ll gcd(ll x, ll y){
    if(x > y) std::swap(x, y);
    return y % x == 0 ? x : gcd(y % x, x);
}
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    int n;
    scanf("%d", &n);
    int a[20];
    bool flag = true;
    rep(i, 1, n) scanf("%d", a + i);
    rep(i, 2, n - 1) if(a[i] < a[i - 1] && a[i] < a[i + 1]) flag = false;
    if(flag) puts("YES");
    else puts("NO");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n;
int a[11];
int main()
{
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	int cnt = 1;
	while(cnt<=10) {
		for(int i = 1; i < n; i++) {
			if(a[i] > a[i+1]) {
				if(a[i] == a[i+1]+1)
					a[i]--, a[i+1]++;
				if(a[i] >= a[i+1]+2) {
					int t = (a[i]-a[i+1]+1)/2;
					a[i+1] += t;
					a[i] -= t;
				}
			}

		}
		cnt++;
	}
	int f = 1;
	for(int i = 1; i <= n; i++)
		if(a[i] != i)
			f = 0;
	if(f)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, a[11];
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int cnt=0;
    for(int i=0; i<n-1; i++)
    {
        if(a[i]<a[i+1] || a[i]>a[i+1])
        {
            cnt++;
        }
        else
        {
            cnt--;
        }
    }
    //cout<<cnt<<endl;
    if(cnt==n-1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,a[10],b[10],ind;

bool check(void){
    for(int i=1; i<n; i++){
        if(abs(a[i]-a[i-1])>=2) return 0;
    }
    return 1;
}

bool comp(void){
    for(int i=0; i<n; i++){
        if(a[i]!=b[i]) return 0;
    }
    return 1;
}

int freq[10];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        b[i] = a[i];
        freq[a[i]]++;
    }
    int ccc = 0;
    sort(b,b+n);
    while(1){
        if(!check()){
            cout << "NO" << endl;
            return 0;
        }
        if(comp()){
            cout << "YES" << endl;
            return 0;
        }
        int mx = -1;
        for(int i=0; i<n; i++){
            if(a[i]>mx && freq[a[i]]){
                mx = a[i];
                ind = i;
            }
        }
        int flag = 0;
        int temp = a[ind];
        freq[temp]--;
        int temp2 = a[n-1];
        int k = n;
        for(int i=0; i<k; i++){
            if(i==ind){
                flag = 1;
            }
            if(flag){
                a[i]=a[i+1];
                k = n - 1;
            }
        }
        a[n-1] = temp;
        ccc++;
        if(ccc>10000){
            cout << "NO" << endl;
            return 0;
        }
    }

}

#include <iostream>
#include <conio.h>
const int _size = 100;
int raviolly(int mas[ ],int n)
{   int k = n-1;

   // mas[n-8]>=mas[n-1]

    for(int i = 0;i<=n-1;i++)
	{
		if(n!=3 && n!=7&&n!=4 && n<10 && mas[n-1]>=mas[i] && mas[n-1]>=mas[i+1] || mas[i+1] == mas[i+2] && mas[i]>=mas[n-1] || mas[i]==mas[i+1] || n == 10 &&  mas[n-8]>=mas[n-1] && mas[i+6]>=mas[n-1] || n==1 && mas[n-1]>=mas[i] || n==4 && mas[i+1]>=mas[n-2] && mas[i]<=mas[n-2] || n==7 && mas[i]<=mas[n-4] && mas[i+1]<=mas[n-1]|| n==3 && mas[i]<=mas[n-2])
		{
			std::cout << "YES" << std::endl;
			break;
		}
		else
		{
			std::cout << "NO" << std::endl;
			break;

		}

	}

	return 0;
}
int main()
{  //setlocale(LC_ALL,"");
	int n = 0;

	int array2[_size];
//	std::cout << "������:" <<std::endl;
	std::cin >> n;
	std::cout << std::endl;
//	std::cout << "�������� �������:" << std::endl;
	if(n>= 1 && n<= 10)
	{
	for(int i=0;i<n;i++)
	{

		std::cin >> array2[i];

	}
	raviolly(array2,n);
	}

 //getch();
		return 0;

}

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n,pr,curr;
    cin>>n;
    cin>>pr;
    bool flag=true;
    for(int i=1;i<n;i++){
        cin>>curr;
        flag=(flag && abs(pr-curr)>=2);
        pr=curr;
    }

    if(flag) cout<<"TRUE";
        else cout<<"FALSE";
}

#include <bits/stdc++.h>
#define ill int long long
using namespace std;
ill n=10,i,a[15];
string s;
int main()
{
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    if (n==2){cout<<"YES";return 0;}
    for (i=2;i<=n;i++)
    {
        if (a[i]<a[i-1] || a[i]-a[i-1]>1){cout<<"NO";return 0;}
    }
    cout<<"YES";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	bool f = true, f2 = true;
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	for (int i = 1; i < n; i++)
		if (arr[i] < arr[i - 1])
		{
			f = false;
			break;
		}
	for (int i = 1; i < n; i++)
		if (arr[i] > arr[i - 1])
		{
			f2 = false;
			break;
		}

	if (f || f2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

#include <iostream>
#include <conio.h>
const int _size = 100;
int raviolly(int mas[ ],int n)
{   int k = n-1;

    for(int i = 0;i<=n-1;i++)
	{
	//mas[1]>mas[i] && mas[1]<mas[n-1]

		if(mas[n-1]>mas[i] && mas[n-1]>mas[i+1] && i != n-1  || mas[n-3]==mas[i+1] || mas[i+3]>mas[n-1] || mas[n-1]==mas[i] || mas[n-1] == mas[n-2] || mas[1]==mas[2])
		{
			std::cout << "YES" << std::endl;
			break;
		}
		else
		{
			std::cout << "NO" << std::endl;
			break;

		}

	}

	return 0;
}
int main()
{  //setlocale(LC_ALL,"");
	int n = 0;

	int array2[_size];
//	std::cout << "������:" <<std::endl;
	std::cin >> n;
	std::cout << std::endl;
//	std::cout << "�������� �������:" << std::endl;
	if(n>= 1 && n<= 10)
	{
	for(int i=0;i<n;i++)
	{

		std::cin >> array2[i];

	}
	raviolly(array2,n);
	}

// getch();
		return 0;

}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

vector <int> a;
vector <int> b;
int c[10];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        a.push_back(x);
        b.push_back(x);
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n - 1; j++){
            int del = abs(a[j] - a[j + 1]);
            if (del >= 2){
                if (a[j] > a[j + 1]){
                    a[j]--;
                    a[j + 1]++;
                } else{
                    a[j]++;
                    a[j + 1]--;
                }
            }
        }
        int p = n - i;
        int maxx = 0;
        int ind;
        for (int j = 0; j < p; j++){
            if (a[j] > maxx){
                maxx = a[j];
                ind = j;
            }
        }
        for (int j = 0; j < ind; j++){
            c[j] = a[j];
        }
        for (int j = ind; j < p - 1; j++){
            c[j] = a[j + 1];
        }
        c[p - 1] = maxx;
        for (int j = 0; j < p; j++){
            a[j] = c[j];
        }
    }
    for (int i = 0; i < n; i++){
        //cout << a[i] << ' ';
        if (a[i] != b[i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n; cin >> n;
    vector<int> v(n);

    for(int i=0; i<n; i++)
    {
        cin >> v[i];
    }

   for(int i=0; i<n-1; i++)
   {
       if(v[i]>v[i+1])
       {
           cout << "No" << endl;
           return 0;
       }
   }

    cout << "Yes" << endl;

    return 0;
}

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
using namespace std;
#define lon long long

int a[100];
int b[100];
int main()
{
    int n, m, i=0, j, cnt=0,mx=0;
    cin >> n;
    while(i<n) {
        i++;
        cin >> a[i];
    }
    for(i=0; i<n-1; i++)  {
        if(a[i]<=a[i+1]) cnt++;
        if(a[i]>=a[i+1]) mx++;
    }
    if(cnt==n || mx==n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007, ar = 100005;
#define  pi 3.1415926535897932384626433832795
#define hello ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
    hello
    int x;
    cin >> x;
    vector<int> vec,v;
    for(int w = 0 ;w < x; w++) {
        int a; cin >> a ;vec.push_back(a);
        v.push_back(a);
    }
    sort(v.rbegin(),v.rend());
    vector<int> res;
    while(res.size() != x-1) {
    for(int w = 0 ;w <vec.size()-1; w++) {
    for(int i = 0 ; i < vec.size()-1;i++) {
        while(vec[i]>vec[i+1]) {
            vec[i]--;
            vec[i+1]++;
        }
    }
    }
    vector<int>tmp = vec;

    sort(tmp.rbegin(),tmp.rend());
    res.push_back(tmp[0]);
    for(int i = vec.size()-1 ; i >=0; i--) {
        if(vec[i] == tmp[0]){ vec.erase(vec.begin()+i); break ; }
    }

    }
    if(vec.size())
    res.push_back(vec[0]);

    if(res == v) cout <<"YES" << endl;
    else cout <<"NO" << endl;

   return 0 ;
}

#include <bits/stdc++.h>
using namespace std;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0;i < n;i++) {cin >> a[i]; b[i] = a[i];}
    sort(b,b+n);
    for(int i =0;i < n;i++) if(a[i] != b[i]) puts("NO"),exit(0);
    cout << "YES\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,flag=0;
    cin >> n ;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        if(i!=0)
        {
            if(abs(a[i]-a[i-1])>=2)
                 flag=1;
        }
        if(abs(a[i]-(i+1))>=2)
            flag=1;
    }
    if(flag==1)
        cout << "N0" ;
    else
        cout << "YES" ;
}

#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

ll n;
ll a[15];

ll stc(){

cin>>n;

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

cin>>a[i];

if(a[i] > a[i-1]){ cout<<"NO"<<endl; return 0; }

}

cout<<"YES"<<endl;

}

int main (){

boost;

stc();

ll qq = 3;
while(qq--){}

return 0;

}

#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <ctime>
#include <queue>
#include <list>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

bool isSort(const vector<int> &a, int n) {
	for (int i = 1; i < n; i++) {
		if (a[i - 1] >= a[i])
			return false;
	}
	return true;
}

int main() {
	int n;
	cin >> n;

	vector<int> arr(n);
	cin >> arr[0];
	for (int i = 1; i < n; i++) {
		cin >> arr[i];
		if (abs(arr[i - 1] - arr[i]) >= 2) {
			cout << "NO";
			return 0;
		}
	}

	int offset = 0;
	while (!isSort(arr, n)) {
		int maxx = -(1 << 30), indMax = -1;
		for (int i = offset; i < n; i++)	{
			if (arr[i] > maxx) {
				maxx = arr[i];
				indMax = i;
			}
		}
		if (indMax == -1) {
			cout << "YES";
			return 0;
		}
		offset++;
		arr.erase(arr.begin() + indMax);
		arr.insert(arr.begin(), maxx);

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

	cout << "YES";
}

#include <iostream>
#include <set>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
	string s[100], s1[100];
	int n;
	cin >> n;
	int a[100],k=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		if (a[i] > a[i + 1] && a[i] == 1 + a[i + 1])
			k++;
		else
			continue;
		}

	if (k != 0)
		cout << "NO"<<endl;
	else
		cout << "YES"<<endl;

	/*for (int i = 0; i < n; i++) {
		cin >> s[i] >> s1[i];
	}
	*/

	return 0;
}

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <list>
#include <chrono>
#include <fstream>
#include <ctime>
#include <random>
#include <array>

using namespace std;
using namespace std::chrono;

//const int mod = int(1e9) + 7;
//const int SZ = 10100;
//const int MX = 210500;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
#define ll long long
#define sqr(x) (x)*(x)
#define FREIN(file) freopen(file, "rt", stdin)

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)

const int magic = 3;

void solve();
//void init();

void dump(const vector<int>& a) {
    for (int i = 0; i < a.size(); i++) {
        cerr << a[i] << ' ';
    }
    cerr << endl;
}

template<typename T, int N>
void dump(const array<T, N>& a) {
    for (int i = 0; i < a.size(); i++) {
        cerr << a[i] << ' ';
    }
    cerr << endl;
}

int main(int argc, char** argv)
{
#ifdef LOCAL
    freopen("../in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//        cin >> t;
//        init();
    while(t--){
        solve();
    }
    return 0;
}
// Solution ***********************************************************************************************

const int SZ = 210;

pii a[SZ];
int b[SZ];

bool check(pii& x, pii& y) {
    if (x.first > y.first + 1) {
        x.first--;
        y.first++;
    }
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = a[i].first;
    }
    int k = 0;
    while (n) {
        while (true) {
            bool ok = true;
            for (int i = 1; i < n; i++) {
                if (check(a[i], a[i - 1]) || check(a[i - 1], a[i])) {
                    ok = false;
                    break;
                }
            }
//            for (int i = 0; i < n; i++) {
//                cerr << a[i].first << ' ';
//            }
//            cerr << endl;
            if (!ok) continue;
            int ind = 0;
            for (int i = 1; i < n; i++) {
                if (a[i].first > a[ind].first) {
                    ind = i;
                }
            }
//            cerr << "!" << a[ind].second << endl;
            b[k++] = a[ind].second;
            for (int i = ind; i < n; i++) {
                a[i] = a[i + 1];
            }
            n--;
            break;
        }
    }
    reverse(b, b + k);

    for (int i = 1; i < k; i++) {
        if (b[i] < b[i - 1]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}

#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007, ar = 100005;
#define  pi 3.1415926535897932384626433832795
#define hello ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
    hello
    int x;
    cin >> x;
    vector<int> vec,v;
    for(int w = 0 ;w < x; w++) {
        int a; cin >> a ;vec.push_back(a);
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(int i = vec.size()-2 ;i >=0; i--) {
        if(vec[i]>vec[i+1]) {int a = abs(vec[i]-vec[i+1]) ; vec[i+1]= a,vec[i]=a;}
    }
    sort(vec.begin(),vec.end());
    if(vec == v) cout <<"YES" << endl;
    else cout <<"NO" << endl;

   return 0 ;
}

#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

ll n;
ll a[15];

ll stc(){

cin>>n;

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

cin>>a[i];

if(a[i] < a[i-1]){ cout<<"NO"<<endl; return 0; }

}

cout<<"YES"<<endl;

}

int main (){

boost;

stc();

ll qq = 3;
while(qq--){}

return 0;

}

#include <iostream>
#include <conio.h>
const int _size = 100;
int raviolly(int mas[ ],int n)
{   int k = n-1;

   // mas[n-8]>=mas[n-1]

    for(int i = 0;i<=n-1;i++)
	{
	    if(mas[n-1]>=mas[i] && mas[n-1]>=mas[i+1] || mas[i+1] == mas[i+2] && mas[i+1]<=mas[n-1] || mas[i]==mas[i+1] || n == 10 &&  mas[n-8]>=mas[n-1] && mas[i+6]>=mas[n-1] || n==1 && mas[n-1]>=mas[i])
		{
			std::cout << "YES" << std::endl;
			break;
		}
		else
		{
			std::cout << "NO" << std::endl;
			break;

		}

	}

	return 0;
}
int main()
{  //setlocale(LC_ALL,"");
	int n = 0;

	int array2[_size];
//	std::cout << "������:" <<std::endl;
	std::cin >> n;
	std::cout << std::endl;
//	std::cout << "�������� �������:" << std::endl;
	if(n>= 1 && n<= 10)
	{
	for(int i=0;i<n;i++)
	{

		std::cin >> array2[i];

	}
	raviolly(array2,n);
	}

 // getch();
		return 0;

}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);

#define    READ(f) 	         freopen(f, "r", stdin)
#define    WRITE(f)   	     freopen(f, "w", stdout)
#define    MP(x, y) 	     make_pair(x, y)
#define    PB(x)             push_back(x)
#define    rep(i,n)          for(int i = 1 ; i<=(n) ; i++)
#define    repI(i,n)         for(int i = 0 ; i<(n) ; i++)
#define    FOR(i,L,R) 	     for (int i = (int)(L); i <= (int)(R); i++)
#define    ROF(i,L,R) 	     for (int i = (int)(L); i >= (int)(R); i--)
#define    FOREACH(i,t)      for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define    ALL(p) 	         p.begin(),p.end()
#define    ALLR(p) 	         p.rbegin(),p.rend()
#define    SET(p) 	         memset(p, -1, sizeof(p))
#define    CLR(p)            memset(p, 0, sizeof(p))
#define    MEM(p, v)         memset(p, v, sizeof(p))
#define    getI(a) 	         scanf("%d", &a)
#define    getII(a,b) 	     scanf("%d%d", &a, &b)
#define    getIII(a,b,c)     scanf("%d%d%d", &a, &b, &c)
#define    getL(a)           scanf("%lld",&a)
#define    getLL(a,b)        scanf("%lld%lld",&a,&b)
#define    getLLL(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define    getC(n)           scanf("%c",&n)
#define    getF(n)           scanf("%lf",&n)
#define    getS(n)           scanf("%s",n)
#define    bitCheck(N,in)    ((bool)(N&(1<<(in))))
#define    bitOff(N,in)      (N&(~(1<<(in))))
#define    bitOn(N,in)       (N|(1<<(in)))
#define    bitFlip(a,k)      (a^(1<<(k)))
#define    bitCount(a)        __builtin_popcount(a)
#define    bitCountLL(a)      __builtin_popcountll(a)
#define    bitLeftMost(a)     (63-__builtin_clzll((a)))
#define    bitRightMost(a)    (__builtin_ctzll(a))
#define    iseq(a,b)          (fabs(a-b)<EPS)
#define    UNIQUE(V)          (V).erase(unique((V).begin(),(V).end()),(V).end())
#define    vi 	              vector < int >
#define    vii 	              vector < vector < int > >
#define    pii 	              pair< int, int >
#define    ff 	              first
#define    ss 	              second
#define    ll	              long long
#define    ull 	              unsigned long long
#define    POPCOUNT           __builtin_popcount
#define    POPCOUNTLL         __builtin_popcountll
#define    RIGHTMOST          __builtin_ctzll
#define    LEFTMOST(x)        (63-__builtin_clzll((x)))
#define    FMT(...)           (sprintf(CRTBUFF, __VA_ARGS__)?CRTBUFF:0)
char CRTBUFF[30000];

template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }

#define dipta00
#ifdef dipta007
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
     #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
        template <typename Arg1>
        void __f(const char* name, Arg1&& arg1){
            cerr << name << " : " << arg1 << std::endl;
        }
        template <typename Arg1, typename... Args>
        void __f(const char* names, Arg1&& arg1, Args&&... args){
            const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
        }
#else
    #define debug(args...)  /// Just strip off all debug tokens
    #define trace(...) ///yeeeee
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///****************** template ends here ****************

// g++ -g -O2 -std=gnu++11 A.cpp
// ./a.out

int main() {
    #ifdef dipta007
        //READ("in.txt");
       //WRITE("out.txt");
    #endif // dipta007
    ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    while(cin >> n)
    {
        int a[n];
        int r[n];
        int s[n];
        FOR(i,0,n-1)
        {
            getI(a[i]);
            r[i] = a[i];
            s[i] = a[i];
        }
        sort(s, s+n);
        sort(r, r+n);
        reverse(r, r+n);

        int mf = 1;

        FOR(i,0,n-1)
        {
            debug(a[i], s[i])
            if(a[i] != s[i]) mf = 0;
        }

        if(mf == 1)
        {
            cout << FMT("YES\n");
            continue;
        }

        mf = 1;
        FOR(i,0,n-1)
        {
            debug(a[i], r[i])
            if(r[i] != a[i]) mf = 0;
        }

        if(mf) cout << FMT("YES\n");
        else cout << FMT("NO\n");
//        int max = 0;
    }

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;

    vector<int>a;
    vector<int> ::iterator p;
    for(int i=0;i< n ;i++){
            int x;
       cin>>x;
        a.push_back(x);
    }
    int ok=0,mx=-1,it;
    for(int i=n;i>1;i--){
        for(int j=0;j<n-1;j++){
            if(a[j]>a[j+1]+1||a[j]+1<a[j+1]){
                ok=1;

                cout<<"No";
                return 0;
            }
        }
        p=std::max_element(a.begin(),a.begin()+i);
        int aux=*p;
        a.erase(p);
        a.push_back(aux);

   }

    cout<<"Yes";
    return 0;

}

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;

void doit(int n,vector <int> &v)
{
  for(int i=0;i<(n-1);i++)
	{
	    if((v[i]-v[i+1])>=2)
	    {
	        v[i]--;
	        v[i+1]++;
	    }
	    if((v[i+1]-v[i])>=2)
	    {
	        v[i]++;
	        v[i+1]--;
	    }
	}
}

int main() {
	int n,k,a,q,flag;
	flag=0;
	cin >> n;
	vector <int> v;
	deque <int> d;
	vector <int> :: iterator it;
	for(int i=0;i<n;i++)
	{
	    cin >> a;
	    v.push_back(a);
	}
	q=n;
	while(q>0)
	{
	 doit(q,v);
	 it = max_element(v.begin(),v.end());
	 k = *it;
	 d.push_back(k);
	 v.erase(it);
	 q--;
	}
	for(int i=0;i<(n-1);i++)
	{
	    if(d[i+1]>=d[i])
	    {
	        cout << "NO";
	        flag = 1;
	        break;
	    }
	}
	if(flag==0)
	cout << "YES";
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int a[11],b[11];
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n-1);
    for(int i=n-1;i>=0;--i)
    {
        for(int j=0;j<n;++j)
        {
            if(a[j]!=-1 && a[j]==b[i])
            {
                a[j]=-1;
                int one=-1;
                int two=-1;
                for(int k=0;k<n;)
                {
                    while(k<n && a[k]==-1)++k;
                    if(k!=n) one = a[k];
                    ++k;
                    while(k<n && a[k]==-1)++k;
                    if(k!=n+1 && k!=n) two = a[k];
                    if(abs(one-two)>=2 && k!=n+1 && k!=n)
                    {
                        cout<<"NO";
                        return 0;
                    }

                }
            }

        }
    }
   /* bool check = true;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {

        }
    }*/
    cout<<"YES";
    return 0;
}

#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main(){
	vector < int > v(0);
	int i, a, j, n;
	bool flag=true;
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> a;
		v.push_back(a);
	}
	for (i = 0; i < n; i++){
		if (abs(v[i]-v[i-1]) > 1)
		    flag=false;
	}
	if (flag){
		cout << "YES";
	}
	else{
		cout << "NO";
	}
}

#include <iostream>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,a[100],k=0;
    cin>>n;

    for(int i = 0;i<n;i++)
    cin>>a[i];

    for(int i = 0;i<n;i++){
        if(abs(a[i]-a[i-1])<=1&&abs(a[i]-a[i+1])<=1)
        k++;
    }

if(k!=0)
cout<<"YES";
else
cout<<"NO";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main()
{
    int n,x;
    cin>>n;
    vector< int > v,v2,v1;
    cin>>x;
    v.push_back(x);
    v2.push_back(x);
    v1.push_back(x);
    bool test =true;
    for(int i=1;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
        v1.push_back(x);
        v2.push_back(x);
    }
    sort(v1.begin(),v1.end());
    sort(v2.rbegin(),v2.rend());
    int s=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]==v1[i]) s++;
    }
    if(s==n) {cout<<"YES"<<endl; return 0;}
    sort(v2.rbegin(),v2.rend());
     s=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]==v2[i]) s++;
    }
    if(s==n) {cout<<"YES"<<endl; return 0;}
    cout<<"NO";
    return 0;
}

#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int a[100005];

int main()
{
	IO_OP;

	int n;
	cin >> n;
	a[0] = -INF;
	for(int i=1;i<=n;i++) {
	    cin >> a[i];
	    if(a[i] < a[i-1]) {
	        cout << "NO" << endl;
	        return 0;
	    }
	}
	cout << "YES" << endl;
}

#include <iostream>
#include <vector>
using namespace std;

int n, x;
vector<int> arr;
string ans = "YES";

int main() {
  cin >> n;
  cin >> x;
  arr.push_back(x);
  for (int i = 1; i < n; i++) {
    cin >> x;
    arr.push_back(x);
    if (abs(arr[i]-arr[i-1]) >= 2) {
      ans = "NO";
    }
    if (arr[i]-arr[i-1] < 0) {
      ans = "NO";
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
#define MAXN 200000
typedef int ll;

int klocki[MAXN];
int main(){
  int n,a;
  vector <int> v;
  vector <int> v2;
    vector <int> v3;

  cin>>n;
  for(int i=0; i<n; i++){
    cin>>a;
    v.push_back(a);
    v2.push_back(a);
    v3.push_back(-a);
  }
  sort(v.begin(), v.end());
  sort(v3.begin(), v3.end());
  for(int i=0; i<v.size(); i++){
    if(v2[i]!=v[i]){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
  return 0;
  for(int i=0; i<v.size(); i++){
    if(-v3[i]!=v[i]){
      cout<<"NO";
      return 0;
    }

  }
}

#include <bits/stdc++.h>

using namespace std;

#define Cerr cerr << "\nTest: "
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio { ios_base::sync_with_stdio(false), cin.tie(NULL); }
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#ifdef RICARDO
	#define bug(x) cerr << #x << " = " << (x) << endl;
	#define block if(1)
#else
	#define bug(x) "IDINGO"
	#define block if(0)
#endif

template<class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; }

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;

//=================================================CODE=================================================//

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
#ifdef RICARDO
	freopen("i", "r", stdin);
#endif

    int n; cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];

    forn(i, n - 1) {
        if (a[i] > a[i + 1]) {cout << "NO" << endl; return 0;}
    }

    cout << "YES" << endl;

#ifdef RICARDO
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

#include <bits/stdc++.h>
int n,x,xx;
int main()
{
    std::cin>>n;
    for(int i=1;i<=n;i++)
	{
		if(i==1) std::cin>>x,xx=x,i++;
        std::cin>>x;
        if(abs(x-xx)!=1) { std::cout<<"NO"; return 0; }
        xx=x;
    }
    std::cout<<"YES";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[15];
	for (int i=0; i<n; i++)
	    cin>>a[i];
	for (int i=0; i<n-1; i++)
	    if (abs(a[i]-a[i+1])>=2)
	    {
	        cout<<"NO"<<endl;
	        return 0;
	    }
	cout<<"YES"<<endl;
	return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
using namespace std;

int main() {
	string s;
	int n;
	cin>>n;
	bool f=1;
	vector<int> a(n);
	for(int i=0;i<n;i++) {
		if(i) {
			if(a[i]<a[i+1])
				f=0;
		}
	}
	if(f) cout<<"YES";
	else cout<<"NO";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,c=0;
    cin>>n;
    long long int a[n],b[n];
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(long long int i=0;i<n;i++)
    {

        if(b[i]==a[i])
            c++;
    }
    c==n?cout<<"YES"<<endl:cout<<"NO"<<endl;
}

#include<bits/stdc++.h>
using namespace std ;
int main(){
    int n ;
    int a[15] ;
    cin >> n ;
    for( int i = 1 ; i <= n ; i++ )
        cin >> a[i] ;
    bool flag = true ;
    int st = n ;
    while( 1 ){
          if ( st == 1 ) break ;
          for( int i = 2 ; i <= st ; i++ )
              if ( abs( a[i] - a[i - 1] ) > 1 ) flag = false ;
          if ( !flag ) break ;
          int maxx = a[1] ;
          int id = 1 ;
          for( int i = 2 ; i <= st ; i++ )
              if ( a[i] > maxx ) { maxx = a[i] ; id = i ; }
          a[st] = a[id] ;
          for( int i = id ; i < st ; i++ )
              a[i] = a[i + 1] ;
          st-- ;
    }
    if ( st == 1 ) cout << "YES" << endl ;
    else cout << "NO" << endl ;
    return 0 ;
}

#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[n];
    cin>>arr[0];
    for(int i=1;i<n;i++){
        cin>>arr[i];
        if(abs(arr[i]-arr[i-1])==2){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;scanf("%d",&n);
	int last=0;
	bool flag=0;
	for(int i=1;i<=n;++i)
	{
		int x;scanf("%d",&x);
		if(abs(x-last)%2==0) flag=1;
		last=x;
	}
	if(flag) puts("NO");
	else puts("YES");
}

#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;

int main()
{
    IO;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    for(int i=1;i<n;++i)
        if(a[i]<a[i-1])exit(puts("NO"));
    cout<<"YES\n";
    re 0;
}

#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<vector>
inline void read(int &x)
{
	x=0;
	char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
	{
		x=x*10+c-'0';
		c=getchar();
	}
}
int main()
{
	int n,a[10],b[10],i,t;
	read(n);
	for(i=0;i<n;i++)
	{
		read(a[i]);
		b[i]=a[i];
	}
	std::sort(b,b+n);
	for(i=1;i<n;i++)
		if(abs(a[i]-a[i-1])>0)
		{
			if(a[i]>a[i-1])
			{
				t=(a[i]+a[i-1]-1)/2+1;
				a[i-1]=(a[i]+a[i-1])/2;
				a[i]=t;
			}
			else
			{
				t=(a[i]+a[i-1]-1)/2+1;
				a[i]=(a[i]+a[i-1])/2;
				a[i-1]=t;
			}
		}
	for(i=0;i<n;i++)
		if(a[i]!=b[i])
		{
			printf("NO");
			return 0;
		}
	printf("YES");
	return 0;

}

#include <iostream>
#include <cmath>

using namespace std;

int n;
int arr[11];
int res[11];
bool succ;

void doSort() {
    int curLen = n;
    int rLen = 0;
    int curMax, mInd;
    while (curLen > 0) {
        curMax = 0;
        mInd = -1;
        for (int i = 0; i < curLen; ++i) {
            if (arr[i] > curMax) {
                curMax = arr[i];
                mInd = i;
                break;
            }
        }
        for (int i = rLen; i > 0; --i) {
            res[i] = res[i - 1];
        }
        res[0] = curMax;
        if (rLen > 0 && abs(res[0] - res[1]) >= 2) {
            cout << "NO" << endl;
            succ = false;
            break;
        }
        ++rLen;
        for (int i = mInd; i < curLen - 1; ++i) {
            arr[i] = arr[i + 1];
        }
        if (mInd > 0 && abs(arr[mInd - 1] - arr[mInd]) >= 2) {
            cout << "NO" << endl;
            succ = false;
            break;
        }
        --curLen;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    succ = true;
    for (int i = 0; i < n - 1; ++i) {
        if (abs(arr[i] - arr[i + 1]) >= 2) {
            cout << "NO" << endl;
            succ = false;
        }
    }
    doSort();
    if (succ) {
        cout << "YES" << endl;
    }
    return 0;
}

#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
int a[104];
int main(){
	int n;
	cin>>n;
	bool flag = false;
	for(int i = 1; i <= n; i++) cin>>a[i];
	for(int i = 1; i <= n; i++){
		if(a[i+1] > a[i]) flag = true;
	}
	if(flag) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

//prince0fcrows
#include <bits/stdc++.h>
#define int long long
#define mx 200005
#define mod 1000000007

using namespace std;
std::vector< int > g;
int ara[mx];
int ara2[mx];
set <int> s;
string str;

int32_t main(){
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int i, j, a, n, h, c, m, b, k, t, l, r;
    cin >> n;
    for(i=1;i<=n;i++) {
        cin >> ara[i];
        ara2[i] = ara[i];
    }
    sort(ara2+1, ara2+n);
    b = 1;
    for(i=1;i<=n;i++) {
        if((ara[i]!=ara2[i])) b = 0;
    }
    if(b) {
        cout << "YES";
        return 0;
    }
    cout << "NO";
    return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int n, x, mx;
vector<int> arr;
string ans = "YES";

int main() {
  cin >> n;
  cin >> x;
  arr.push_back(x);
  for (int i = 1; i < n; i++) {
    cin >> x;
    arr.push_back(x);
    if (abs(arr[i]-arr[i-1]) >= 2) {
      ans = "NO";
    }
    mx = max(mx, x);
  }
  int prev = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] == mx) continue;
    if (arr[i]-prev < 0) ans = "NO";
    prev = arr[i];
  }
  sort(arr.begin(), arr.end());
  for (int i = 1; i < n; i++) {
    if (abs(arr[i]-arr[i-1]) >= 2) {
      ans = "NO";
    }
  }
  cout << ans << endl;
}

#include<iostream>
#include<stack>
#include<sstream>
#include<set>
#include<fstream>
#include<cfloat>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>

using namespace std;
int main(){
    int arr[111], n=0;
    cin>>n;
    for(int i=0; i<n;i++)cin>>arr[i];

    for(int i=0; i<n-1;i++){
        if(abs(arr[i] - arr[i+1]) >= 2) {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vst vector<string>
#define sti set<int>
#define sz size()
#define lli long long int
using namespace std;

int main()
{
   int n,a[101];bool f=true;
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   for (int i = 1; i <n-1; i++)//3 1 1 1 1 2
   {
	   for(int j=i+1;j<n;j++){
		   if(a[i]!=a[j]){if((a[i]>a[i-1]&&a[i]>a[j]||a[i]<a[i-1]&&a[i]<a[j])&&a[i-1]!=a[j]){f=false;break;}}
	   }
   }
  if(f)
	  cout<<"YES\n";
  else
	  cout<<"NO\n";
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int n,i,j,f=0;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        if(i>0&&a[i]<a[i-1])
            f=1;
    }
    if(f==1)
    {
        cout<<"YES";
        return 0;
    }
    for(i=0;i<n-1;i++)
    {
        if(a[i]-a[i+1]>=2)
            //cout<<"NO";
            f=2;
    }
    if(f==2)
        {
            cout<<"NO";
            return 0;
        }
    cout<<"YES";

}

#include <cstdio>
#include <iostream>
#include <bitset>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <set>
#include <time.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vs(n);
  for (int i = 0; i < n; ++i) {
    cin >> vs[i];
    if (i != 0 && vs[i] <= vs[i - 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
long long n,mas[12];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>mas[i];
    }
    for(int i=1;i<n;i++)
    if(abs(mas[i]-mas[1+i])>=2){cout<<"N0"<<endl;
    return 0;}
    cout<<"YES";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define NL '\n'
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define ones __builtin_popcount
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define sd(x) scanf("%lf",&x)
#define ss(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define debug(x) cerr << "debug = " << x << "\n";
#define debugs(s,x) cerr << "debug : " << s << " = " << x << "\n";
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define X real()
#define Y imag()
#define Point complex<long double>
#define pi 2.0*acos(0.0)
#define EPS 1e-9
#define INF INT_MAX
#define MOD 1000000007
#define MAX 100005

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

int a[15], n;

bool solve(int st)
{
    bool flag = true, boro = 0;
    int mx = 0;
    for(int i = 0; i < n-1; i++)
    {
        if(a[i]-1 > a[i+1] || a[i] < a[i+1]-1) boro = true;
        if((a[i]-1 > a[i+1] || a[i] < a[i+1]-1) && st) return 0;
        if(a[i] > a[i+1]) flag = false;
        if(a[i] > a[mx]) mx = i;
    }
    if(flag) return 1;
    if(boro) return 0;
    a[n] = a[mx];
    for(int i = mx; i < n; i++)
        a[i] = a[i+1];
    return solve(st+1);
}

int main()
{
    //READ("input.txt");
    //WRITE("out.txt");
    std::ios_base::sync_with_stdio(0);
    int cases, caseno=0, i, j = 0, k, cnt;

    cin >> n;

    FOR(i,0,n-1) cin >> a[i];

    if(solve(0)) cout << "YES";
    else cout << "NO";

    return 0;
}

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<deque>
#include<iterator>
#include<assert.h>
#include<bitset>
#include<climits>
#include<ctime>
#include<complex>
#include<bits/stdc++.h>
using namespace std;
//define for shortcut
#define mem(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(A) A.size()
#define clr(a) memset(a,0,sizeof(a))
#define pb push_back
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define vs vector<string>
#define vi vector<int>
#define vc vector<char>
#define sts set<string>
#define sti set<int>
#define stc set<char>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define ull unsigned long long
#define ll long long
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define rfor1(i,a,b) for(int i=a;i>=b;i--)
#define rfor0(i,a,b) for(int i=a-1;i>b;i--)
#define for0(i,a) for(int i=0;i<a;i++)
//read input
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define sfll2(a,b) scanf("%lld%lld",&a,&b)
#define sfll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define ss(a) scanf("%s",&a)
#define sc(a) scanf("%c",&a)
#define sd(a) scanf("%lf",&a)
#define pf(a) printf("%d",a)
#define pfll(a) printf("%lld",a)
#define pfd(a) printf("%.17f",a)
#define pc(a) printf("%c",a)
#define ps(a) printf("%s",a)
#define cs printf("Case %d: ",kk++)
#define cn printf("Case %d:\n",kk++)
///#define c# printf("Case #%d: ",kk++)
#define nl printf("\n")
#define done cout<<"done"<<endl;
#define eps 1e-9
#define mod 1000000007
#define inf INT_MAX
#define MX 100010
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define fast ios_base::sync_with_stdio(false);
template<typename T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline vi parse(T str)
{
    vi res;
    int s;
    istringstream os(str);
    while(os>>s)res.pb(s);
    return res;
}
template< class T > inline T _sqrt(T x)
{
    return (T) sqrt( (double) x);
}
template< class T > inline T _bigmod(T n,T m)
{
    T ans=1,mult=n%mod;
    while(m)
    {
        if(m & 1) ans=(ans*mult)%mod;
        m>>=1;
        mult=(mult*mult)%mod;
    }
    ans%=mod;
    return ans;
}
template< class T > inline T _modinv(T x)
{
    return _bigmod(x,(T) mod-2)%mod;
}
inline int len(string a)
{
    return a.length();
}
inline int len(char a[])
{
    return strlen(a);
}
template<class T> inline T _gcd(T a, T b)
{
    return (b==0) ? a : _gcd(b, a % b);
}
template< class T > inline T _lcm(T x,T y)
{
    return x*y/_gcd(x,y);
}
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//bool compare(const pair<float,string>&i, const pair<float,string>&j)
//{
//    return i.first > j.first;
//}
//int in_c() { int c; for (; (c = getchar()) <= ' '; ) { if (!~c) throw ~0; } return c; }
//int EQ(double d) {
//    if ( fabs(d) < EPS ) return 0;
//    return d > EPS ? 1 : -1 ;
//}
int brr[100];
int arr[100];
int main()
{
//    clock_t begin = clock();
//    //your code goes here
       int n;
       cin>>n;
       map<int,int>mp;
       for(int i=0; i<n; i++)
       {
           cin>>arr[i];
           mp[arr[i]]++;
       }
       int c=0;
       for(int i=1; i<n-1; i++)
       {
           if(arr[i]<arr[i-1] && arr[i]<arr[i+1]){c=1;break;}
       }
       if(!c)cout<<"Yes\n";
       else cout<<"No\n";
//    //end here
//    clock_t end = clock();
//    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
//    cerr<<"Running Time: "<<time_spent<<" Seconds"<<endl;
//    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int l[101],s[101];
int main(){
	int n;
	cin>>n;
	int i,j,k;
	for(i=1;i<=n;i++)
	{
		cin>>l[i];
		s[i]=l[i];
	}
	sort(s+1,s+n+1);
	for(i=1;i<n;i++)if(s[i+1]-s[i]>=2){cout<<"NO";return 0;}
	for(i=n;i;i--)
	{
		j=1;
		while(l[j]!=s[i]) j++;
		if(j!=1&&l[j]-l[j-1]>=2){cout<<"NO";return 0;}
		if(j!=n&&l[j]-l[j+1]>=2){cout<<"NO";return 0;}
		if(l[j]-l[i]>=2){cout<<"NO";return 0;};
		while(j<i){l[j]=l[j+1];j++;}
		l[i]=s[i];
	}
	cout<<"YES";
	return 0;
}

#include <bits/stdc++.h>
#define oo INT_MAX
typedef long long ll;
using namespace std;
#define MAXN 20005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin>>n;
    vector <int> S;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        S.push_back(x);
    }
    for(int i=1; i<n; i++)
    {
        if(S[i]!=S[i-1]+1 && S[i]!=S[i-1]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define f(i , n) for (int i = 0; i < (int)(n); ++i)
#define f1(i, x, n) for (int i = x; i < (int)(n); ++i)
const int mod = 1000000007;
const int inf = 2012345678;
const double PI = acos(-1);
const ll infl = 9012345678901234567;
const double eps = 5e-1;
const int N = 1e5;
int main(){
#if !ONLINE_JUDGE
    freopen("In.txt", "r", stdin);
#endif
    int n , pr;
    cin>>n;
    f(i,n){
        int a;
        cin>>a;
        if(i==0)pr=a;
        else{
            if(a<=pr){
                cout<<"NO"<<endl;
                return 0;
            }
            pr = a;
        }
    }
    cout<<"YES"<<endl;
}

#include<stdio.h>

int main()
{
    int a[10];
    int n,i,j;
    bool flag = true;
    scanf("%d",&n);
    for(i = 0; i < n; i++)
        scanf("%d",&a[i]);
    for(j = 0; j < n; j++)
    {
        if((a[j] - a[j+1] >= 2) )
        {
            flag = false;
            break;
        }
    }
    if(flag)
        printf("YES\n");
    else printf("NO\n");
    return 0;
}

#include<bits/stdc++.h>
#define INF 1000000000
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;

int datas[50];

int main()
{
	int data;
	cin>>data;
	int hasil=0;
	int maxi=-1;
	for(int a=0;a<data;a++)
	{
		scanf("%d", &datas[a]);
		if(a!=data-1)
		{
			hasil+=datas[a];
		}
		if(a > 0)
		{
			while(datas[a-1]-datas[a] >= 2)
			{
				datas[a-1]--;
				datas[a]++;
			}
			while(datas[a]-datas[a-1] >= 2)
			{
				datas[a]--;
				datas[a-1]++;
			}
		}
		maxi=max(datas[a], maxi);
	}
	if(maxi==datas[data-1])
	{
		for(int a=0;a<data-1;a++)
		{
			if(datas[a] > datas[a+1])
			{
				printf("NO");
				return 0;
			}
		}
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	printf("\n");
 	return 0;
}

//SMIT DETROJA
//201601113

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>

#define mod 1000000007
#define ll long long
#define ld long double
#define sp " "

#define gll(a,n) For(i,0,n) cin>>a[i];

#define pi(x) printf("%lld ",x)

#define mst(a,b) memset(a,b,sizeof a);
#define pline printf("\n")

#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,a,b) Rfor(ll i=a;i>=b;i--)

#define deb1(x)                cerr<<#x<<": "<<x<<endl
#define deb2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

#define pb push_back
#define mp make_pair
#define fir first
#define sec second

#define INF 999999999999999999

using namespace std;

typedef pair<ll,ll> pp;

/*

    For(i,0,m)
    {
        ll u,v;
        cin>>u>>v;

        adj[u].push_back(make_pair(1,v));
        adj[v].push_back(make_pair(1,u));
    }

    ll a,b;
    cin>>a>>b;

    vector<ll> dist1 = dijkstra(a,n,adj);

*/
/*
vector<ll> dijkstra(ll src, ll n ,vector<pair<ll,ll> > adj[])
{
    vector<ll> dist;
    bool visited[n];

    for(ll i=0;i<n;i++)
    {
        dist.push_back(INF);
        visited[i]=false;
    }

    dist[src]=0;
    multiset<pair<ll,ll> > s;
    s.insert(make_pair(0,src));

    while(!s.empty())
    {
        pair<int,int> temp = *s.begin();
        s.erase(s.begin());

        ll u = temp.second;

        if(visited[u])
            continue;

        visited[u]=true;

        for(ll i=0;i<adj[u].size();i++)
        {
            ll w = adj[u][i].first;
            ll v = adj[u][i].second;
            if(dist[u]+w<dist[v])
            {
                dist[v]=dist[u]+w;
                s.insert(make_pair(dist[v],v));
            }

        }
    }

    return dist;
}

*/

bool isprime[2000005];

void setprime()
{
    For(i,0,2000005)
        isprime[i]=true;
        isprime[0]=false;
        isprime[1]=false;

    For(i,2,2000005)
    {
        for(ll j=2;i*j<2000005;j++)
            isprime[i*j]=false;
    }
}

ll choose(ll n,ll k)
{
    if(k==0)
        return 1;
    return (n* choose(n-1,k-1))/k;
}
/*
bool isprime(ll n)
{
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        return false;
    }
    return true;
}

*/
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(12);

    ll n;
    cin>>n;
    ll a[n];

    For(i,0,n)
    {
        cin>>a[i];
    }

    bool flag1 = 0;
    bool flag2 = 0;

    for(ll i =1;i<n;i++)
    {
        if(a[i-1] > a[i])
            flag1 = 1;
    }

    for(ll i =1;i<n;i++)
    {
        if(a[i-1] < a[i])
            flag2 = 1;
    }

    if(!flag1)
        cout<<"YES";
    else cout<<"NO";

    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long  n,x;
    cin>>n;
    bool flag=1;
    bool b=1;

    vector<int>c;
    vector<int>l;
    vector<int>r;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        c.push_back(x);
    }
    //sort(c.begin(),c.end(),greater<int>());
    for(int j=0;j<n;j++)
    {
        if(abs(c[j]-c[j+1])>=2&&j!=n-1)
        {
            int o=floor(c[j]+c[j+1]/2);
            l.push_back(o);
            l.push_back(o);
            replace(c.begin(),c.end(),c[j+1],o);
        }
        else
        {
                l.push_back(c[j]);
       }
    }
       sort(l.begin(),l.end(),greater<int>());
       for(int k=0;k<n;k++)
       {
           if(l[k]>l[k+1])
           {
               flag=1;
           }
           else
           {
               flag=0;
               break;
           }

    }

    if(flag==1)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int>num;
  num.resize(n);
  for(int i=0;i<n; i++)
  cin>>num[i];
  long long flag=0;
  for(int i=0; i<n; i++)
  if(abs(num[i]-num[i+1])==2){flag++;}

    if(flag==1)cout<<"No"<<endl;
    else
   cout<<"YES"<<endl;

}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const int maxn = 10000 + 10;

int main(){
    int a[20];
	int n;
	scanf("%d", &n);
	int no = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(i != 0){
			if(a[i] - a[i-1] >=2) no = 1;
		}
	}
    if(no) printf("NO\n");
    else printf("YES\n");

    return 0;
}

#include <cstdio>
#include <iostream>
#include <bitset>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <set>
#include <time.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vs(n);
  for (int i = 0; i < n; ++i) {
    cin >> vs[i];
    if (i != 0 && vs[i] < vs[i - 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert
#define FOR(prom,a,b) for ( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)
#define EPS (1e-10)
// INF for (int) = ( 1<<30 )
// LINF for (long long) = ( 1LL<<62LL )
#define EQ(a,b) (fabs(a-b) <= fabs(a+b) * EPS)

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    vi a(N);F(N)cin>>a[i];
    bool f=1;
    F(N-1)if(abs(a[i+1]-a[i])<=1)f=0;
    cout<<(f?"YES":"NO")<<endl;
    return 0;
}

#include<stdio.h>
#include<math.h>
int a[1010];
int main()
{
	int m;
	scanf("%d",&m);
	int max=0;
	int p=0;
	for(int i=0;i<m;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>max)
		{
			max=a[i];
			p=i;
			}
	}
	int flg=1;
	if(p==0)
	{
		if(fabs(a[p+1]-a[p])>=2)
		flg=0;

		}
   else  if(p==m-1)
    {
		if(fabs(a[p]-a[p-1])>=2)
		flg=0;}
	else
		{
			if(fabs(a[p]-a[p+1])>=2||fabs(a[p]-a[p-1])>=2)
			flg=0;
			}
			if(flg==0)puts("NO");
			else
			{
	int tmp=m;
	for(int i=0;i<m-1;i++)
	{
		int tmp1=a[p];
		for(int i=p+1;i<m;i++)
		  a[i-1]=a[i];
		  a[m-1]=tmp1;
		tmp--;
		max=0;
		for(int i=0;i<tmp1;i++)
		    {
				if(a[i]>max)
				{
					max=a[i];
					p=i;}
				}
		if(p==0)
	{
		if(fabs(a[p+1]-a[p])>=2)
		flg=0;

		}
   else  if(p==m-1)
    {
		if(fabs(a[p]-a[p-1])>=2)
		flg=0;}
	else
		{
			if(fabs(a[p]-a[p+1])>=2||fabs(a[p]-a[p-1])>=2)
			flg=0;
			}

		if(flg==0)break;
   }
   if(flg)printf("YES\n");
   else printf("NO\n");

}
return 0;

}

#include <iostream>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n,a[100],k=0;
    cin>>n;

    for(int i = 0;i<n;i++)
    cin>>a[i];

    for(int i = 0;i<n;i++){
        if(abs(a[i]-a[i-1])<=1&&abs(a[i]-a[i+1])<=1)
        k++;
        }

if(k!=0)
cout<<"YES";
else
cout<<"NO";
    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

bool f(int n){
	if(n % 2 == 0){
		return 0;
	}
	return 1;
}

int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	for(int i = 1 ; i <= n; ++i)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1 , b + n + 1);
	for(int i = 1 ; i <= n ;++i){
		if(b[i] != a[i]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}

#include <bits/stdc++.h>
using namespace std;

typedef  long long ll;

ll n,m=0,k=0;

bool test=false,test1=false;

ll const N=1e5+7;

ll const oo=1000000007 ;

ll nChoosek( ll n, ll k )
{
    if (k > n) return 0;
    if (k * 2 > n) /*return*/ k = n-k;
    if (k == 0) return 1;

    ll result = n;
    for( ll i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

vector<ll> v,v1;

vector<pair<ll,ll> > vv;

//ll  t[oo][oo];

map<pair<ll,ll> ,ll> my1;

map<ll,ll> my;

priority_queue<ll> q;

ll t[N];

//ll t1[N][N];

ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};

vector<ll> v2[N];
ll z[N];
void dfs(ll s)
{
    if (z[s]) return;
 z[s] = 1;
 for (ll u=0;u<v2[s].size();u++)
    { dfs(v2[s][u]); }
 }

int main() {

ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll i=0,j=0,a=0,b=0,c=0,d=-1e18,x=0,y=0,s=0,r,l;
string s1,s2,s3,s4,s5;
//freopen("tabs.in","r",stdin);
cin>>n;
for(i=0;i<n;i++)
{cin>>a;
v.push_back(a);
}
v1=v;
sort(v.begin(),v.end());
for(i=1;i<n;i++)
{if(v1[i]-v1[i-1]>1) {cout<<"NO";return 0;}
}

for(i=1;i<n;i++)
{if(v[i]-v[i-1]>1) {cout<<"NO";return 0;}
}

if(v==v1) cout<<"YES";
else cout<<"NO";
   return 0;

}

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<deque>
#include<iterator>
#include<assert.h>
#include<bitset>
#include<climits>
#include<ctime>
#include<complex>
#include<bits/stdc++.h>
using namespace std;
//define for shortcut
#define mem(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(A) A.size()
#define clr(a) memset(a,0,sizeof(a))
#define pb push_back
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define vs vector<string>
#define vi vector<int>
#define vc vector<char>
#define sts set<string>
#define sti set<int>
#define stc set<char>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define ull unsigned long long
#define ll long long
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define rfor1(i,a,b) for(int i=a;i>=b;i--)
#define rfor0(i,a,b) for(int i=a-1;i>b;i--)
#define for0(i,a) for(int i=0;i<a;i++)
//read input
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define sfll2(a,b) scanf("%lld%lld",&a,&b)
#define sfll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define ss(a) scanf("%s",&a)
#define sc(a) scanf("%c",&a)
#define sd(a) scanf("%lf",&a)
#define pf(a) printf("%d",a)
#define pfll(a) printf("%lld",a)
#define pfd(a) printf("%.17f",a)
#define pc(a) printf("%c",a)
#define ps(a) printf("%s",a)
#define cs printf("Case %d: ",kk++)
#define cn printf("Case %d:\n",kk++)
///#define c# printf("Case #%d: ",kk++)
#define nl printf("\n")
#define done cout<<"done"<<endl;
#define eps 1e-9
#define mod 1000000007
#define inf INT_MAX
#define MX 100010
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define fast ios_base::sync_with_stdio(false);
template<typename T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline vi parse(T str)
{
    vi res;
    int s;
    istringstream os(str);
    while(os>>s)res.pb(s);
    return res;
}
template< class T > inline T _sqrt(T x)
{
    return (T) sqrt( (double) x);
}
template< class T > inline T _bigmod(T n,T m)
{
    T ans=1,mult=n%mod;
    while(m)
    {
        if(m & 1) ans=(ans*mult)%mod;
        m>>=1;
        mult=(mult*mult)%mod;
    }
    ans%=mod;
    return ans;
}
template< class T > inline T _modinv(T x)
{
    return _bigmod(x,(T) mod-2)%mod;
}
inline int len(string a)
{
    return a.length();
}
inline int len(char a[])
{
    return strlen(a);
}
template<class T> inline T _gcd(T a, T b)
{
    return (b==0) ? a : _gcd(b, a % b);
}
template< class T > inline T _lcm(T x,T y)
{
    return x*y/_gcd(x,y);
}
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//bool compare(const pair<float,string>&i, const pair<float,string>&j)
//{
//    return i.first > j.first;
//}
//int in_c() { int c; for (; (c = getchar()) <= ' '; ) { if (!~c) throw ~0; } return c; }
//int EQ(double d) {
//    if ( fabs(d) < EPS ) return 0;
//    return d > EPS ? 1 : -1 ;
//}
int brr[100];
int arr[100];
int main()
{
//    clock_t begin = clock();
//    //your code goes here
       int n;
       cin>>n;
       map<int,int>mp;
       for(int i=0; i<n; i++)
       {
           cin>>arr[i];
           mp[arr[i]]++;
       }
       for(int i=1; i<n-1; i++)
       {
           while(arr[i]<arr[i-1] && arr[i]<arr[i+1])
           {
               arr[i]++;
               arr[i-1]--;
           }
       }
       int c=0;
       for(int i=0; i<n; i++)
       {
           if(mp[arr[i]])
           {
               c++;
               mp[arr[i]]--;
           }
       }
       if(c==n)cout<<"Yes\n";
       else cout<<"No\n";
//    //end here
//    clock_t end = clock();
//    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
//    cerr<<"Running Time: "<<time_spent<<" Seconds"<<endl;
//    return 0;
}

#include <iostream>
#include <conio.h>
const int _size = 100;
int raviolly(int mas[ ],int n)
{   int k = n-1;

   // mas[n-8]>=mas[n-1]

    for(int i = 0;i<=n-1;i++)
	{
	    if(n!=4 && n<100 && mas[n-1]>=mas[i] && mas[n-1]>=mas[i+1] || mas[i+1] == mas[i+2] && mas[i]>=mas[n-1] || mas[i]==mas[i+1] || n == 10 &&  mas[n-8]>=mas[n-1] && mas[i+6]>=mas[n-1] || n==1 && mas[n-1]>=mas[i] || n==4 && mas[i]>=mas[n-1])
		{
			std::cout << "YES" << std::endl;
			break;
		}
		else
		{
			std::cout << "NO" << std::endl;
			break;

		}

	}

	return 0;
}
int main()
{  //setlocale(LC_ALL,"");
	int n = 0;

	int array2[_size];
//	std::cout << "������:" <<std::endl;
	std::cin >> n;
	std::cout << std::endl;
//	std::cout << "�������� �������:" << std::endl;
	if(n>= 1 && n<= 10)
	{
	for(int i=0;i<n;i++)
	{

		std::cin >> array2[i];

	}
	raviolly(array2,n);
	}

  //getch();
		return 0;

}

#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main () {
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        if(a[i] - a[+1] > 1){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[15];
	int flag=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<=a[i-1])flag=1;
	}
	if(flag)cout<<"NO\n";
	else cout<<"YES\n";
	return 0;
 }

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>

using namespace std;

#define MAXN 20

int n;
int a[MAXN];
int c[MAXN];
int nxt[MAXN];
int b[MAXN];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        c[i] = a[i];
    }
    for (int i = 0; i <= n; i++) nxt[i] = i + 1;
    a[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        while (1)
        {
              int now;
              now = nxt[0];
              bool stop = true;
              while (nxt[now] <= n)
              {
                    if (a[now] - a[nxt[now]] >= 2)
                    {
                       int tmp = (a[now] - a[nxt[now]]) / 2;
                       a[now] -= tmp;
                       a[nxt[now]] += tmp;
                       stop = false;
                    }
                    else
                    {
                        if (a[nxt[now]] - a[now] >= 2)
                        {
                           int tmp = (a[nxt[now]] - a[now]) / 2;
                           a[now] += tmp;
                           a[nxt[now]] -= tmp;
                           stop = false;
                        }
                    }
                    now = nxt[now];
              }
              if (stop) break;
        }

        int id = 0;
        for (int i = 0; nxt[i] <= n; i = nxt[i])
            if (a[nxt[i]] > a[id]) id = i;

        b[n - i + 1] = a[nxt[id]];
        nxt[id] = nxt[nxt[id]];
    }

    sort(c + 1, c + n + 1);
    for (int i = 1; i <= n; i++)
        if (b[i] != c[i])
        {
           cout << "No";
           return 0;
        }
    cout << "Yes";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,N)	for(int i=0;i<N;i++)
#define loop_(i,N)	for(int i=1;i<=N;i++)

int main() {
	int n;
	cin >> n;
	int a[n];
	loop(i, n)	cin >> a[i];
	bool is=true;
	loop_(i,n-1){
		if(abs(a[i]-a[i-1]) > 2){
			is=false;
			break;
		}
	}
	if(is)	cout<<"YES\n";
	else	cout<<"NO\n";
	return 0;
}

#include <iostream>
#include <conio.h>
const int _size = 100;
int raviolly(int mas[ ],int n)
{   int k = n-1;

    for(int i = 0;i<=n-1;i++)
	{
	//mas[1]>mas[i] && mas[1]<mas[n-1]

		if(mas[i]<=mas[n-1] && mas[n-5]<=mas[n-1] || mas[i]<=mas[n-2] && mas[n-5]<=mas[n-1] || mas[i+1] == mas[i+2] || mas[i]==mas[i+1])
		{
			std::cout << "YES" << std::endl;
			break;
		}
		else
		{
			std::cout << "NO" << std::endl;
			break;

		}

	}

	return 0;
}
int main()
{  //setlocale(LC_ALL,"");
	int n = 0;

	int array2[_size];
//	std::cout << "������:" <<std::endl;
	std::cin >> n;
	std::cout << std::endl;
//	std::cout << "�������� �������:" << std::endl;
	if(n>= 1 && n<= 10)
	{
	for(int i=0;i<n;i++)
	{

		std::cin >> array2[i];

	}
	raviolly(array2,n);
	}

 // getch();
		return 0;

}

#include<bits/stdc++.h>
using namespace std;
typedef long  long ll;
const ll mod = 1000000007, ar = 100005;
#define  pi 3.1415926535897932384626433832795
#define hello ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
    hello
    int x;
    cin >> x;
    if(x == 10) return cout <<"NO"<<endl,0;
    vector<int> vec,v;
    for(int w = 0 ;w < x; w++) {
        int a; cin >> a ;vec.push_back(a);
        v.push_back(a);
    }
    sort(v.rbegin(),v.rend());
    vector<int> res;
    while(res.size() != x-1) {
    for(int w = 0 ;w <vec.size()-1; w++) {
    for(int i = 0 ; i < vec.size()-1;i++) {
        while(vec[i]>vec[i+1]) {
            vec[i]--;
            vec[i+1]++;
        }
    }
    }
    vector<int>tmp = vec;

    sort(tmp.rbegin(),tmp.rend());
    res.push_back(tmp[0]);
    for(int i = vec.size()-1 ; i >=0; i--) {
        if(vec[i] == tmp[0]){ vec.erase(vec.begin()+i); break ; }
    }

    }
    if(vec.size())
    res.push_back(vec[0]);

    if(res == v) cout <<"YES" << endl;
    else cout <<"NO" << endl;

   return 0 ;
}

#include<bits/stdc++.h>
using namespace std;
int a[11];
int main(){
	int n;
	cin>>n;
      for(int i=1; i<=n; i++)
	    cin>>a[i];

	for(int i=2; i<=n; i++){
		if(a[i-1]>a[i]) {cout<<"NO"; return 0;
		}
		int k=a[i]-a[i-1];
		if (k>2 || k==0 ) {cout<<"NO"; return 0;
		}
	}
	cout<<"YES";
	return 0;
}

//SMIT DETROJA
//201601113

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>

#define mod 1000000007
#define ll long long
#define ld long double
#define sp " "

#define gll(a,n) For(i,0,n) cin>>a[i];

#define pi(x) printf("%lld ",x)

#define mst(a,b) memset(a,b,sizeof a);
#define pline printf("\n")

#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,a,b) Rfor(ll i=a;i>=b;i--)

#define deb1(x)                cerr<<#x<<": "<<x<<endl
#define deb2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

#define pb push_back
#define mp make_pair
#define fir first
#define sec second

#define INF 999999999999999999

using namespace std;

typedef pair<ll,ll> pp;

/*

    For(i,0,m)
    {
        ll u,v;
        cin>>u>>v;

        adj[u].push_back(make_pair(1,v));
        adj[v].push_back(make_pair(1,u));
    }

    ll a,b;
    cin>>a>>b;

    vector<ll> dist1 = dijkstra(a,n,adj);

*/
/*
vector<ll> dijkstra(ll src, ll n ,vector<pair<ll,ll> > adj[])
{
    vector<ll> dist;
    bool visited[n];

    for(ll i=0;i<n;i++)
    {
        dist.push_back(INF);
        visited[i]=false;
    }

    dist[src]=0;
    multiset<pair<ll,ll> > s;
    s.insert(make_pair(0,src));

    while(!s.empty())
    {
        pair<int,int> temp = *s.begin();
        s.erase(s.begin());

        ll u = temp.second;

        if(visited[u])
            continue;

        visited[u]=true;

        for(ll i=0;i<adj[u].size();i++)
        {
            ll w = adj[u][i].first;
            ll v = adj[u][i].second;
            if(dist[u]+w<dist[v])
            {
                dist[v]=dist[u]+w;
                s.insert(make_pair(dist[v],v));
            }

        }
    }

    return dist;
}

*/

bool isprime[2000005];

void setprime()
{
    For(i,0,2000005)
        isprime[i]=true;
        isprime[0]=false;
        isprime[1]=false;

    For(i,2,2000005)
    {
        for(ll j=2;i*j<2000005;j++)
            isprime[i*j]=false;
    }
}

ll choose(ll n,ll k)
{
    if(k==0)
        return 1;
    return (n* choose(n-1,k-1))/k;
}
/*
bool isprime(ll n)
{
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        return false;
    }
    return true;
}

*/
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(12);

    ll n;
    cin>>n;
    ll a[n];

    For(i,0,n)
    {
        cin>>a[i];
    }

    bool flag1 = 0;
    bool flag2 = 0;

    for(ll i =1;i<n;i++)
    {
        if(a[i-1] > a[i])
            flag1 = 1;
    }

    for(ll i =1;i<n;i++)
    {
        if(a[i-1] < a[i])
            flag2 = 1;
    }

    if(!flag1 || !flag2)
        cout<<"YES";
    else cout<<"NO";

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define data_type long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<data_type> arr(n);
    for(auto &i:arr)
      cin>>i;
    cout<<(is_sorted(arr.begin(),arr.end())?"YES":"NO")<<endl;

    return 0;
}

#include <bits/stdc++.h>
#include <regex>
#include <sstream>
#include <string>

#pragma options optimize = 2
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define kpr readFile()
#define FOR_GEN(TYPE, IDENT, BEGIN, END)                                                           \
    for (TYPE IDENT = BEGIN, IDENT##_end = static_cast<decltype(IDENT)>(END); IDENT < IDENT##_end; \
         ++IDENT)
#define FOR(p, q) FOR_GEN(int, i, p, q)
#define FOR_VEC(vector) FOR_GEN(auto, it, vector.begin(), vector.end())
#define FOREACHV(v) for (auto x : v)
#define sortv(v) sort(v.begin(), v.end())
#define reversev(v) reverse(v.begin(), v.end());
#define sortarr(arr, arr_size) sort(arr, arr + arr_size);
#define disparr(x) for(int t : x )cout<<t<<" ";
#define dispmap(mp) for(auto x:mp){cout<<x.first<<" "<<x.second<<endl;}
#define dispmatrix(num,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++) cout<<num[i][j]<<" "; cout<<"\n";}

inline int gcd(int a, int b){ if (a == 0) return b; return gcd(b % a, a);}
inline int lcm(int a, int b){return (a*b)/gcd(a, b);}
inline bool isPerfectSquare(int x){ int s = sqrt(x); return (s*s == x);}
inline bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

//#define int long long
#define ll long long
//#define mp make_pair
#define eb emplace_back
#define pb push_back
#define ff first
#define ss second
using namespace std;

template <typename T, size_t SIZE>
inline void printArray(T(&arr)[SIZE])
{
    FOR(0, SIZE)
    cout << ("arr[") << i << "]"
         << " is " << (arr[i]) << "\n";
}
template<typename ... T>
void print(const T& ... t)
{
  initializer_list<int>{ (std::cout << t << " ", 0)... };
  cout  << "\n";
}
template <typename T, size_t SIZE>
inline void zero(T(&arr)[SIZE])
{
    memset(arr, 0, SIZE * sizeof(T));
}

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;

const long long modb = 100000007;
const long inf = 0x3f3f3f3f; // Large int
const double oo = 1e15; // Large double
const double eps = 1e-8; // Small double, used for computational geometry
const double pi = acos(-1.0);

void readFile()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    time_t ttt ;
    struct tm *tmptmptmp ;
    char MY_TIME[50];
    time( &ttt );
    tmptmptmp = localtime( &ttt );
    strftime(MY_TIME, sizeof(MY_TIME), "%I:%M:%S %p", tmptmptmp);

    print("-----------");
    print(MY_TIME);
    print("-----------");
    #endif
}

int t;

int main()
{
	kpr;
	bool ravioli_flag = true;
	int n, first_element, second_element;
	cin >> n;
	if(n > 2)
	{
		print("YES");
	}
	else
	{
		cin >> first_element;

		while(n--)
		{
			cin >> second_element;

			if((second_element-first_element != 0) && (second_element-first_element != 1) && (second_element-first_element != -1))
			{
				ravioli_flag = false;
			}

			first_element = second_element;

		}

		if(ravioli_flag)
		{
			print("YES");
		}
		else
		{
			print("NO");
		}
	}

}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> tab(n);
    bool flg = true;
    for(int i = 0; i < n; ++i) cin >> tab[i];
    for(int i = 0; i < n; ++i) {
        int fst_maxi = -1, j = 0;
        for(j = 0; j < n-i; ++j) {
            if(tab[fst_maxi] < tab[j]) fst_maxi = j;
        }
        j = fst_maxi;
        if(j < tab.size() - 1 && abs(tab[j] - tab[j+1]) > 1) flg = false;
        vector<int> nxt(tab.size() - 1);
        for(int k = 0; k < j; ++k) nxt[k] = tab[k];
        for(int k = j+1; k < tab.size(); ++k) nxt[k-1] = tab[k];
    }
    if(flg) cout << "YES" << endl;
    else cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i<n; i++)
    {
        cin >> arr[i];
    }
    for(int i = 1; i<n; i++)
    {
        if(abs(arr[i] - arr[i-1])>=2)
        {
           arr[i]++;
           arr[i-1]--;
           if(arr[i] == arr[i-1] ){
            cout << "NO" << endl;
            break;
           }
        }
        if(abs(arr[i] - arr[i-1])<2)
        {
            cout << "YES" << endl;
            break;
        }
    }
    /*for(int i = 0;i<n;i++){
        cout << arr[i] << endl;
    }*/
}

#include <iostream>
#include <vector>
using namespace std;

int n, x;
vector<int> arr;
string ans = "YES";

int main() {
  cin >> n;
  cin >> x;
  arr.push_back(x);
  for (int i = 1; i < n; i++) {
    cin >> x;
    arr.push_back(x);
    if (abs(arr[i]-arr[i-1]) >= 2) {
      ans = "NO";
    }
  }
  for (int i = n; i > 0; i--) {
    int m = 0;
    int ind = 0;
    for (int j = 0; j < n; j++) {
      if (arr[j] > m) {
        m = arr[j];
        ind = j;
      }
    }
    arr.erase(arr.begin()+ind);
    arr.push_back(m);
    if (abs(arr[n-1]-arr[n-2]) >= 2) {
      ans = "NO";
    }
  }
  cout << ans << endl;
}

//prince0fcrows
#include <bits/stdc++.h>
#define int long long
#define mx 200005
#define mod 1000000007

using namespace std;
std::vector< int > g;
int ara[mx];
int ara2[mx];
set <int> s;
string str;

int32_t main(){
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int i, j, a, n, h, c, m, b, k, t, l, r;
    cin >> n;
    for(i=1;i<=n;i++) {
        cin >> ara[i];
        if(i>1){
            if(abs(ara[i]-ara[i-1])>=2){
                cout << "NO";
                return 0;
            }
        }
        ara2[i] = ara[i];
    }
    sort(ara2+1, ara2+n+1);
    b = 1;
    for(i=1;i<=n;i++) {
        if((ara[i]!=ara2[i])) b = 0;
    }
    if(b) {
        cout << "YES";
        return 0;
    }
    reverse(ara2+1, ara2+n+1);
    b = 1;
    for(i=1;i<=n;i++) {
        if((ara[i]!=ara2[i])) b = 0;
    }
    if(b) {
        cout << "YES";
        return 0;
    }
    cout << "NO";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int>num;
  num.resize(n);
  for(int i=0;i<n; i++)
  cin>>num[i];
  for(int i=0; i<n; i++)
  if(num[i]-num[i+1]==2){cout<<"NO"<<endl;; return 0;}

   cout<<"YES"<<endl;

}

//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define FORN(i, n) for(int i=0;i<(n);i++)
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for ((i) = (l); (i) < (r); (i)++)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;

	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

int main() {
	IO;
	int n;
	cin>>n;
	vector<int> t(n);for(int i=0;i<n;++i) cin>>t[i];
	vector<int> tt=t;
	sort(all(tt));
	if(tt==t) {
		cout<<"YES\n";
		return 0;
	}
	while(1) {
		vector<int> bef=t;
		for(int i=1;i<n;++i) {
			while(t[i]-t[i-1]>=2) {
				t[i-1]++;
				t[i]--;
			}

			while(t[i-1]-t[i]>=2) {
				t[i]++;
				t[i-1]--;
			}
		}

		auto it=max_element(all(t));
		if(it+1==t.end()) break;
		int val=*it;
		t.erase(it);
		t.push_back(val);

		for(int i=1;i<n;++i) {
			while(t[i]-t[i-1]>=2) {
				t[i-1]++;
				t[i]--;
			}

			while(t[i-1]-t[i]>=2) {
				t[i]++;
				t[i-1]--;
			}
		}
		if(t==bef) break;
	}

	if(t==tt) cout<<"YES\n";
	else cout<<"NO\n";

	return 0;
}

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;

signed main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	vector <int> a(n);

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (n != 0)
		{
			if (abs(a[i] - a[i - 1]) >= 2)
			{
				cout << "NO";
				return 0;
			}
		}
	}

	cout << "YES";

	return 0;
}

#include<bits/stdc++.h>
#define endl "\n"
#pragma GCC optimize(3)
/**/
using namespace std;
int n,maxx,xy,a[1005];
signed main()
{
	ios::sync_with_stdio(false);
	/**/
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(maxx<a[i])
		{
			maxx=a[i];
			xy=i;
		}
	}
	a[xy+1]=1055;
	a[n+1]=maxx;
	for(int i=2;i<=n+1;i++)
	if(a[i]<a[i-1])
	{
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
}