#include #include using namespace std; int main() { int n; cin >> n; int b[200005]; for(int i = 0; i < n; i++) { cin >> b[i]; } b[n++] = 0; int h[200005]; int d[200005]; stack st; for(int i = 0; i < n; i++) { d[i] = b[i]; if(i) { d[i] -= d[i - 1]; } if(st.empty() && d[i] == 0) { h[i] = 0; continue; } if(st.size() && b[i] % 2 == b[st.top()] % 2) { h[i] = h[st.top()]; st.pop(); } else { st.push(i); h[i] = st.size(); } if(h[i] > b[i]) { cout << "No" << endl; return 0; } } if(h[n - 1] != 0) { cout << "No" << endl; return 0; } for(int i = 0; i < n - 1; i++) { if(b[i] > b[i + 1]) { cout << "No" << endl; return 0; } b[i + 1] -= b[i]; } if(b[n - 1]) { cout << "No" << endl; return 0; } cout << "Yes" << endl; }