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
aneeshs_7901: 2019-11-19 16:19:14

its giving wrong answer everytime i submit.its working fine and the output is correct in ideone

binit_54: 2019-10-15 06:22:42

can someone give me some idea on how to store the strings in this problem for later access when all the input has been finished?

pranay19263: 2019-10-10 08:19:56

giving runtime error all the time
beside it is fully working on ideone

suryansh_singh: 2019-10-06 18:31:42

i written my code without using nested loop ,then also it raising ' time exceeded limit'
just used this ( if str(m)==str(m)[::-1]: ) in python3,
does anyone facing same problem?

meonspoj01: 2019-09-29 20:08:18

"For a given positive integer K of not more than 1000000 digits", really 1000000 digits or it talks about the input being less than it?

pretam9: 2019-08-26 16:20:25

The question was damn good....took me 3 hrs to understand and implement

kmkhan_014: 2019-08-16 13:12:56

ye question hatao, har company yehi puchti hai

Last edit: 2019-08-24 12:59:57
mriow: 2019-08-13 09:35:32

It works fine with python3, BUT do not convert ever from string to int (do not use int() on python) since it is a HUGE slow down of the running time, giving even a TLE error.
(the slow down is also true regardless of the language)

Last edit: 2019-08-13 09:36:03
thirumalai: 2019-08-13 08:39:36

Does this work in python?

hit7sh: 2019-08-09 17:48:01

Works perfectly in Bluej and shows compilation error in here. Like wtf!?


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