#K73707. Longest Even-Odd Subsequence

    ID: 34035 Type: Default 1000ms 256MiB

Longest Even-Odd Subsequence

Longest Even-Odd Subsequence

Given a sequence of integers, your task is to find the longest contiguous subsequence in which every pair of consecutive elements has the same parity (i.e., both are even or both are odd). In other words, for a subsequence S, for every consecutive pair Si and Si+1, either both should be even or both odd.

If there are multiple subsequences with the same maximum length, return the one that appears first in the sequence.

Note: A subsequence in this context is a contiguous segment of the original sequence.

Example: For the input sequence [5, 3, 8, 6, 2, 4, 7, 15], the longest even or odd contiguous subsequence is [8, 6, 2, 4] because 8, 6, 2 and 4 are all even and adjacent pairs satisfy the condition.

inputFormat

The first line of input contains an integer n representing the number of elements in the sequence. The second line contains n space-separated integers.

outputFormat

Output the longest contiguous subsequence (as space-separated integers) where every pair of consecutive elements has the same parity. If the input sequence is empty, output nothing.

## sample
8
5 3 8 6 2 4 7 15
8 6 2 4