Algorithm


B. All Distinct
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sho has an array a consisting of n integers. An operation consists of choosing two distinct indices i and j and removing ai�� and aj�� from the array.

For example, for the array [2,3,4,2,5][2,3,4,2,5], Sho can choose to remove indices 11 and 33. After this operation, the array becomes [3,2,5][3,2,5]. Note that after any operation, the length of the array is reduced by two.

After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible.

More formally, the array after Sho has made his operations respects these criteria:

  • No pairs such that (i<j�<�) and ai=aj��=�� exist.
  • The length of a is maximized.

Output the length of the final array.

Input

The first line contains a single integer t (1t1031≤�≤103) — the number of test cases.

The first line of each test case contains a single integer n (1n501≤�≤50) — the length of the array.

The second line of each test case contains n integers ai�� (1ai1041≤��≤104) — the elements of the array.

Output

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.

Example
input
Copy
4
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000
output
Copy
2
1
2
4
Note

For the first test case Sho can perform operations as follows:

  1. Choose indices 11 and 55 to remove. The array becomes [2,2,2,3,3,3][2,2,3,3][2,2,2,3,3,3]→[2,2,3,3].
  2. Choose indices 11 and 44 to remove. The array becomes [2,2,3,3][2,3][2,2,3,3]→[2,3].
The final array has a length of 22, so the answer is 22. It can be proven that Sho cannot obtain an array with a longer length.

For the second test case Sho can perform operations as follows:

  1. Choose indices 33 and 44 to remove. The array becomes [9,1,9,9,1][9,1,1][9,1,9,9,1]→[9,1,1].
  2. Choose indices 11 and 33 to remove. The array becomes [9,1,1][1][9,1,1]→[1].
The final array has a length of 11, so the answer is 11. It can be proven that Sho cannot obtain an array with a longer length.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    int arr[n];
    set<int> st;
    for(int i = 0; i < n; i++){
      cin>>arr[i];
      st.insert(arr[i]);
    }
    int sub = n - st.size();
    if(sub%2){
      sub++;
    }
    cout<<n-sub<<endl;


  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000

Output

x
+
cmd
2
1
2
4
Advertisements

Demonstration


Codeforcess Solution 1692-BB. All Distinct ,C++, Java, Js and Python , 1692-B,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+