#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
long long A[100005 * 10];
long long B[100005 * 10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long tst = 1;
  for (long long tt = 1; tt <= tst; tt++) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> A[i];
    ;
    long long pos1 = 1, pos2 = n;
    for (long long i = 1; i <= n; i++) {
      pos1 = i;
      if (A[i] >= A[i + 1]) break;
    }
    for (long long i = n; i >= pos1; i--) {
      pos2 = i;
      if (A[i] >= A[i - 1]) break;
    }
    sort(A + pos1, A + pos2 + 1);
    if (A[pos1] != A[pos2])
      cout << "NO" << '\n';
    else
      cout << "YES" << '\n';
  }
  return 0;
}
