#include <bits/stdc++.h>
using namespace std;
int n, a[200005], valmax, vtmax, b[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > valmax) valmax = a[i], vtmax = i;
    b[a[i]]++;
  }
  if (b[valmax] > 1) {
    cout << "NO";
    return 0;
  }
  int l = vtmax - 1, r = vtmax + 1;
  int gt = valmax;
  a[0] = a[n + 1] = 1000006;
  while (1) {
    if (min(a[l], a[r]) >= gt) break;
    if (l > 0 && r < n + 1) {
      if (a[l] > a[r]) {
        if (a[l] < gt)
          gt = a[l], l--;
        else
          gt = a[r], r++;
      } else {
        if (a[r] < gt)
          gt = a[r], r++;
        else
          gt = a[l], l--;
      }
    } else if (r < n + 1) {
      if (a[r] < gt) gt = a[r], r++;
    } else {
      if (a[l] < gt) gt = a[l], l--;
    }
  }
  if (r == n + 1 && l == 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
