forked from livingstream/codejam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
67 lines (59 loc) · 1.52 KB
/
Solution.java
File metadata and controls
67 lines (59 loc) · 1.52 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import static java.util.Arrays.deepToString;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
private static void debug(final Object...objs) {
System.out.println(deepToString(objs));
}
private String solveCase() throws IOException {
final int N = nextInt();
final int[] C = new int[N];
int sum = 0;
for (int i = 0; i < N; i++) {
final int c = nextInt();
sum ^= c;
C[i] = c;
}
if (sum != 0) return "NO";
long res = 0;
Arrays.sort(C);
for (int i = 1; i < N; i++)
res += C[i];
return String.valueOf(res);
}
private void solve() throws IOException {
final int testNumber = nextInt();
for (int test = 0; test < testNumber; test++) {
final String result = "Case #" + (test + 1) + ": " + solveCase();
pw.println(result);
System.out.println(result);
}
}
private BufferedReader br;
private PrintWriter pw;
private StringTokenizer st;
int nextInt() throws IOException {
return Integer.parseInt(next());
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public static void main(final String[] args) throws IOException {
new Solution().run();
}
private void run() throws IOException {
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter("output.txt");
solve();
br.close();
pw.flush();
pw.close();
}
}