#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1002];
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    if (n == 1) {
      cout << "YES" << endl;
      continue;
    }
    int f = 0, de[1001], j = 0;
    for (int i = 0; i < n - 1;) {
      if (a[i] < a[i + 1]) {
        while (a[i] < a[i + 1] && i < n) i++;
        de[j++] = 1;
      }
      if (a[i] == a[i + 1]) {
        while (a[i] == a[i + 1] && i < n) i++;
        de[j++] = 2;
      }
      if (a[i] > a[i + 1]) {
        while (a[i] > a[i + 1] && i < n) i++;
        de[j++] = 3;
      }
    }
    if (j == 1 && (de[0] == 1 || de[0] == 2 || de[0] == 3)) f = 1;
    if (j == 2 && ((de[0] == 1 && de[1] == 2) || (de[0] == 1 && de[1] == 3) ||
                   (de[0] == 2 && de[1] == 3)))
      f = 1;
    if (j == 3 && de[0] == 1 && de[1] == 2 && de[2] == 3) f = 1;
    if (f)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
