Given a click log of student numbers and K seats, keep each student's last click, then print the first K distinct students in that order.
Easy3QueueHash mapSimulationInterviewNo attempts yetTime limit1sMemory limit256 MBEvery semester students register for courses through the university information system. The moment registration opens, a large number of students click at once and the server load grows, so the university runs a registration load management system with the following rules.

The table above shows six students registering for an algorithms course with three seats. When the button is deactivated, the earlier entries of any student who clicked more than once are deleted, so only each student's last click remains. The first three students of that cleaned list are then taken. The rightmost column of the table shows the result. Write a program that prints the students who succeeded in registering under these rules.
Input is given on standard input and consists of a single test case. The first line contains the number of seats K (1≤K≤100,000) and the length L (1≤L≤500,000) of the waiting list that records the click order. Each of the next L lines contains the student number of a student who clicked the button, in click order. A student number consists of 8 digits and may start with 0.
Use standard output. After the rules are applied, print the student number of every student who succeeded in registering, one per line, in the order the registrations are processed. If fewer than K distinct students clicked the button, print all of them.