#C10153. Odd Occurrence Finder

    ID: 39327 Type: Default 1000ms 256MiB

Odd Occurrence Finder

Odd Occurrence Finder

You are given a list of positive integers. Your task is to find and output all the integers that occur an odd number of times in the list. The output list must be sorted in ascending order.

For example, if the input list is [1, 2, 3, 2, 3, 1, 3], the integer 3 appears 3 times (which is an odd number), so the output is [3]. Similarly, if the input is [4, 5, 6, 4, 6, 6, 5, 5], the numbers 5 and 6 appear an odd number of times, hence the output is [5, 6].

Note: If no number occurs an odd number of times, output an empty line.

The problem can be formally defined as follows. Given an array of positive integers:

$$\text{Given } arr = [a_1, a_2, \dots, a_n], \text{ find all } x \text{ such that } \left|\{ i : a_i = x\}\right| \equiv 1 \; (\bmod\; 2), $$

and output them in ascending order.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains an integer n denoting the number of elements in the list.
  • The second line contains n space-separated positive integers.

outputFormat

Print the sorted list of integers that appear an odd number of times. The output should be written to stdout. If no number meets the criteria, print an empty line.

Separate the numbers by a single space.

## sample
7
1 2 3 2 3 1 3
3

</p>