14849 - Simulated bookshelf management system(linked list)   

Description

Redo Problem 14804 using linked list representation.

This time, since the number of books n and the number of shelf positions m are no longer restricted, we can attempt larger inputs.

Constraints:
0 < n ≤ 1024,
0 < m ≤ 128

Input

The first line of input contains n, the number of books, and m, the number of shelf positions.
The books are numbered from 1 to n.

The second line contains a sequence of integers between 1 and n, representing the order in which we read the books.
The program must process all input until EOF.

Ex. 255 8
1 2 3 4 5 6 7 8 6 10 23 7 4

Output

The output consists of m integers, representing the books currently on the shelf from left to right.
If a shelf position does not contain a book, output 0 for that position.

Ex. 3 5 8 6 10 23 7 4

Sample Input  Download

Sample Output  Download




Discuss