#C987. Find All Duplicates in Array

    ID: 54010 Type: Default 1000ms 256MiB

Find All Duplicates in Array

Find All Duplicates in Array

You are given an array of n integers where each integer is in the range \(1 \leq a_i \leq n\). Your task is to find all elements that appear exactly twice in the array and print them in increasing order. If no element appears exactly twice, print -1.

Input Constraints:

  • The first line contains a single integer n, the number of elements in the array.
  • The second line contains n space-separated integers.

Output: Print all numbers that appear exactly twice in the array in strictly increasing order separated by a single space. If no such number exists, print -1.

Example:

Input:
8
4 3 2 7 8 2 3 1

Output: 2 3

</p>

inputFormat

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

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

outputFormat

The output should be printed to standard output. It contains the duplicate numbers that appear exactly twice in the array, printed in increasing order separated by spaces. If no such duplicates exist, output -1.

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