#K79692. Next Palindrome
Next Palindrome
Next Palindrome
Given an integer x, your task is to compute the smallest palindromic number that is strictly greater than x. A number is called a palindrome if it reads the same forwards and backwards. For example, 121 and 1331 are palindromic numbers, while 123 is not.
You can think of a palindromic number mathematically as satisfying the condition:
\( n = \text{reverse}(n) \)
where reverse(n)
is the number obtained by reversing the digits of n
.
Your solution should read the input from stdin and write the output to stdout.
inputFormat
The input consists of a single line containing one integer x (0 \leq x < 10^{18}
), representing the number from which you should find the next palindrome.
outputFormat
Output the smallest palindromic number that is strictly greater than x. The result should be printed on a single line.
## sample123
131