#C1244. Find Duplicates in an Array

    ID: 41867 Type: Default 1000ms 256MiB

Find Duplicates in an Array

Find Duplicates in an Array

Given an array of integers, your task is to find and print all the numbers that occur more than once in the array. Each duplicate number should be printed only once, in the order of their first appearance.

For example, if the array is [1, 2, 2, 3, 3, 3, 4], the output should be 2 3 because 2 and 3 are the only numbers that appear more than once.

The task is to correctly identify the duplicate elements using efficient methods such as hash maps. Ensure that the input is read from standard input (stdin) and the output is written to standard output (stdout).

inputFormat

The first line contains a single integer n representing the number of elements in the array. The second line contains n space-separated integers. Formally, the array is given as \(a_1, a_2, \ldots, a_n\).

\(0 \le n \le 10^5\) and each integer \(a_i\) satisfies \( -10^9 \le a_i \le 10^9 \).

outputFormat

Print the duplicate elements separated by a single space in the order of their first occurrence. If no duplicates exist, print an empty line.

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

</p>