#K40052. Zigzag Sequence Checker
Zigzag Sequence Checker
Zigzag Sequence Checker
Given a sequence of integers, determine whether it is a zigzag sequence. A sequence is considered zigzag if the differences between consecutive elements alternate in sign. Specifically, if we denote \(d_i = a_{i} - a_{i-1}\) for \(i \geq 2\), then the sequence is zigzag if \(d_2, d_3, \dots, d_n\) alternate between positive and negative values. A sequence with a single element (or an empty sequence) is always considered zigzag.
For example, the sequence [1, 3, 2, 4, 3] is zigzag since \(3-1 > 0\), \(2-3 0\), and \(3-4 < 0\). On the other hand, [5, 1, 2, 3] is not a zigzag sequence because the differences do not alternate properly.
inputFormat
Input is read from STDIN. The first line contains an integer \(n\) indicating the size of the sequence. The second line contains \(n\) space-separated integers that form the sequence.
outputFormat
Output a single line to STDOUT containing either Yes if the sequence is a zigzag sequence or No otherwise.
## sample5
1 3 2 4 3
Yes