407200: GYM102697 171 Nearest Palindromes

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

171. Nearest Palindromestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

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.

Output

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.

ExamplesInput
600 4
Output
595
606
585
616
Input
753 8
Output
757
747
767
737
777
727
787
717
Input
6 10
Output
6
5
7
4
8
3
9
2
1
11

加入题单

算法标签: