欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1234B1.Social Network (easy version)
Social Network (easy version)
The only difference between easy and hard versions are constraints on and .
You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals ).
Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.
You (suddenly!) have the ability to see the future. You know that during the day you will receive messages, the -th message will be received from the friend with ID ().
If you receive a message from in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.
Otherwise (i.e. if there is no conversation with on the screen):
- Firstly, if the number of conversations displayed on the screen is , the last conversation (which has the position ) is removed from the screen.
- Now the number of conversations on the screen is guaranteed to be less than and the conversation with the friend is not displayed on the screen.
- The conversation with the friend appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.
Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all messages.
Input
The first line of the input contains two integers and ( — the number of messages and the number of conversations your smartphone can show.
The second line of the input contains integers (), where is the ID of the friend which sends you the -th message.
Output
In the first line of the output print one integer () — the number of conversations shown after receiving all messages.
In the second line print integers , where should be equal to the ID of the friend corresponding to the conversation displayed on the position after receiving all messages.
Note
In the first example the list of conversations will change in the following way (in order from the first to last message):
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- .
In the second example the list of conversations will change in the following way:
- ;
- ;
- ;
- ;
- ;
- and then the list will not change till the end.
Samples
7 2
1 2 3 2 1 3 2
2
2 1
10 4
2 3 3 1 1 2 1 2 3 3
3
1 3 2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |