#K86062. Sum of Unique Values
Sum of Unique Values
Sum of Unique Values
You are given T test cases. For each test case, the first integer is N which denotes the number of elements in the sequence, followed by N integers. Your task is to compute the sum of the unique integers in each sequence. An integer is considered unique if it appears exactly once in the sequence.
Formally, for a sequence \(a_1, a_2, \dots, a_N\), calculate:
\(\sum_{\substack{1 \le i \le N \\ \text{frequency}(a_i)=1}} a_i\)
Output one result per test case on a separate line.
inputFormat
The input is read from stdin
and has the following format:
- The first line contains an integer T, the number of test cases.
- Each of the following T lines represents a test case and begins with an integer N (the number of elements), followed by N space-separated integers.
outputFormat
For each test case, output a single line on stdout
that contains the sum of the integers that appear exactly once in the test case.
3
5 1 2 2 3 4
4 1 1 1 1
6 5 5 5 4 3 2
8
0
9
</p>