#K40537. Next Palindromic Number

    ID: 26664 Type: Default 1000ms 256MiB

Next Palindromic Number

Next Palindromic Number

Given a positive integer (n), the task is to find the smallest palindromic number that is strictly greater than (n). A number is palindromic if it reads the same forward and backward (e.g. (121), (1331)). However, if the returned number would have more than 9 digits, the output should be (0). Note that we also return (0) if the input (n) itself has more than 8 digits (since (n + 1) might reach 9 digits at most).

inputFormat

The input consists of a single integer (n) provided via standard input. You may assume (0 < n < 10^9).

outputFormat

Print the smallest palindromic number that is greater than (n) to standard output. If such a number would exceed 9 digits, output (0).## sample

1
2

</p>