#CCBCHBAHAI0000023. Dãy đổi chiều theo quan hệ kề (Alternating Adjacent Comparisons)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy đổi chiều theo quan hệ kề (Alternating Adjacent Comparisons)
Dãy đổi chiều theo quan hệ kề (Alternating Adjacent Comparisons)
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem
Given an integer sequence .
The sequence has alternating adjacent comparisons when the relation between consecutive elements alternates strictly between increasing and decreasing. Formally, for every with ,
Equivalently, every interior position must satisfy exactly one of
or
Equal adjacent values violate the condition. For , there is no interior position to check, so the sequence is considered valid.
Determine whether the given sequence satisfies the condition.
Input
The first line contains integer . The second line contains space-separated integers .
Output
Print YES if the sequence has alternating adjacent comparisons; otherwise print NO.
Subtasks
Subtask 1 (100 points): ; .
Example
Input
6
1 4 2 5 3 6
Output
YES
Explanation
The adjacent relations are , so the comparison direction alternates at every step.