#JSUTFPC2025C. Incomplete Cauchy Sequence —— 不完全柯西序列

Incomplete Cauchy Sequence —— 不完全柯西序列

Statement

Timothy became fascinated with mathematical analysis when he was in second grade.

Since you will be dealing more with integers in algorithm competitions, you don't need a foundation in mathematical analysis to analyze the entire dense R\mathbb{R} but rather the discrete Z\mathbb{Z}, ensuring that the given data xx is definitely within the range of 1×109x1×109-1\times 10^9 \leqslant x \leqslant 1\times 10^9.

Let {xn}\left\{x_n\right\} be a sequence (where nNn \in \mathbb{N}). For each nn, define the distance between adjacent terms as dn=xnxn+1d_n = |x_n - x_{n+1}|. If the sequence dn{d_n} is (non-monotonically) decreasing [1], then xn{x_n} is called an Incomplete Cauchy sequence. For example, the general formula for the sequence {xn}\left\{ x_n \right\} is xn=n,nNx_n=-n, n\in \mathbb{N}, that is, {xn}=[1,2,3,,n]\left\{ x_n \right\}=[-1,-2,-3,\cdots,-n] is an Incomplete Cauchy sequence; an array of the form [1,100,50,75,75,75,75,,75][1,100,50,75,75,75,75,\cdots,75] is also an Incomplete Cauchy sequence; whereas [1,100,300,300,300,,300][1,100,300,300,300,\cdots,300] is not, because d1=99,d2=100,d3=200d_1=99, d_2=100, d_3=200 does not satisfy the above definition.

Given an array aa of length nn, determine whether this array can be a continuous subsequence of an Incomplete Cauchy sequence [2].

Input

The first line contains an integer nn representing the length of the array, where 3n2×1053\leqslant n\leqslant 2\times 10^5.

The second line contains nn integers separated by spaces, representing each element aia_i in the array aa, where 1×109ai1×109-1\times 10^9 \leqslant a_i\leqslant 1\times 10^9.

Output

If the array is a possible continuous subsequence of an Incomplete Cauchy sequence, output Yes. Otherwise, output No. The output is not case-sensitive. For example, YES and yEs are both considered as Yes.

Samples

3
-1 -2 -3
Yes
5
1 100 50 75 75
Yes
5
1 100 300 300 300
No

  1. A sequence {xn}\left\{ x_n \right\} is (non-monotonically) decreasing if and only if iN\forall i\in \mathbb{N} satisfies xixi+1x_i\geqslant x_{i+1}. ↩︎

  2. A sequence s1s_1 is a continuous subsequence of another sequence s2s_2 if and only if there exists an interval [,r][\ell, r] such that s1s_1 is exactly equal to the subsequence of s2s_2 within that interval. ↩︎