#C5406. Sum of Unique Elements

    ID: 49052 Type: Default 1000ms 256MiB

Sum of Unique Elements

Sum of Unique Elements

Given a list of integers, your task is to compute the sum of all unique elements in the list. An element is considered unique if it appears exactly once. Formally, for a list \( A = [a_1, a_2, \ldots, a_n] \), you need to calculate:

$$ S = \sum_{\substack{1 \le i \le n \\ \text{frequency}(a_i) = 1}} a_i $$

If there is no unique element, the answer is 0.

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains a single integer \( n \), the number of elements in the list.
  • The second line contains \( n \) space-separated integers representing the elements of the list.

outputFormat

Output a single integer to standard output (stdout) which is the sum of the unique elements in the list.

## sample
7
1 2 2 3 4 4 5
9