{"raw_statement":[{"iden":"statement","content":"A number is called a _palindrome_ if it reads the same forwards and backwards. For example, 5775, 98389, 7, and 66 are palindromes, but 552, 35, and 86867 are not palindromes.\n\nGiven a number $n$, figure out the closest $k$ palindromes to $n$. If two palindromes have the same distance away from $n$, print the smaller one first.\n\nFor example, let's say $n$ = 600 and $k$ = 4.\n\nThe closest palindrome to $n$ is 595, with a distance of 5. The next closest palindrome is 606, with a distance of 6. The next two are 585 (distance of 15) and 616 (distance of 16), so we would print 595, 606, 585, and 616, in that order.\n\nThe only line of input consists of two space-separated integers $n$ and $k$: the number to check palindromes near, and the number of palindromes to print out, respectively.\n\nOutput $k$ lines, each consisting of a palindrome, sorted by their distance from $n$ (calculated as abs($n$ - $p$) for a palindrome $p$).\n\n*The palindromes must be positive integers*.\n\n"},{"iden":"input","content":"The only line of input consists of two space-separated integers $n$ and $k$: the number to check palindromes near, and the number of palindromes to print out, respectively."},{"iden":"output","content":"Output $k$ lines, each consisting of a palindrome, sorted by their distance from $n$ (calculated as abs($n$ - $p$) for a palindrome $p$).*The palindromes must be positive integers*."},{"iden":"examples","content":"Input600 4\nOutput595\n606\n585\n616\nInput753 8\nOutput757\n747\n767\n737\n777\n727\n787\n717\nInput6 10\nOutput6\n5\n7\n4\n8\n3\n9\n2\n1\n11\n"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the target number, and $ k \\in \\mathbb{Z}^+ $ be the number of closest palindromes to find.  \nLet $ \\mathcal{P} \\subset \\mathbb{Z}^+ $ be the set of all positive palindromic integers.\n\n**Constraints**  \n1. $ n \\geq 1 $  \n2. $ k \\geq 1 $  \n3. All palindromes $ p \\in \\mathcal{P} $ must satisfy $ p \\geq 1 $\n\n**Objective**  \nFind the multiset $ S \\subseteq \\mathcal{P} $ of size $ k $ such that:  \n- For any $ p_1 \\in S $, $ p_2 \\in \\mathcal{P} \\setminus S $, it holds that $ |n - p_1| \\leq |n - p_2| $  \n- If $ |n - p_1| = |n - p_2| $ for $ p_1, p_2 \\in \\mathcal{P} $, then the smaller palindrome is prioritized  \n- Output the elements of $ S $ sorted by increasing distance $ |n - p| $, and for equal distances, by increasing value of $ p $","simple_statement":"Given a number n and a number k, find the k closest palindromes to n. If two palindromes are equally close, choose the smaller one first. Print each palindrome on a separate line.","has_page_source":false}