#include<bits/stdc++.h>
using namespace std;
//https://www.geeksforgeeks.org/check-given-array-can-represent-level-order-traversal-binary-search-tree/
struct df{
    int d;
    int mn,mx;
};
bool checkforlevelorder(int arr[],int n){
if(n == 0){
    return true;
}
queue<df>q;
int i = 0;
df newnode;
newnode.d = arr[i++];
newnode.mn = INT_MIN;
newnode.mx = INT_MAX;
q.push(newnode);
while(i != n && !q.empty()){
    df temp = q.front();
    q.pop();
    if(i < n && arr[i] > temp.mn && arr[i] < temp.mx){
        df tempnode;
        tempnode.d = arr[i++];
        tempnode.mn = temp.mn;
        tempnode.mx = temp.d;
        q.push(tempnode);
    }
    if(i < n && arr[i] > temp.mn && arr[i] < temp.mx){
        df tempnode;
        tempnode.d = arr[i++];
        tempnode.mn = temp.d;
        tempnode.mx = temp.mx;
        q.push(tempnode);
    }  

}
if(i == n){return true;}
return false;
}
int main(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0;i < n;i++){cin>> arr[i];}
    if(checkforlevelorder(arr,n)){cout << "yes";}
    else{cout << "No"<< endl;}
    return 0;
}