#include <bits/stdc++.h>
using namespace std;
long long n, x;
stack<long long> arr;
bool nol, satu;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    x %= 2;
    if (!arr.empty() && arr.top() == x) {
      arr.pop();
    } else {
      arr.push(x);
    }
  }
  while (!arr.empty()) {
    if (arr.top() == 0)
      nol = true;
    else
      satu = true;
    arr.pop();
  }
  if (nol && satu)
    cout << "NO\n";
  else
    cout << "YES\n";
}
