#CCBCHBAHAI0000023. Dãy đổi chiều theo quan hệ kề (Alternating Adjacent Comparisons)

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 a1,a2,…,ana_1,a_2,\ldots,a_n.

The sequence has alternating adjacent comparisons when the relation between consecutive elements alternates strictly between increasing and decreasing. Formally, for every ii with 2≤i≤n−12\le i\le n-1,

(ai−ai−1)(ai+1−ai)<0.(a_i-a_{i-1})(a_{i+1}-a_i)<0.

Equivalently, every interior position must satisfy exactly one of

ai−1<ai>ai+1a_{i-1}<a_i>a_{i+1}

or

ai−1>ai<ai+1.a_{i-1}>a_i<a_{i+1}.

Equal adjacent values violate the condition. For n≤2n\le2, 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 nn. The second line contains nn space-separated integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print YES if the sequence has alternating adjacent comparisons; otherwise print NO.

Subtasks

Subtask 1 (100 points): 1≤n≤2⋅1051\le n\le 2\cdot 10^5; ∣ai∣≤109|a_i|\le 10^9.

Example

Input

6
1 4 2 5 3 6

Output

YES

Explanation

The adjacent relations are <,>,<,>,<<,>,<,>,<, so the comparison direction alternates at every step.