C. Make It Good

C. Make It Good
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array a consisting of  integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array  is a subarray consisting several first elements: the prefix of the array a of length k is the array (0kn).

The array b of length m is called good, if you can obtain a non-decreasing array () from it, repeating the following operation  times (initially,  is empty):

  • select either the first or the last element of ð‘, remove it from , and append it to the end of the array  . 

For example, if we do 4 operations: take , then  , then  and at last , then   becomes [b3,b4,…,bm−3]and ð‘=[𝑏1,𝑏𝑚,𝑏𝑚−1,𝑏2].

Consider the following example: b=[1,2,3,4,4,2,1]. This array is good because we can obtain non-decreasing array c from it by the following sequence of operations:

  1. take the first element of , so ð‘=[2,3,4,4,2,1], 𝑐=[1]; 
  2. take the last element of , so ð‘=[2,3,4,4,2], 𝑐=[1,1]; 
  3. take the last element of , so ð‘=[2,3,4,4], 𝑐=[1,1,2]; 
  4. take the first element of , so ð‘=[3,4,4], 𝑐=[1,1,2,2]; 
  5. take the first element of , so ð‘=[4,4], 𝑐=[1,1,2,2,3]; 
  6. take the last element of , so ð‘=[4], 𝑐=[1,1,2,2,3,4]; 
  7. take the only element of , so ,  —  is non-decreasing. 

Note that the array consisting of one element is good.

Print the length of the shortest prefix of  to delete (erase), to make  to be a good array. Note that the required length can be .

You have to answer  independent test cases.

Input

The first line of the input contains one integer  () — the number of test cases. Then   test cases follow.

The first line of the test case contains one integer 𝑛 (1≤𝑛≤2⋅105) — the length of 𝑎. The second line of the test case contains 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an (1≤𝑎𝑖≤2⋅1051≤ai≤2⋅105), where 𝑎𝑖ai is the 𝑖-th element of 𝑎.

It is guaranteed that the sum of n does not exceed 2105 (n2105).

Output

For each test case, print the answer: the length of the shortest  prefix of elements you need to erase from  to make it a good array.

Example
input
Copy
5
4
1 2 3 4
7
4 3 3 8 4 5 2
3
1 1 1
7
1 3 1 4 5 3 2
5
5 4 3 2 3
output
Copy
0
4
0
2
3
Note

In the first test case of the example, the array  is already good, so we don't need to erase any prefix.In the second test case of the example, the initial array  is not good. Let's erase first  elements of , the result is . The resulting array is good. You can prove that if you erase fewer number of first elements, the result will not be good.

Comments

Popular posts from this blog

How to pass parameters in webhook?

Access and modify all the resources of our Wiki.js using WikiJS API

Fahrenheit to Celsius