A conservatory records the key index a student presses at every beat during a warm-up trill drill, in the order the presses happened. A drill only counts as a clean trill if, at every single step, the key index just pressed has different parity from the key index pressed immediately before it -- the student is supposed to alternate strictly between an even-numbered key and an odd-numbered key on every beat, with no exceptions.
Given the full recorded sequence of key indices, decide whether the drill was a clean trill.
Line 1: a single integer n -- the number of presses recorded. Line 2: n integers a_0 a_1 ... a_{n-1}, the key index pressed at each beat, in the order they were pressed.
Print "YES" if every pair of adjacent presses has different parity (this is automatically true when n = 1, since there is no adjacent pair to violate the rule), otherwise print "NO".
Example 1
Input
6 4 3 8 1 6 5
Expected
YES
Explanation
The parities of the sequence are even, odd, even, odd, even, odd -- every adjacent pair differs in parity all the way through, so the drill is a clean trill and the answer is YES.
Example 2
Input
5 2 4 6 1 3
Expected
NO
Explanation
The first two presses, 2 and 4, are both even, so parity fails to alternate at that very first step. The answer is NO regardless of what happens later in the sequence.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →