#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, t;
int a[200001];
string gg() {
  int i = x - 1, j = x + 1;
  int f = 0;
  while (i != -1 or j != n) {
    if (a[i] < a[x] and a[j] < a[x])
      if (a[i] > a[j])
        a[x] = a[i], --i;
      else
        a[x] = a[j], ++j;
    else if (a[i] < a[x])
      a[x] = a[i], --i;
    else if (a[j] < a[x])
      a[x] = a[j], ++j;
    else {
      return "NO";
    }
  }
  while (i != -1) {
    if (a[i] < a[x])
      a[x] = a[i], --i;
    else
      return "NO";
  }
  while (j != n) {
    if (a[j] < a[x])
      a[x] = a[j], ++j;
    else
      return "NO";
  }
  return "YES";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  m = -1;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    if (a[i] > m) m = a[i], x = i;
  }
  int f = 0, i = x - 1, j = x + 1;
  cout << gg();
  return 0;
}
