#C4832. Find Element Between Odd and Even
Find Element Between Odd and Even
Find Element Between Odd and Even
You are given a sequence of integers. Your task is to find the first element that appears after the first odd number and before the first even number in the sequence.
Formally, let the sequence be \(a_1, a_2, \dots, a_n\). Find the element \(a_j\) such that:
- There exists an index \(i < j\) with \(a_i\) odd, and \(a_i\) is the first odd number in the sequence.
- \(a_{j+1}\) exists and is the first even number which appears after an odd number.
If there is no even number following any odd number, or if any condition is not satisfied, output \(-1\).
Note: The search stops at the first even number that occurs after an odd number. The element immediately preceding this even number is considered the answer.
inputFormat
The input is provided via standard input. The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.
For example:
4 1 3 2 4
outputFormat
Output a single integer to standard output: the element found as described. If no such element exists, output \(-1\).
## sample4
1 3 2 4
3
</p>