#K1341. Equalizing Sequence via Parity Condition
Equalizing Sequence via Parity Condition
Equalizing Sequence via Parity Condition
You are given a sequence of n integers. Your task is to determine whether it is possible to make all elements of the sequence equal by performing a specific operation (the details of which are abstracted away). It turns out that the answer depends solely on the parity of the first and the last elements of the sequence.
More formally, let the sequence be \(a_1, a_2, \ldots, a_n\). It can be shown that all elements can be made equal if and only if the following condition holds:
\[
(a_n - a_1) \bmod 2 = 0.
\]
If the condition is satisfied, output YES
; otherwise, output NO
.
Note: You must read input from stdin
and write your answer to stdout
.
inputFormat
The first line of input contains an integer n (number of elements in the sequence). The second line contains n space-separated integers representing the sequence.
Constraints:
- 1 ≤ n ≤ 105
- Each element is an integer.
outputFormat
Output a single line with YES
if it is possible to make all elements equal, or NO
otherwise.
5
4 3 3 4 4
YES