#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
using namespace std;
int a[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(time(0));
  int f = 0, i, n, mx = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == a[i - 1] && a[i] != mx) {
      cout << "NO"
           << "\n";
      return 0;
    }
    if (a[i - 1] > a[i]) f = 1;
    if (a[i - 1] < a[i] && f == 1) {
      cout << "NO"
           << "\n";
      return 0;
    }
  }
  cout << "YES"
       << "\n";
  return 0;
}
