#C10633. Difference between the Largest Even and the Smallest Odd
Difference between the Largest Even and the Smallest Odd
Difference between the Largest Even and the Smallest Odd
You are given an array of integers. Your task is to compute the difference between the largest even number and the smallest odd number in the array.
If either an even number or an odd number does not exist in the array, then output -1
.
Mathematically, if we denote the largest even number as \(L\) and the smallest odd number as \(O\), you need to compute \(L - O\). The input should be read from standard input and the result printed to standard output.
inputFormat
The input consists of two lines.
The first line contains an integer n representing the number of elements in the array.
The second line contains n space-separated integers.
outputFormat
Print a single integer which is the difference between the largest even number and the smallest odd number, or -1 if the array does not contain at least one even and one odd number.
## sample6
4 6 8 9 15 17
-1