#K49947. Odd-Even Neighbor Arrangement
Odd-Even Neighbor Arrangement
Odd-Even Neighbor Arrangement
You are given a list of positive integers. Your task is to determine whether it is possible to rearrange these numbers such that the sum of every adjacent pair is odd. Note that the sum of two numbers is odd if and only if one of them is even and the other is odd. Therefore, a necessary and sufficient condition for such an arrangement is that the list contains an equal number of odd and even numbers.
If such an arrangement exists, output POSSIBLE
; otherwise, output IMPOSSIBLE
.
inputFormat
The input consists of two lines:
- The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of positive integers.
- The second line contains n space-separated positive integers.
outputFormat
Output a single string: POSSIBLE
if it is possible to rearrange the numbers so that the sum of every adjacent pair is odd; otherwise, output IMPOSSIBLE
.
4
1 2 3 4
POSSIBLE