#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (auto &x : v) {
    cin >> x;
  }
  vector<long long> v2;
  for (long long i = 1; i < n; i++) {
    if (v[i] < v[i - 1]) {
      v2.emplace_back(-1);
    } else if (v[i] > v[i - 1]) {
      v2.emplace_back(1);
    } else {
      v2.emplace_back(0);
    }
  }
  bool f1 = 0;
  bool f2 = 0;
  bool f3 = 0;
  for (auto &x : v2) {
    if (x == 1) {
      if (f2 || f3) {
        cout << "NO";
        return 0;
      }
      f1 = 1;
    } else if (x == 0) {
      if (f3) {
        cout << "NO";
        return 0;
      }
      f2 = 1;
    } else {
      f3 = 1;
    }
  }
  cout << "YES";
  return 0;
}
