#C3873. Wiggle Sequence Verification

    ID: 47348 Type: Default 1000ms 256MiB

Wiggle Sequence Verification

Wiggle Sequence Verification

Given a sequence of n integers, determine whether it is a wiggle sequence. A sequence is called a wiggle sequence if the differences between successive numbers strictly alternate in sign. In other words, if we denote the sequence by \(a_1, a_2, \dots, a_n\), then after removing any zero differences, the consecutive differences \(d_i = a_{i+1} - a_i\) for \(1 \leq i < n\) must satisfy \(d_i \times d_{i+1} < 0\) for all valid indices.

Note that sequences with fewer than two elements are considered wiggle sequences. However, if the sequence contains only identical adjacent elements (yielding no nonzero differences), it is not considered a wiggle sequence.

The task is to implement a program that reads the sequence and outputs YES if it is a wiggle sequence, or NO otherwise.

inputFormat

The input is read from standard input (stdin). The first line contains a single integer (n) representing the number of elements in the sequence. The second line contains (n) space-separated integers.

outputFormat

Print a single line to standard output (stdout): YES if the sequence is a wiggle sequence or NO otherwise.## sample

6
1 7 4 9 2 5
YES