#C12335. Remove Duplicates from a List

    ID: 41751 Type: Default 1000ms 256MiB

Remove Duplicates from a List

Remove Duplicates from a List

Given a list of integers, your task is to remove duplicate elements while preserving the original order of appearance.

The input is provided via standard input. The first token is an integer \(n\) which represents the number of subsequent integers. The next \(n\) tokens form the list. Your program must validate the input in the following ways:

  • If the first token is not a valid integer, print: Error: Input must be a list.
  • If any of the \(n\) tokens are not valid integers, print: Error: List must contain only integers.

If the input is valid, remove any duplicate integers from the list while preserving the order of their first occurrence, and output the resulting list as space-separated values to standard output.

Formally, given a list \(L = [l_1, l_2, \dots, l_n]\), produce a list \(R\) where \(R\) contains the first occurrence of each integer from \(L\).

inputFormat

The input is read from standard input in the following format:

n
x1 x2 x3 ... xn

Where:

  • \(n\) is the number of elements in the list.
  • \(x1, x2, \dots, xn\) are the elements of the list.

outputFormat

Output to standard output the de-duplicated list as space‑separated integers. In case of any input validation error, output the corresponding error message exactly as specified.

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