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


bool func(vector<int>& v,bool flag)
{
    int u = 0;
    int i=1;
    int curr = 1;
    vector<int> f(v.size(),-1);
    f[0] = 0;

    if(flag)
    {
        u++;
        f[0] = 1;
    }

    for(;i<v.size();i++)
    {
        if(f[i-1]==1 && v[i]==v[i-1])
        {
            f[i]=1;
            u++;
        }
        else if(f[i-1]==1 && v[i]>v[i-1]) f[i]=0;
        else if(f[i-1]==1 && v[i]<v[i-1]) return 0;
        else if(f[i-1]==0 && v[i]==v[i-1]) f[i]=0;
        else if(f[i-1]==0 && v[i]>v[i-1]) return 0;
        else if(f[i-1]==0 && v[i]<v[i-1])
        {
            f[i]=1;
            u++;
        }
    }


    int mx = *max_element(v.begin(),v.end());
    int mn = *min_element(v.begin(),v.end());
    int n;

    if(mx==v.size()-1 && mx==mn) n = v.size();
    else n = mx;

    if(u>n) return false;


    if(n==u && n==v.size()) return true;
    else if(n==u) return false;
    else if((n-u)*2+u<=v.size()) return true;
    return false;
}


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

    int N;
    cin >> N;
    vector<int> v(N);
    for(int i=0;i<N;i++) cin >> v[i];
    bool flag = func(v,0)||func(v,1);

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
//
//    vector<int> v = {3,3,3,3,3};
//    cout << func(v,0) << endl;

    return 0;
}
