#CF2236E. 友好的礼物 / E. Friendly Gifts
友好的礼物 / E. Friendly Gifts
E. Friendly Gifts
Source: Codeforces 2236E
Contest: Codeforces Round 1103 (Div. 3)
Time limit: 3 seconds
Memory limit: 512 megabytes
Statement
Arseniy decided to make his friends Dabir and Egor happy. For this, he decided to give each of them an array of numbers of the same length. An array is called good if its elements can be rearranged so that for all the condition holds.
Arseniy wants Dabir and Egor to be able to play with these arrays. For this, the following conditions must be satisfied:
- Each of the given arrays is good.
- If you write one array after the other (in other words, concatenate them), the resulting array is also good.
Arseniy already has an array of length . He plans to cut both arrays from , that is, to choose two non-overlapping subsegments of the same length. Help Arseniy determine the maximum possible length of the resulting arrays.
Input
The first line contains a single integer — the number of test cases.
Then test cases follow.
The first line of each test case contains a single integer .
The second line contains integers .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the maximum possible length of the arrays.
Note
In the first sample, it is impossible to select arrays, so the answer is .
In the second sample, the maximum length of the selected arrays is . Arrays [] and [] can be selected.
In the fourth sample, the maximum length of the selected arrays is . You can select arrays [] and [].
In the fifth sample, the maximum length of the selected arrays is . One way to select arrays is [] and []. Other methods are arrays [] and [], [] and [], or [] and [].
Examples
7
1
1
2
1 2
3
2 1 1
4
2 1 4 3
5
1 2 4 5 3
6
3 2 1 6 5 4
10
1 1 2 3 4 1 6 5 7 8
0
1
1
2
1
3
4