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
rjenni: 2015-08-12 16:41:20

Finally green! :D

Himanshu Garg: 2015-08-11 15:11:11

Learned new concept....Great Problem.... :)

subhajit321: 2015-08-09 11:35:04

what is the highest input of the test case?

einsdurchnull: 2015-08-05 14:22:55

Finally ACC...
Got a SIGSEV error all the time, because incrementing the digits recursevily. This produced a stack overflow, due to high amount of digits.

Rohit Retnakaran: 2015-08-04 15:55:21

Seriously, there is something wrong with the judge, a wrong code gets accepted... :/

Sanjeev Kumar: 2015-08-04 00:17:43

@prashadG my code is working for all cases you mentioned but still it is showing wa. also
what is the maximum value of input?
they have mentined large input/output but not sure how large...

Last edit: 2015-08-04 00:19:10
skrishna99: 2015-08-01 07:10:20

I am getting time exceeded in java , I am using biginteger to get value and biginteger array . do i need to use string to get input ?

PrasadG: 2015-07-29 18:46:27

Finally got green..
For WA guys..check following test cases->
909 --> 919
99899 --> 99999
9989 --> 9999
99999 --> 100001

Last edit: 2015-07-29 18:47:17
luisdanielmesa: 2015-07-25 06:56:49

I'm done... the checker is wrong.

Last edit: 2015-07-25 07:35:47
luisdanielmesa: 2015-07-25 06:33:26

I'm pretty sure this problem is not being checked right in java... After 10 attempts I checked with 100 Strings against a code that was accepted... and both produce the same results... but mine is still rejected...


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