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
Punit Bhatt: 2015-01-02 11:33:13

Tried solving this problem. Got right answers in all cases but am getting wrong answer here in spoj. Please help me out
ideone.com/iu5T4S

Nazmul Hossain: 2014-12-29 06:38:12

I am getting runtime error NZEC ....

Ankit: 2014-12-27 05:17:21

Its a general question. I am not sure of the answer.
How should the input ouput sequence be for problems.?

Input
Input
Input
Input

Output
Output
Output
Output

" OR "
Input
Output
Input
Output
Input
Output

Last edit: 2014-12-27 05:17:46
Petar Jesic: 2014-12-26 20:40:53

@Dan: thanks a million, had that problem.

Yogesh Jindal: 2014-12-25 09:52:32

Last edit: 2014-12-25 09:57:09
Dan Pallas: 2014-12-18 02:39:53

One thing that isn't really part of the problem that caused me some issues. The last (at least I assume it was the last) input doesn't have a newline character in it. Don't assume that all inputs do.

LabdaABeta: 2014-12-15 19:58:49

@naman gupta (and others)
Note that its integer k not more than 1000000 **DIGITS** so any c-derived 'int' type will not be big enough. Also implementing full arithmetic for bignums is overkill. This can be done by string manipulation.

Manglesh Sharma: 2014-12-09 19:12:15

what is expected in case where the integer has more than 1000000 digits

a test case:
3
808
integer more than 1000000 digits
2133

what should be the output???

[reply by cyclops: That is not valid input. We are given that K is not more than 1000000 digits.]

Last edit: 2014-12-21 15:28:29
numerix: 2014-12-09 18:07:54

@Kushagra Bhatnagar: Why do you post your comment here, though it was a problem with your submissions for FIBOSUM?
Explanation: You used Python 3.4 as language, but FIBOSUM is still on Pyramid cluster where Python 3.4 and PyPy are not available. Use Python 3.2 instead.

Kushagra Bhatnagar: 2014-12-09 15:11:40

My Code Is running Fine In Python
But Here It Says INTERNAL ERROR what does that mean?


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