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
vasayashwanth: 2015-06-17 07:31:59

if you are getting too many WA ,try these test cases :9,11,99,100,9999 and check whether you are getting 11,22,101,101,10001 as answers......

Last edit: 2015-06-17 07:33:17
raahulsaxena: 2015-06-16 16:49:31

works in codechef...doesnt work here...saying wrong answer...why?

bazuga: 2015-06-16 12:17:02

AC finally... advice: definition of palindrome is as in wiki. don't worry about that.

najeeb97khan: 2015-06-15 17:24:54

am getting a time limit exceeding error. I am using the method of recursion bt still there is no change! Can anybody please help me out?

sharmin03: 2015-06-12 21:52:01

For all those who are getting SIGSEGV runtime error, do not use pointer char *s, although it runs on your system. Instead use the array with the size provided in the question is 1000000. This might help. :)

goyat7: 2015-06-12 17:30:14

Getting wrong answer.. even if the code is working fine on my system. Can anyone tell me the sample input to cross verify my solution ?

cassiano: 2015-06-11 02:48:04

Dealing with strings in Java gave TLE... Had to deal directly with array of short.

lvn_anand: 2015-06-10 20:28:06

ok. this problem is really frustating.
1. I'm using brute force, so answer has to be correct.(no issues for 9's or whatever)
2. I'm not using strings, so no problem for leading zeroes.
3. Tried both cases for single digit integers(11 and next digit).
4. Tried removing new line character at the end.
5. Using long int in C.

What else shall I try to remove this WA!!!

kimku: 2015-06-10 20:25:11

getting wrong answer...can someone give me sample data to cross check my code..

ashish07: 2015-06-10 10:01:50

getting runtime error (SIGXFSZ) i don't know why no extra space other than char array are used;


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