#C10793. Unique Sum of Array Elements

    ID: 40037 Type: Default 1000ms 256MiB

Unique Sum of Array Elements

Unique Sum of Array Elements

Given an integer T and for each test case an array of N integers, your task is to compute the sum of all the numbers that appear exactly once in the respective array.

More formally, for each test case, let the array be \(A = [a_1, a_2, \dots, a_N]\). Define the frequency \(f(x)\) as the number of occurrences of \(x\) in \(A\). You are required to compute the sum:

[ S = \sum_{\substack{x \in A \ f(x)=1}} x, ]

For instance, if the array is [1, 2, 2, 3, 4, 4, 5], the numbers that occur exactly once are 1, 3, and 5, and hence \(S = 1 + 3 + 5 = 9\).

You must read the input from stdin and write the output to stdout.

inputFormat

The input consists of multiple test cases. The first line of the input contains a single integer T denoting the number of test cases.

For each test case, the first line contains a single integer N denoting the number of elements in the array. The next line contains N space-separated integers representing the array elements.

For example:

3
7
1 2 2 3 4 4 5
5
1 1 1 1 1
6
2 2 -1 3 3 0

outputFormat

For each test case, output a single integer on a new line representing the sum of the unique numbers (i.e. the numbers that occur exactly once) in that test case's array.

For the sample input above, the output should be:

9
0
-1
## sample
3
7
1 2 2 3 4 4 5
5
1 1 1 1 1
6
2 2 -1 3 3 0
9

0 -1

</p>