#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> a;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    cout << "YES";
    return 0;
  }
  int i = 0;
  while (i < n - 1 && a[i + 1] > a[i]) i++;
  int j = n - 1;
  while (j > 0 && a[j] < a[j - 1]) j--;
  while (i < j) {
    if (a[i] != a[j]) {
      cout << "NO";
      return 0;
    }
    i++;
  }
  cout << "YES";
}
