#P1713B. Optimal Reduction

    ID: 7824 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>constructive algorithmssortings*1000

Optimal Reduction

No submission language available for this problem.

Description

Consider an array aa of nn positive integers.

You may perform the following operation:

  • select two indices ll and rr (1lrn1 \leq l \leq r \leq n), then
  • decrease all elements al,al+1,,ara_l, a_{l + 1}, \dots, a_r by 11.

Let's call f(a)f(a) the minimum number of operations needed to change array aa into an array of nn zeros.

Determine if for all permutations^\dagger bb of aa, f(a)f(b)f(a) \leq f(b) is true.

^\dagger An array bb is a permutation of an array aa if bb consists of the elements of aa in arbitrary order. For example, [4,2,3,4][4,2,3,4] is a permutation of [3,2,4,4][3,2,4,4] while [1,2,2][1,2,2] is not a permutation of [1,2,3][1,2,3].

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1n1051 \leq n \leq 10^5) — the length of the array aa.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9) — description of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

For each test case, print "YES" (without quotes) if for all permutations bb of aa, f(a)f(b)f(a) \leq f(b) is true, and "NO" (without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

Input

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1n1051 \leq n \leq 10^5) — the length of the array aa.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9) — description of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, print "YES" (without quotes) if for all permutations bb of aa, f(a)f(b)f(a) \leq f(b) is true, and "NO" (without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

Samples

Sample Input 1

<div class="test-example-line test-example-line-even test-example-line-0">3</div><div class="test-example-line test-example-line-odd test-example-line-1">4</div><div class="test-example-line test-example-line-odd test-example-line-1">2 3 5 4</div><div class="test-example-line test-example-line-even test-example-line-2">3</div><div class="test-example-line test-example-line-even test-example-line-2">1 2 3</div><div class="test-example-line test-example-line-odd test-example-line-3">4</div><div class="test-example-line test-example-line-odd test-example-line-3">3 1 3 2</div><div class="test-example-line test-example-line-odd test-example-line-3"></div>

Sample Output 1

YES
YES
NO

Note

In the first test case, we can change all elements to 00 in 55 operations. It can be shown that no permutation of [2,3,5,4][2, 3, 5, 4] requires less than 55 operations to change all elements to 00.

In the third test case, we need 55 operations to change all elements to 00, while [2,3,3,1][2, 3, 3, 1] only needs 33 operations.