{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eThe only difference between easy and hard versions are constraints on $$$n$$$ and $$$k$$$\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eYou are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $$$k$$$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $$$0$$$).\u003c/p\u003e\u003cp\u003eEach 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.\u003c/p\u003e\u003cp\u003eYou (suddenly!) have the ability to see the future. You know that during the day you will receive $$$n$$$ messages, the $$$i$$$-th message will be received from the friend with ID $$$id_i$$$ ($$$1 \\le id_i \\le 10^9$$$).\u003c/p\u003e\u003cp\u003eIf you receive a message from $$$id_i$$$ 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.\u003c/p\u003e\u003cp\u003eOtherwise (i.e. if there is no conversation with $$$id_i$$$ on the screen):\u003c/p\u003e\u003cul\u003e \u003cli\u003e Firstly, if the number of conversations displayed on the screen is $$$k$$$, the last conversation (which has the position $$$k$$$) is removed from the screen. \u003c/li\u003e\u003cli\u003e Now the number of conversations on the screen is guaranteed to be less than $$$k$$$ and the conversation with the friend $$$id_i$$$ is not displayed on the screen. \u003c/li\u003e\u003cli\u003e The conversation with the friend $$$id_i$$$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYour task is to find the list of conversations (in the order they are displayed on the screen) after processing all $$$n$$$ messages.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 2 \\cdot 10^5)$$$ — the number of messages and the number of conversations your smartphone can show.\u003c/p\u003e\u003cp\u003eThe second line of the input contains $$$n$$$ integers $$$id_1, id_2, \\dots, id_n$$$ ($$$1 \\le id_i \\le 10^9$$$), where $$$id_i$$$ is the ID of the friend which sends you the $$$i$$$-th message.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eIn the first line of the output print one integer $$$m$$$ ($$$1 \\le m \\le min(n, k)$$$) — the number of conversations shown after receiving all $$$n$$$ messages.\u003c/p\u003e\u003cp\u003eIn the second line print $$$m$$$ integers $$$ids_1, ids_2, \\dots, ids_m$$$, where $$$ids_i$$$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $$$i$$$ after receiving all $$$n$$$ messages.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7 2\n1 2 3 2 1 3 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n2 1 \n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e10 4\n2 3 3 1 1 2 1 2 3 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\n1 3 2 \n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first example the list of conversations will change in the following way (in order from the first to last message):\u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$[]$$$; \u003c/li\u003e\u003cli\u003e $$$[1]$$$; \u003c/li\u003e\u003cli\u003e $$$[2, 1]$$$; \u003c/li\u003e\u003cli\u003e $$$[3, 2]$$$; \u003c/li\u003e\u003cli\u003e $$$[3, 2]$$$; \u003c/li\u003e\u003cli\u003e $$$[1, 3]$$$; \u003c/li\u003e\u003cli\u003e $$$[1, 3]$$$; \u003c/li\u003e\u003cli\u003e $$$[2, 1]$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIn the second example the list of conversations will change in the following way:\u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$[]$$$; \u003c/li\u003e\u003cli\u003e $$$[2]$$$; \u003c/li\u003e\u003cli\u003e $$$[3, 2]$$$; \u003c/li\u003e\u003cli\u003e $$$[3, 2]$$$; \u003c/li\u003e\u003cli\u003e $$$[1, 3, 2]$$$; \u003c/li\u003e\u003cli\u003e and then the list will not change till the end. \u003c/li\u003e\u003c/ul\u003e"}}]}