#C5127. Zigzag Number Checker
Zigzag Number Checker
Zigzag Number Checker
You are given a positive integer. Your task is to determine whether the number is a Zigzag Number.
A number is considered a Zigzag Number if for every three consecutive digits \(x, y, z\), the following condition holds:
- Either \(x z\) or \(x > y < z\)
If the number has fewer than three digits, it is not considered a Zigzag Number.
For example, given the number 121
, the digits form a zigzag pattern because \(1 1\), so the output should be YES
. Conversely, for the number 123
, the pattern is not zigzag (\(1 < 2 < 3\)), so the output should be NO
.
Read the input from standard input and output the result to standard output.
inputFormat
The input consists of a single line containing a positive integer \(n\).
Example:
121
outputFormat
Output a single line containing either YES
if \(n\) is a Zigzag Number, or NO
otherwise.
1
NO