#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9 + 7);
int n, a[1005];
bool isT[3] = {false, false, false};
int main() {
  cin >> n;
  for (int i = 0; i < int(n); i++) cin >> a[i];
  int i = 1, j = n - 2;
  while (i < n && a[i] > a[i - 1]) i++;
  while (j >= 0 && a[j] > a[j + 1]) j--;
  if (i >= j) {
    if (i == j)
      cout << (a[i] >= a[i - 1] && a[i] >= a[i + 1] ? "YES" : "NO") << endl;
    else
      cout << "YES" << endl;
  } else {
    if (a[i] < a[i - 1] || a[j] < a[j + 1]) {
      cout << "NO" << endl;
      return 0;
    }
    for (int k = i + 1; k < int(j + 1); k++)
      if (a[k] != a[k - 1]) {
        cout << "NO" << endl;
        return 0;
      }
    cout << "YES" << endl;
  }
  return 0;
}
