#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  string p = "!";
  for (int i = 0, a; i < N && cin >> a; i++) p.push_back(a % 2 ? '1' : '0');
  p.push_back('*');
  for (int i = 1; i < p.size(); i++) {
    int cnt = 0;
    int l = i - 1, r = i;
    while (p[l--] == p[r++]) cnt++;
    p.erase(l + 2, 2 * cnt);
    i -= cnt;
  }
  cout << (p.size() < 4 ? "YES" : "NO") << endl;
  return 0;
}
