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
shivam_04: 2016-07-18 04:48:10

My code is working correctly in my IDE but run time error here...!! pls help and all my test cases are working....!!

Last edit: 2016-07-18 04:50:53
levim: 2016-07-15 17:47:10

Thanks to @Dushyant Singh , 2 times WA using scanf. AC after switching to cin

milos94: 2016-07-07 17:38:23

I'd just like to say to all of you who are getting WA and have tried all of those cases that people posted, got them right, and got right answer in ideone, or wherever you tested your code. When you print answers print them in one line separated by a space. So no endl,\n or anything like that only ' '. Trust me I got 10+ wrong answers because of this.
Also use string because numbers can have 1000000 digits.
Palindrome from 00000 is 00100. And single digit numbers are palindromes so just increment them. Don't forget to test those edge cases that everyone is posting.

Last edit: 2016-07-07 17:44:20
shivani_10: 2016-07-06 17:42:17

Please make it clear that the value of 'k' should be less than 1000000 or the value of 'k' should contain less than 1000000 'digits'? As in the question it is mentioned as 'not more than 1000000 digits'.
And also what is the maximum limit of test cases that can be taken?

mickey_v: 2016-07-06 07:51:46

what about leading zero ? do we need to take care of them?

san93st: 2016-07-02 16:25:08

TLA :(

sanjay_stark4: 2016-07-02 04:32:55

My code is running correctly in my IDE but it is showing "Wrong answer" in spoj!!

joist: 2016-06-27 01:49:37

majorly, just 2 different cases (condition) + 1 exception of all 9s.

codeonwort: 2016-06-26 20:26:14

Solved it but my case condition is really clumsy - six conditions! I wonder if there exists a more elegant way.

mickey_v: 2016-06-26 20:17:41

999
9999
the most tricky one

Last edit: 2016-06-26 20:18:37

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%
467 16