#K5266. Remove Duplicate Nodes from a Linked List

    ID: 29359 Type: Default 1000ms 256MiB

Remove Duplicate Nodes from a Linked List

Remove Duplicate Nodes from a Linked List

You are given a linked list of n nodes, where each node contains an integer value. Your task is to remove all nodes that have duplicate values, leaving only the nodes with distinct values from the original list. The order of the remaining nodes should be preserved.

Formally, if a value appears more than once in the list, all instances of that value should be removed. Otherwise, if a value appears exactly once, it should be kept.

For example, given the list [1, 2, 3, 2, 1, 4], the output should be [3, 4] because both 1 and 2 appear more than once.

Note: You are required to read input from standard input (stdin) and output results to standard output (stdout). Any formulas in your explanation should be written in LaTeX format. For instance, the condition for a number v to be included is

[ \text{count}(v)=1 ]

where (\text{count}(v)) denotes the frequency of (v) in the list.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  • The first line contains an integer n representing the number of nodes in the linked list.
  • The second line contains n space-separated integers representing the node values.

It is guaranteed that n is positive or zero. If n = 0, then the second line will be empty.

outputFormat

Output the node values of the modified linked list in one line, separated by a single space. If there are no nodes left, output an empty line.

## sample
6
1 2 3 2 1 4
3 4

</p>