#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 200031;
int n, ar[N], shit;
set<pair<int, pair<int, int> > > S;
set<pair<int, pair<int, int> > >::iterator it;
int l_ptr[N], r_ptr[N];
int get_val(int ps) {
  if (ps < 1 || ps > n) return 2e9;
  return ar[ps];
}
pair<int, pair<int, int> > run_merge(pair<int, pair<int, int> > p1,
                                     pair<int, pair<int, int> > p2,
                                     int new_val) {
  S.erase(p1);
  S.erase(p2);
  r_ptr[p1.second.first] = p2.second.second;
  l_ptr[p2.second.second] = p1.second.first;
  ar[p1.second.first] = ar[p2.second.second] = new_val;
  S.insert(make_pair(p1.first ^ p2.first,
                     make_pair(p1.second.first, p2.second.second)));
  return make_pair(p1.first ^ p2.first,
                   make_pair(p1.second.first, p2.second.second));
}
pair<int, pair<int, int> > get_pair(int ps) {
  return make_pair(1 - (r_ptr[ps] - ps) % 2, make_pair(ps, r_ptr[ps]));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    ar[i] %= 2;
  }
  int cur_l = 1;
  for (int i = 1; i <= n; i++) {
    if (i > 1 && ar[i] != ar[i - 1]) {
      S.insert(make_pair(1 - ((i - 1) - cur_l) % 2, make_pair(cur_l, i - 1)));
      l_ptr[i - 1] = cur_l;
      r_ptr[cur_l] = i - 1;
      cur_l = i;
    }
  }
  S.insert(make_pair(1 - (n - cur_l) % 2, make_pair(cur_l, n)));
  l_ptr[n] = cur_l;
  r_ptr[cur_l] = n;
  while (S.size() > 1) {
    it = S.begin();
    pair<int, pair<int, int> > P = (*it);
    if (P.second.second % 2 == P.second.first % 2) {
      shit = 1;
    }
    if (P.second.first != 1) {
      pair<int, pair<int, int> > temp = get_pair(l_ptr[P.second.first - 1]);
      P = run_merge(get_pair(l_ptr[P.second.first - 1]), P, 0);
    }
    if (P.second.second != n) {
      run_merge(P, get_pair(P.second.second + 1), 0);
    }
  }
  if (shit) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}
