#C4682. Remove Duplicate Elements from a List
Remove Duplicate Elements from a List
Remove Duplicate Elements from a List
You are given a list of integers. Your task is to remove all duplicate elements from the list while preserving the order of the remaining elements.
For example, given the list:
1 2 3 2 4 1
the output should be:
1 2 3 4
The problem can be formally described as follows:
Let \(A = [a_1, a_2, \dots, a_n]\) be the input list. Produce a list \(B\) by removing duplicate occurrences of any integer from \(A\) such that if \(a_i\) appears before \(a_j\) in \(A\) and \(a_i = a_j\), only the first occurrence is kept.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) (\(0 \leq n \leq 10^5\)) representing the number of elements in the list.
- The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) which form the list.
outputFormat
Print a single line to standard output (stdout) containing the elements of the list after removing duplicates, in the original order. The elements should be separated by a single space. If the list is empty, output nothing.
## sample6
1 2 3 2 4 1
1 2 3 4