#P1905F. Field Should Not Be Empty
Field Should Not Be Empty
No submission language available for this problem.
Description
You are given a permutation of length .
We call index good if for all it holds that and for all it holds that . We call the number of good indices in .
You can perform the following operation: pick distinct indices and and swap elements and .
Find the maximum value of after applying the aforementioned operation exactly once.
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Each test consists of multiple test cases. The first line of contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the permutation .
The second line of each test case contain distinct integers () — the elements of the permutation .
It is guaranteed that sum of over all test cases does not exceed .
For each test case, output a single integer — the maximum value of after performing the operation exactly once.
Input
Each test consists of multiple test cases. The first line of contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the permutation .
The second line of each test case contain distinct integers () — the elements of the permutation .
It is guaranteed that sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the maximum value of after performing the operation exactly once.
Note
In the first test case, and which is already maximum possible. But must perform the operation anyway. We can get by choosing and which makes .
In the second test case, we can transform into by choosing and . Thus .