#include <bits/stdc++.h>
const int MOD = 1000000007;
const int LIMIT = 1e5 + 10;
using namespace std;
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  int ara[n];
  for (int i = 0; i < n; i++) cin >> ara[i];
  int x = 0;
  int y = n - 1;
  while (ara[x] < ara[x + 1]) {
    x++;
  }
  while (ara[y] < ara[y - 1]) {
    y--;
  }
  for (int i = x + 1; i <= y; i++)
    if (ara[x] != ara[i]) {
      cout << "NO\n";
      return 0;
    }
  cout << "YES\n";
  return 0;
}
