#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[200010];
int main() {
  int n = read();
  int fen = 0, gu = 0;
  for (int i = 1; i <= n; i++) a[i] = read();
  bool ok = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1]) ok = 0;
  }
  if (ok == 0) {
    printf("NO");
    return 0;
  }
  for (int i = 2; i <= n - 1; i++) {
    if (a[i - 1] < a[i] && a[i] > a[i + 1])
      fen++;
    else if (a[i - 1] > a[i] && a[i + 1] > a[i])
      gu++;
  }
  if (fen <= 1 && gu == 0)
    printf("YES");
  else
    printf("NO");
  return 0;
}
