#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long found = 0;
  long long flag = 0;
  for (long long i = 1; i < n; i++) {
    if (a[i] > a[i - 1]) {
      if (found != 0) {
        flag = 1;
        break;
      }
      found = 0;
    } else if (a[i] == a[i - 1]) {
      if (found == 2) {
        flag = 1;
        break;
      }
      found = 1;
    } else {
      found = 2;
    }
  }
  if (flag == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
