#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int cir = 0;
  bool ans = true;
  int now;
  for (int i = 0; i < n; i++) {
    if (!i) {
      scanf("%d", &now);
      continue;
    }
    int temp;
    scanf("%d", &temp);
    if (temp > now) {
      if (cir != 0) {
        ans = false;
      }
      now = temp;
    } else if (temp == now) {
      if (cir == 0) {
        cir = 1;
      } else if (cir == 1) {
      } else {
        ans = false;
      }
    } else {
      if (cir == 0 || cir == 1) {
        cir = 2;
      }
    }
    now = temp;
  }
  if (ans)
    printf("YES\n");
  else
    printf("NO\n");
}
