#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  int n;
  cin >> n;
  int i;
  int s[200005];
  int st = 0;
  bool flag = true;
  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (i == 0) {
      s[st++] = x;
    } else {
      if (s[st - 1] == x) {
        if (st > 1) st--;
      } else if (s[st - 1] > x) {
        s[st++] = x;
      } else {
        if (i % 2 == 0 && st == 1)
          s[st - 1] = x;
        else {
          flag = false;
          break;
        }
      }
    }
  }
  if (flag == false || st > 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
