You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.
For any segment of the array starting at position $$$l$$$ and ending at position $$$r$$$ ($$$1 \le l \le r \le n$$$), let $$$m(l, r)$$$ denote the minimum value in that segment, and $$$M(l, r)$$$ denote the maximum value in that segment. Formally,
$$$$$$ \begin{aligned} m(l,r) &= \min(a_l, a_{l+1}, \ldots, a_r),\\ M(l,r) &= \max(a_l, a_{l+1}, \ldots, a_r).\\ \end{aligned} $$$$$$
You may perform the following operation any number of times (possibly zero):
Determine whether you can make the array $$$a$$$ non-decreasing$$$^{\text{∗}}$$$ by performing a series of operations.
$$$^{\text{∗}}$$$An array $$$[b_1, b_2, \ldots, b_k]$$$ is considered non-decreasing iff $$$b_1 \le b_2 \le \ldots \le b_k$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the length of the array $$$a$$$.
The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.
For each test case, print "YES" if you can make the array $$$a$$$ non-decreasing, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
641 1 2 332 1 355 4 3 2 164 1 2 3 3 654 2 4 2 463 3 1 5 5 2
YESYESNOYESNONO
For the first testcase, the array is already non-decreasing. Hence, output YES.
For the second testcase, let us choose $$$l = 1$$$ and $$$r = 2$$$. We can see that $$$\min(2, 1) + \max(2, 1) = 2 + 1 = 3$$$, which is odd. Thus, after simultaneously assigning $$$a_i := a_{3-i}$$$ for all $$$1 \le i \le 2$$$, we get $$$a = [1, 2, 3]$$$, which is non-decreasing.
Consider the fourth testcase,
For the fifth testcase, note that it is impossible to choose indices $$$l$$$ and $$$r$$$ satisfying the conditions. Hence, output NO.