#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  unsigned long long a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  stack<unsigned long long> s;
  for (int i = 0; i < n; ++i) {
    a[i] %= 2;
    if (s.empty() || s.top() != a[i])
      s.push(a[i]);
    else
      s.pop();
  }
  bool all1 = true, all0 = true;
  while (!s.empty()) {
    all0 = all0 && (s.top() == 0);
    all1 = all1 && (s.top() == 1);
    s.pop();
  }
  bool ans = all0 || all1;
  cout << (all0 || all1 ? "YES" : "NO") << endl;
  return 0;
}
