407200: GYM102697 171 Nearest Palindromes
Description
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.
Given 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.
For example, let's say $$$n$$$ = 600 and $$$k$$$ = 4.
The 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.
InputThe 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.
OutputOutput $$$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.
ExamplesInput600 4Output
595 606 585 616Input
753 8Output
757 747 767 737 777 727 787 717Input
6 10Output
6 5 7 4 8 3 9 2 1 11