Pen switches
A teacher writes a list of numbers: odd numbers in green, even numbers in red. Count how many times she has to switch from the green pen to the red pen while writing the list in order.
Reported in: Cognizant GenC (memory-based)
Input
First line: N. Second line: N integers.
Output
The number of green-to-red switches.
Constraints
1 ≤ N ≤ 10^5.
Example 1
Input:
6
1 2 3 5 4 6
Output:
2Example 2
Input:
3
2 4 1
Output:
0Hint: Count positions where an odd number is immediately followed by an even number.