#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, a[N], pos[N];
int fen[N];
void upd(int pos, int val) {
  for (int i = pos; i < N; i |= i + 1) fen[i] += val;
}
int get(int r) {
  int ret = 0;
  for (int i = r; i > 0; i = (i & (i + 1)) - 1) ret += fen[i];
  return ret;
}
int get(int l, int r) {
  if (l > r) swap(l, r);
  return get(r) - get(l - 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  upd(pos[n], 1);
  for (int i = n - 1; i >= 1; i--) {
    int p = pos[i + 1];
    if (get(pos[i], p) != abs(pos[i] - p)) {
      puts("NO");
      return 0;
    }
    upd(pos[i], 1);
  }
  puts("YES");
}
