Determine whether a given integer sequence forms a straight arithmetic progression with step 2.
Problem
You are given a sequence of integers. Your task is to determine whether the sequence is a valid “Straight <<A>>” sequence: each next value should differ from the previous one by exactly 2, and the sequence should progress consistently throughout.
In other words, for every adjacent pair, the difference must be the same, and that common difference must be 2.
Return whether the sequence satisfies this condition.
Input Format
- The first line contains an integer
n— the length of the sequence. - The second line contains
nintegersa1, a2, ..., an.
Output Format
- Print
YESif the sequence is a straight progression with common difference2. - Otherwise, print
NO.
Constraints
1 <= n <= $10^{5}$- Values fit in 32-bit signed integers
Example 1
Input
4 1 3 5 7
Output
YES
Explanation
Every adjacent difference is 2, so the sequence is valid.
Example 2
Input
4 1 4 6 8
Output
NO
Explanation
The first difference is 3, so the sequence does not use a consistent step of 2.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.