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
arekz: 2015-05-12 08:41:39

Hi, on all colected in comments cases I get correct answer but still I get WA in jugde system. (see: <snip> )
@Anakar Parida: I think you should consider the resigne from the use of BigDecimal.

Last edit: 2022-07-26 22:23:43
Anakar Parida: 2015-05-08 21:39:22

For the below input it took 0.002547891 sec
Input :-
6
623616231737147634792734623479273472347762394792734
6947274274702734727597205772268628648269472047927498729
927497927496294702749729569729561724162731069164793645926
92749724370274072094728765872057072407120470197401720
72984727498274720749872487289479827498729847
727498298472740720470274070274274072042374

Output :-
623616231737147634792734626437297436741737132616326
6947274274702734727597205772775027957274372074724727496
927497927496294702749729569737965927947207492694729794729
92749724370274072094728765956782749027047207342794729
72984727498274720749877894702747289472748927
727498298472740720471174027047274892894727

Anakar Parida: 2015-05-08 21:27:09

Can anyone really give me input for which my time limit will get exceeded. my java program in ideone is <snip>

Last edit: 2022-07-26 22:23:48
ash: 2015-05-08 09:24:10

getting TLE for a large string of random numbers :( whereas correct answer for short strings of random numbers and answer is also coming correct if all the characters in the string are 9's (no matter what the length of the string is )...plz help...

AbuGasem: 2015-05-07 13:10:46

<snip>
This Is My Code Whats Wrong ????

Last edit: 2022-07-26 22:29:38
baby_monk: 2015-05-05 23:42:27

@adrian: Can you let me know which test this is <snip>

Last edit: 2022-07-26 22:29:34
sksuman.nitw: 2015-05-04 19:36:08

finally accepted.....
points to remember
1. check for all 9's i.e for 9999 output should be 10001
2. check for palindrome no.
3. palindrome of single digit is its next digit. i.e 0--->1, 5--->6, 3->4 and for 9--->11
4. some test cases
1 2 9 2 1 ----------> 13031
7 8 3 3 2 2---------->7 8 3 3 8 7
9 4 1 8 7 9 7 8 3 2 2------------>9 4 1 8 8 0 8 8 1 4 9
192---------->202 (you will get output as 2 if you are just dividing by 58 of (string[i]+10) which is wrong....in this case put string[i]='0' if string[i]==':'
hope it will help.

sanlocoz: 2015-05-03 04:20:13

<snip>

Last edit: 2022-07-26 22:29:30
chazshiz: 2015-05-02 21:05:47

i got 21s base on 100,000, how can i do for 1,000,000?

Anakar Parida: 2015-04-28 18:04:21

I am able to pass wrong answer but now getting time limit exceeded :(


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