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
pv: 2016-01-02 21:11:27

So, i implemented this in c++ (converted my recursive logic to an iterative one) and i still get a WA. So while trying to find reasons for why this happens, I came across a comment here saying single digit numbers are not palindromes ... is this true??
EDIT : Forgot to mention this but i have also taken care of cases like 99, 100 etc. Also, i checked on wikipedia, and it says that single digit numbers are palindromic.

Last edit: 2016-01-02 21:14:37
nithi_karu: 2016-01-02 06:38:49

Many of my java programs are rejected by Spoj one being this Next Palindrome Program.

dupletor: 2015-12-28 20:10:06

I did a correct algorithm, but it is limited to the integer received (2.1b?)
Even if I could put the 1000000 digits to an integer vector, how am I supposed to receive the number?

Last edit: 2015-12-28 20:20:56
ashu14: 2015-12-27 15:58:12

@imshubhamk it means that no cant be like 0067

imshubhamk: 2015-12-25 18:11:56

what does without leading zero mean can anybody help me please......

Last edit: 2015-12-25 18:23:23
sukriti_verma: 2015-12-23 19:09:22

Go through ALL the comments to debug if you're getting a WA for no apparent reason. No shit. You'll find the reason.

lgarvey: 2015-12-21 00:01:39

Getting NZEC despite my implementation working perfectly on my computer, even with a single 1 mill input, on python 2.7.1. Argh!

kunal3110: 2015-12-15 18:31:58

getting NZEC

Vardi Narendra: 2015-12-14 09:31:20

Try this input
1
94187978322

pparas007: 2015-12-13 15:25:38

Code is running perfectly on local machine with small trial input combinations!
but getting 'NZEC runtime error' in Java language! what could be the problem???


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