Split into Odd or Split into Even!
InterviewTime limit1sMemory limit1024 MB
Given a sequence of positive integers, decide whether it can be split into an odd number of sets with odd sums, or an even number of sets with even sums.
Problem
Given a sequence of length made of positive integers, you must split the sequence into one or more sets by grouping consecutive elements. When splitting, you may choose one of two methods: split into odd or split into even. Every element of the sequence must belong to exactly one of the sets.
-
Split into odd
- The sum of the elements in each set must be odd.
- The sequence must be split into an odd number of sets.
-
Split into even
- The sum of the elements in each set must be even.
- The sequence must be split into an even number of sets.
Determine whether the sequence can be split into one or more sets using one of these methods.
Input
The first line contains the length of the sequence .
The second line contains the elements of the sequence, separated by spaces.
Output
If the sequence can be split into one or more sets using one of the given methods, print 1. Otherwise, print 0.
Hint
The input is large, so use fast I/O. Examples for common languages are below.
- C++: When using
cinandcout, callcin.tie(nullptr); ios::sync_with_stdio(false);once before any input or output. Use'\n'instead ofendlfor line breaks. - Java: Use
BufferedReaderandBufferedWriter. - Python3, PyPy3: Use
sys.stdin.readline().rstrip()instead ofinput().