2438.Chat Order

Time Limit: 1s Memory Limit: 256MB

Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.

Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.

Input Format(From the terminal/stdin)

The first line contains integer n (1 \le n \le 200000)- the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.

Output Format(To the terminal/stdout)

Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.

Sample Input 1

Copy
4
alex
ivan
roman
ivan
 \n
    \n
    \n
     \n
    \n

Sample Output 1

Copy
ivan
roman
alex
    \n
     \n
    \n

Sample Input 2

Copy
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
 \n
     \n
     \n
         \n
     \n
     \n
         \n
     \n
     \n

Sample Output 2

Copy
alina
maria
ekaterina
darya
     \n
     \n
         \n
     \n

Hints

In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
ivan alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
roman ivan alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
ivan roman alex

Submit

请先 登录

© 2025 FAQs