Under construction

Still being built. Things may change

Solitaire

Interview

Time limit2sMemory limit1024 MB

Summary
Find the length of the longest subsequence of the cards that is strictly increasing and alternates between even and odd numbers.
Level

Easy3 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

Sometimes Rick remembers that he is no longer young and prefers to rest from endless adventures. One early evening he wanted to play solitaire, but he had no ordinary playing cards. After searching the house, Rick found nn cards with natural numbers written on them and decided to build a solitaire layout from them.

Since the cards were not made for solitaire, Rick invented his own rules. To make up for the lack of suits, he wants the cards to alternate so that adjacent cards have different remainders when divided by two. In the laid-out sequence the numbers must alternate as even, odd, even, and so on. Also, the number on each card must be strictly less than the number on the next card.

Rick shuffled the deck carefully and started playing. Morty, watching him, wondered what is the longest sequence of cards that satisfies Rick's conditions that can be taken from this deck. Help him find out.

Input

The first line contains an integer nn (1≤n≤1001 \le n \le 100), the number of cards.

The second line contains nn natural numbers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9), the numbers written on the cards.

Output

Print one number, the length of the longest sequence that can be obtained from the given deck.

Hint

In the first sample, in the best case Rick draws the cards in the same order as given. The sequence 1,2,31, 2, 3 satisfies the condition.

In the second sample, the sequence 1,2,3,81, 2, 3, 8 fits.

Examples2

  1. Example 1

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

    Input
    6
    3 2 8 1 4 3
    
    Expected output
    4