fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*;
  4.  
  5. import static java.lang.Math.*;
  6. import static java.lang.Character.*;
  7. import static java.util.Arrays.*;
  8. import static java.util.Collections.*;
  9. import static java.math.BigInteger.*;
  10.  
  11. class C {
  12. static final char PROB = C.class.getSimpleName().charAt(0);
  13. static final boolean PRAC = false;
  14.  
  15. static final int INF = 1 << 20;
  16. static final int[] di = { -1, 0, 0, 1 };
  17. static final int[] dj = { 0, -1, 1, 0 };
  18. static Scanner sc = new Scanner(System.in);
  19.  
  20. final int N;
  21. final int[] c;
  22.  
  23. public C() {
  24. N = sc.nextInt();
  25. c = new int[N];
  26. for(int i = 0; i < N; i++)
  27. c[i] = sc.nextInt();
  28. }
  29.  
  30. public String solve() {
  31. int min = Integer.MAX_VALUE;
  32. int sum = 0;
  33. int xor = 0;
  34. for(int i = 0; i < N; i++) {
  35. min = min(min, c[i]);
  36. sum += c[i];
  37. xor ^= c[i];
  38. }
  39. return xor == 0 ? "" + (sum - min) : "NO";
  40. }
  41.  
  42. public static void main(String... args) {
  43. // large();
  44. int T = Integer.parseInt(sc.nextLine());
  45. for (int t = 1; t <= T; t++) {
  46. System.err.printf("Case #%s%n", t);
  47. System.out.printf("Case #%s: %s%n", t, new C().solve());
  48. }
  49. System.err.println("done.");
  50. }
  51.  
  52. public static void small() {
  53. String in = PROB + "-small" + (PRAC ? "-practice" : "-attempt" + 0) + ".in";
  54. String out = PROB + "-small.out";
  55. try {
  56. if (!PRAC)
  57. for (int i = 1; new File(PROB + "-small" + "-attempt" + i + ".in").exists(); i++)
  58. in = PROB + "-small" + "-attempt" + i + ".in";
  59. System.setOut(new PrintStream(out));
  60. } catch (Exception e) {
  61. e.printStackTrace();
  62. System.exit(0);
  63. }
  64. sc = new Scanner(System.in);
  65. }
  66.  
  67. public static void large() {
  68. String in = PROB + "-large" + (PRAC ? "-practice" : "") + ".in";
  69. String out = PROB + "-large.out";
  70. try {
  71. System.setOut(new PrintStream(out));
  72. } catch (Exception e) {
  73. e.printStackTrace();
  74. System.exit(0);
  75. }
  76. sc = new Scanner(System.in);
  77. }
  78.  
  79. private static void debug(Object... os) {
  80. System.err.println(deepToString(os));
  81. }
  82. }
  83.  
Success #stdin #stdout 0.08s 213888KB
stdin
2
5
1 2 3 4 5
3
3 5 6
stdout
Case #1: NO
Case #2: 11