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
bin_saurabh: 2016-11-02 13:56:48

can anyone give a hint for this problem?

sarthak_aws: 2016-10-28 16:22:48

Just compiled and executed the program successfully on ideone.com but get wrong answer here...can someone look into my code and check it whats the problem??

nobody6501: 2016-10-26 00:42:25

Getting WA just like others, even though the test cases came out correct. . . . . i don't even

harsh2leo: 2016-10-25 14:45:56

does runtime error signifies more time complexity??

ajeetk_973: 2016-10-24 20:50:09

i m getting WA. tell me where to find test cases..

rohit1507: 2016-10-19 19:24:05

does '0000' be considered '0' or the places matter?

secondyearcse: 2016-10-17 17:41:20

thanks @jbirlingmair for test case

jbirlingmair: 2016-10-17 17:36:09

make sure you try test cases like this number:
532428761239534781239875438971234...

The problem says the number can be up to 1 million digits long.

Note that without a good algorithm you will get time limit exceeded.

Last edit: 2016-10-21 19:53:19
secondyearcse: 2016-10-17 08:33:00

my code works accurately on code blocks,but i am getting WA here why??

♥☻♥ David ♥☻♥: 2016-10-11 21:38:39

I have been trying to solve this problem here. but encountering WA..
Fun fact : I can get it accepted on CodeChef but not here...

I had testcases generated for "1" to "10000" and verified that my program works flawlessly.

Just curious to know where my program fails.

Last edit: 2016-10-20 22:23:26

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