#include <bits/stdc++.h>
const double pi = 4.0 * atan(1.0);
const double e = exp(1.0);
const int maxn = 3e5 + 8;
const long long mod = 1e9 + 7;
const unsigned long long base = 1e7 + 7;
using namespace std;
long long a[maxn];
long long ma = 0;
int main() {
  int n;
  scanf("%d", &n);
  int x, y;
  int tot = 0;
  bool is = 1;
  while (n--) {
    scanf("%d", &a[++tot]);
    ma = max(ma, a[tot]);
    if (tot >= 2 && a[tot] == a[tot - 1]) {
      tot -= 2;
    }
    if (tot >= 2 && a[tot] > a[tot - 1]) {
      is = 0;
    }
  }
  if (is && (tot == 0 || (tot == 1 && a[tot] == ma))) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
