-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplit.java
More file actions
41 lines (39 loc) · 1.06 KB
/
Split.java
File metadata and controls
41 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.HashMap;
import java.util.Scanner;
public class Split {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for (int i = 0; i < t; i++) {
int n=sc.nextInt();
HashMap<Integer,Integer> h=new HashMap<>();
int nn=2*n;
for (int j = 0; j < nn; j++) {
int x=sc.nextInt();
h.put(x,h.getOrDefault(x,0)+1);
}
int res=0;
int y=0;
int y4=0;
for(int x:h.keySet()) {
int s=h.get(x);
if (s%2 != 0) {
res += 1;
y += h.get(x);
}
else if (s % 4 == 0) {
y4++;
}
else{
res+=2;
}
}
if(y4%2==0) res+=(y4*2);
else{
res+=((y4-1)*2);
if(y>=2) res+=2;
}
System.out.println(res);
}
}
}