PALIN - The Next Palindrome


A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.

Input

The first line contains integer t, the number of test cases. Integers K are given in the next t lines.

Output

For each K, output the smallest palindrome larger than K.

Example

Input:
2
808
2133

Output:
818
2222

Warning: large Input/Output data, be careful with certain languages


hide comments
tokyoghoul1993: 2019-07-08 16:57:29

Before writing code, try to think of as many tricky test cases to cover all cases.
then this problem became easy

mr_quan1998: 2019-07-05 18:53:03

it take me 5h
<snip>

Last edit: 2022-07-26 22:14:42
beingbmc: 2019-07-03 21:45:19

https://stackoverflow.com/questions/7934519/a-better-algorithm-to-find-the-next-palindrome-of-a-number-string/8187788#8187788
This might help.

gauravj3: 2019-07-03 12:18:16

I will say, just be careful of edge cases and its simple,
HINT :- use char array, it might be helpful(initially i tried with int, and then switched to char array :P)
Question difficulty :- easy
Implementation difficulty : - HARD

dm07: 2019-06-30 12:26:52

time limit exceeded

Last edit: 2019-06-30 12:27:22
saumya29: 2019-06-28 08:09:48

Help? not able to figure out the problem.I'm not even using loops then also its giving tle..I'm coding in python..

sapto1998: 2019-06-27 19:36:31

My code is correct but it is showing TLE.Any help?I am using Java.

ankyy_0103: 2019-06-25 13:45:29

solskgaer you can't take the same number as a palindrome like you are doing in case of all 9s

sharukmsd: 2019-06-24 21:42:29

Program works fine on all test cases but I am getting this unusual error "runtime error (SIGABRT)". What should I do??

blackdeath1278: 2019-06-11 19:32:14

i am getting time limit exceeded but i cant see a problem


Added by:adrian
Date:2004-05-01
Time limit:2s-9s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6

Problem's scores 1 vote

Concept difficulty
Concept difficulty 37%
Implementation difficulty
Implementation difficulty 50%
468 16