Three Copies of Every Packet
A weather balloon talks to its ground station over a noisy radio link, so its firmware sends every telemetry packet three times. Copies of different packets can end up interleaved in any order. During the last flight, a firmware bug made the balloon send exactly one packet only once. Every other packet was sent and received exactly three times.
The ground station's receiver is a small microcontroller. It sees the packet IDs as a stream, in the order they arrived, and has to report the ID that was received only once. It has very little RAM, so the memory limit for this problem is 16 MB.
Input
The first line contains n (1 ≤ n ≤ 5·10^5, n mod 3 = 1), the number of received packets.
Each of the next n lines contains one packet ID a_i (−9223372036854775808 ≤ a_i ≤ 9223372036854775807, so any signed 64-bit integer).
Exactly one ID occurs once in the stream. Every other ID that occurs in the stream occurs exactly three times.
Output
Print the ID that occurs exactly once, as a signed decimal integer.
Notes
In the first example, IDs 1001 and 42 each arrive three times and 7 arrives once.
In the second example, IDs 0, −1 and 3 each arrive three times, so the answer is −6. IDs can be negative, and the answer can be negative too.