#C11078. Longest Special Subarray
Longest Special Subarray
Longest Special Subarray
Given an array of integers of length \( n \), a special subarray is defined as a contiguous segment of the array that contains at least one even number and at least one odd number. It can be proven that if the array contains both even and odd numbers, then the longest special subarray is the entire array.
Your task is to determine the length of the longest special subarray. If the array does not contain both even and odd numbers, output 0.
The problem can be summarized by the following logic:
[ \text{answer} = \begin{cases} n, & \text{if the array contains at least one even and one odd number};\ 0, & \text{otherwise.} \end{cases} ]
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \( n \) denoting the number of elements in the array.
- The second line contains \( n \) space-separated integers.
outputFormat
Output a single integer on standard output (stdout) - the length of the longest special subarray. If there is no subarray containing both even and odd numbers, output 0.
## sample7
1 2 3 4 5 6 7
7