Under construction

Still being built. Things may change

Unstable Sequence

Interview

Time limit1.5sMemory limit1024 MB

Summary
Pick the most numbers in their original order so that every two adjacent picked numbers have an odd sum, meaning their parities alternate.
Level

Easy3 of 10

Topics
Array, Greedy
Solved
No attempts yet

Problem

NN natural numbers are lined up from left to right. The ii-th number from the left (1≤i≤N1 \le i \le N) is AiA_i.

You may pick any number of these numbers. You cannot pick none, so you must pick at least one.

Let kk be the number of picked numbers, and let the picked numbers be B1,B2,⋯ ,BkB_1, B_2, \cdots, B_k in order. They keep the order they had in the original row.

For example, take N=5N = 5 and A=[3,1,4,1,5]A = [3, 1, 4, 1, 5]. If you pick the 2nd, 4th, and 5th numbers from the left, then k=3k = 3 and B=[1,1,5]B = [1, 1, 5].

Call BB an unstable sequence if the sum of every pair of adjacent numbers is odd: the sum of B1B_1 and B2B_2, the sum of B2B_2 and B3B_3, and so on. If k=1k = 1, then BB counts as an unstable sequence.

For example, if k=6k = 6 and B=[1,4,3,2,5,4]B = [1, 4, 3, 2, 5, 4], then the adjacent sums are 5, 7, 5, 7, and 9. All are odd, so BB is an unstable sequence.

Also, if k=1k = 1 and B=[2]B = [2], then BB is an unstable sequence because k=1k = 1.

But if k=4k = 4 and B=[4,5,1,2]B = [4, 5, 1, 2], the first adjacent sum is 9 (odd), but the sum of 5 and 1 is 6 (even). Some adjacent sums are not odd, so BB is not an unstable sequence.

You must pick numbers so that BB is an unstable sequence, and you want to pick as many numbers as possible. Write a program that finds the maximum number of numbers you can pick.

For example, take A=[4,5,1,2]A = [4, 5, 1, 2]. Picking all four numbers gives B=[4,5,1,2]B = [4, 5, 1, 2], which is not an unstable sequence, so four numbers are not possible. Picking the 1st, 3rd, and 4th numbers gives B=[4,1,2]B = [4, 1, 2]. The sums 4 + 1 = 5 and 1 + 2 = 3 are both odd, so BB is an unstable sequence. Three is the maximum.

Input

The first line contains NN.

The second line contains A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N in order, separated by spaces.

Output

Print the answer on the first line.

Constraints

  • Every given number is a natural number.
  • 1≤N≤300 0001 \le N \le 300\,000
  • 1≤Ai≤100 0001 \le A_i \le 100\,000 (1≤i≤N1 \le i \le N)

Examples3

  1. Example 1

    Input
    4
    4 5 1 2
    
    Expected output
    3
    
  2. Example 2

    Input
    3
    3 2 3
    
    Expected output
    3
    
  3. Example 3

    Input
    5
    3 3 3 3 3
    
    Expected output
    1