#K52587. Distinct Numbers in a Linked List

    ID: 29342 Type: Default 1000ms 256MiB

Distinct Numbers in a Linked List

Distinct Numbers in a Linked List

Given a singly linked list, remove all nodes with duplicate values such that only nodes with distinct values remain. The resulting list should be sorted in ascending order.

You are given an integer \(n\) on the first line, representing the number of nodes, followed by a line containing \(n\) space-separated integers representing the values of the nodes in the linked list. Your task is to output all distinct numbers (i.e. numbers that appear exactly once in the input) in sorted order.

Formally, let \(f(x)\) denote the frequency of the number \(x\) in the list. You need to output all \(x\) satisfying \(f(x)=1\) in increasing order.

inputFormat

The input is given via stdin and has the following format:

n
v1 v2 ... vn

Where:

  • \(n\) is the number of nodes in the linked list.
  • \(vi\) (for \(1 \le i \le n\)) is the value at the \(i\)-th node.

outputFormat

The output should be produced via stdout as a single line containing the distinct numbers in sorted order, separated by a single space. If there are no distinct numbers, output an empty line.

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