A warehouse runs two independent stocktake audits over the same shelf, and every scanned item tag code is written into one combined log. Each code appears in that log either once (only one audit spotted the item) or exactly twice (both audits independently confirmed it) — no code appears more than twice. As a lightweight integrity check, the audit system computes the bitwise XOR of every tag code that appears exactly twice in the log. Given the combined log, output that checksum. If no code appears exactly twice, output 0.
Line 1: an integer n, the number of entries in the log.
Line 2: n space-separated integers, the logged tag codes in the order they were scanned.
Print a single integer: the bitwise XOR of every tag code that appears exactly twice in the log (0 if none does).
Example 1
Input
6 5 7 5 9 7 2
Expected
2
Explanation
Code 5 appears twice, code 7 appears twice, while 9 and 2 each appear once. The checksum is 5 XOR 7 = 2.
Example 2
Input
3 1 2 3
Expected
0
Explanation
Every code appears exactly once, so no code is confirmed twice and the checksum is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →