#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int pre = INT_MIN;
  int cur;
  int state = 0;
  for (int i = 0; i < n; i++) {
    cin >> cur;
    if (cur > pre) {
      if (state == 0) {
        pre = cur;
        continue;
      } else {
        cout << "NO" << endl;
        return 0;
      }
    } else if (cur == pre) {
      if (state == 1) {
        pre = cur;
        continue;
      }
      if (state == 0) {
        pre = cur;
        state = 1;
        continue;
      }
      cout << "NO" << endl;
      return 0;
    } else {
      if (state == 2) {
        pre = cur;
        continue;
      }
      if (state < 2) {
        pre = cur;
        state = 2;
        continue;
      }
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
