#include <bits/stdc++.h>
using namespace std;
int n;
int a[1005];
int main() {
  scanf("%d", &n);
  int mid = 0;
  int start = 0;
  int end = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > mid) mid = a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == mid && (a[i - 1] != mid || i == 1)) start = i;
    if (a[i] == mid && (a[i + 1] != mid || i == n)) end = i;
  }
  int flag = 1;
  for (int i = start; i <= end; i++) {
    if (a[i] != mid) {
      flag = 0;
      break;
    }
  }
  for (int i = 1; i <= start - 2; i++) {
    if (a[i + 1] <= a[i]) {
      flag = 0;
      break;
    }
  }
  for (int i = end + 2; i <= n; i++) {
    if (a[i - 1] <= a[i]) {
      flag = 0;
      break;
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
}
