#include <bits/stdc++.h>
void stderr_printf(const char *fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vfprintf(stderr, fmt, ap);
  va_end(ap);
}
using namespace std;
struct flist {
  int val;
  int pos;
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int i, j, k;
  int n;
  cin >> n;
  ;
  int stage = 0;
  bool ans = true;
  cin >> j;
  ;
  for (i = 0; i < n - 1; i++) {
    int cur;
    cin >> cur;
    ;
    if (stage == 0) {
      if (cur == j) {
        stage = 1;
      } else if (cur < j) {
        stage = 2;
      } else if (cur > j) {
        stage = 0;
      }
    } else if (stage == 1) {
      if (cur == j) {
        stage = 1;
      } else if (cur < j) {
        stage = 2;
      } else if (cur > j) {
        ans = false;
      }
    } else {
      if (cur >= j) {
        ans = false;
      }
    }
    j = cur;
  }
  if (ans) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}
