#K1721. Good Array Challenge
Good Array Challenge
Good Array Challenge
Given an array of integers, determine if the array is "Good". An array is defined as Good if every contiguous subarray has an even sum. More formally, for any subarray \(A[i..j]\), the sum \(\sum_{k=i}^{j} A[k]\) must be even.
The input consists of two lines. The first line contains a single integer \(n\) which is the number of elements in the array. The second line contains \(n\) space-separated integers, which are the elements of the array.
Your task is to output YES
if the array is Good, and NO
otherwise.
inputFormat
The first line contains an integer \(n\) (\(1 \leq n \leq 10^5\)) denoting the number of elements in the array.
The second line contains \(n\) space separated integers \(A[1], A[2], \ldots, A[n]\) (\(|A[i]| \leq 10^9\)), which are the elements of the array.
outputFormat
Output a single line containing YES
if the array is Good (i.e. every contiguous subarray has an even sum), otherwise output NO
.
4
2 4 6 8
YES
</p>