#K34692. Closest Palindromic Numbers

    ID: 25366 Type: Default 1000ms 256MiB

Closest Palindromic Numbers

Closest Palindromic Numbers

In this problem, you are given a positive integer ( n ). Your task is to find two numbers: the largest palindromic number that is smaller than ( n ) and the smallest palindromic number that is larger than ( n ).

A palindromic number is one that remains the same when its digits are reversed. In other words, a number ( x ) is palindromic if it satisfies ( x = \text{rev}(x) ), where ( \text{rev}(x) ) denotes the number obtained by reversing the decimal representation of ( x ).

For example:

  • For \( n = 12321 \), the answer is 12221 12421.
  • For \( n = 100 \), the answer is 99 101.

Your solution should read an integer from the standard input (stdin) and print the two resulting palindromic numbers to the standard output (stdout), separated by a space.

inputFormat

The input consists of a single integer ( n ) ((1 \leq n \leq 10^9)).

outputFormat

Output two integers separated by a space: the largest palindromic number smaller than ( n ) and the smallest palindromic number larger than ( n ).## sample

12321
12221 12421