#CCBCHBAHAI0000045. Remove Duplicates (Remove Duplicates)
Remove Duplicates (Remove Duplicates)
Remove Duplicates (Remove Duplicates)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem
Given an integer array .
For each value appearing in the array, keep only its rightmost occurrence. The relative order among the retained elements must remain the same as in the original array.
An index is retained if and only if no equal value appears to its right:
If the retained indices are
print and
Input
The first line contains integer . The second line contains integers .
Output
Print the number of remaining elements on the first line. Print the resulting elements on the second line.
Subtask
Subtask 1 (100 points): ; .
Example
Input
6
1 5 5 1 6 1
Output
3
5 6 1
Explanation
For value , only the occurrence at index 5 remains; for value , only the occurrence at index 2 remains; value remains. The retained indices are , so the result is 5 6 1.