A community festival hands out numbered wristbands to attendees entering a raffle. Because the wristband printer occasionally double-prints a stack, a small number of codes end up issued to two different attendees, while every other code is issued to exactly one attendee. Under the raffle's tie-break rule, only attendees holding a code that was issued to exactly one person are eligible for the grand prize, and the prize pool is split according to the sum of those unique codes.
Given the list of wristband codes actually issued (in the order they were handed out), compute the sum of every code that appears in the list exactly once.
The first line contains a single integer n, the number of wristbands issued.
The second line contains n space-separated integers a_1 ... a_n, the wristband codes.
Print a single integer: the sum of every code that occurs exactly once among a_1 ... a_n. If no code is unique, print 0.
1 <= n <= 1001 <= a_i <= 100Example 1
Input
4 1 2 3 2
Expected
4
Explanation
Codes 1 and 3 each appear exactly once (sum 4); code 2 appears twice so it is excluded from the sum. Output is 4.
Example 2
Input
5 1 1 1 1 1
Expected
0
Explanation
The only code present is 1, and it appears five times, so no code is unique. Output 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 →