#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  int input;
  for (int i = 0; i < n; i++) {
    cin >> input;
    a[i].first = input;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  int l = a[n - 1].second, r = a[n - 1].second;
  bool check = true;
  for (int i = n - 1; i >= 0; i--) {
    if (abs(a[i].second - l) > 1 && abs(a[i].second - r) > 1) {
      check = false;
      break;
    }
    if (abs(a[i].second - l) <= 1) l = min(a[i].second, l);
    if (abs(a[i].second - r) <= 1) r = max(a[i].second, r);
  }
  if (check)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
