#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[105], b[105], cnt = 0;
  scanf("%d", &n);
  b[0] = -1;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    if (a[i] != b[cnt]) {
      b[++cnt] = a[i];
    }
  }
  b[++cnt] = -1;
  int flag = 0, f;
  for (int i = 1; i < cnt; i++) {
    if (b[i] > b[i - 1] && b[i] > b[i + 1]) {
      flag++;
      if (flag == 1) f = b[i];
    }
  }
  if (flag == 0 || flag > 1) {
    printf("NO\n");
    return 0;
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != f && a[i] == a[i + 1] && i + 1 < n) c = -1;
  }
  if (c == -1)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
