Help me in solving MISSP problem

My issue

I’m printing the right values and my code compiles and runs correctly, but it doesn’t give the correct answer when I hit submit.

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.Collections;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
		Scanner scnr = new Scanner(;
		int T = scnr.nextInt();
		int N = scnr.nextInt(); 
		ArrayList<Integer> arr = new ArrayList<Integer>(); 
		HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>(); 
		for (int i = 0; i<N; i++) {
		for (Integer item : arr) {
	        if (!hash.containsKey(item)) {
	            hash.put(item, 1);
	        } else {
		        hash.put(item, hash.get(item)+1);
        for (Integer elem : hash.keySet()) {
            if (hash.get(elem) == 1) {

Problem Link: MISSP Problem - CodeChef

if (hash.get(elem) == 1)
You got problem in that line,
Make a variable which store xor of numbers(initialize it with zero) which don’t exists in pair, then rewrite that line as
if (hash.get(elem) % 2 ==1) xor^=elem
Then you don’t have to print element you take xor of elements,
And at last print no. of elements( basically xor) that doesn’t exists in pair