#K7831. Find the Unique Element with Odd Occurrence
Find the Unique Element with Odd Occurrence
Find the Unique Element with Odd Occurrence
You are given an array of integers of size \(n\). Your task is to determine if there is a unique element that appears an odd number of times. If there is exactly one such element, output that element; otherwise, output \(-1\).
Formally, for an array \(A\) of length \(n\), find an integer \(x\) such that \(\text{occurrences}(x) \mod 2 = 1\) and no other integer satisfies this condition. If either no element or more than one element meets the criteria, return \(-1\).
The solution should handle input from standard input (stdin) and produce output to standard output (stdout).
inputFormat
The first line of input contains an integer \(n\) (the number of elements in the array). The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single integer: the unique element with an odd occurrence if it exists; otherwise, output \(-1\).
## sample5
1 2 2 1 3
3
</p>