#C12972. Remove Duplicates from List

    ID: 42458 Type: Default 1000ms 256MiB

Remove Duplicates from List

Remove Duplicates from List

You are given a sequence of integers. Your task is to remove duplicate values while preserving the order of their first occurrence.

More formally, given an array \( A \) of \( n \) integers, construct a new array \( B \) containing only the first occurrence of each integer from \( A \), in the same order as they appear in \( A \).

For example:

  • If \( A = [1, 3, 3, 5, 1, 3, 7, 9, 5] \) then \( B = [1, 3, 5, 7, 9] \).
  • If \( A = [1, 2, 3, 1, 2, 3] \) then \( B = [1, 2, 3] \).

Implement a program that reads the sequence, processes it, and outputs the deduplicated list.

inputFormat

The input consists of two lines:

  1. The first line contains a single integer \( n \) which is the number of elements in the list.
  2. The second line contains \( n \) space-separated integers.

outputFormat

Output a single line containing the deduplicated list, with each number separated by a single space.

## sample
9
1 3 3 5 1 3 7 9 5
1 3 5 7 9