#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using seika = string;
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}
void solve() {
  int n;
  cin >> n;
  akari<int> as(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    as[i] &= 1;
  }
  stack<int> st;
  int now = -1, cur = 0;
  as.push_back(-1);
  for (int a : as) {
    if (a == now) {
      cur++;
    } else {
      if (cur & 1) {
        if (!st.empty() && st.top() == now) {
          st.pop();
        } else if (now != -1) {
          st.push(now);
        }
      }
      now = a;
      cur = 1;
    }
  }
  if (st.size() < 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  solve();
  return 0;
}
