Sphere Online Judge

SPOJ Problem Set (classical)

5. The Next Palindrome

Problem code: PALIN


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


Added by:Adrian Kosowski
Date:2004-05-01
Time limit:2s-9s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-07-21 16:28:30 Zishan Ahmad
what is the upper limit of t ?
2014-07-20 18:11:52 Michael Moerschell


Last edit: 2014-07-20 18:21:30
2014-07-13 06:38:05 Yevgen Yampolskiy
WARNING: last line does not have terminating '\n'. If you implement your own I/O library then you may run into an issue (as I did)

Last edit: 2014-07-13 17:43:42
2014-07-12 23:01:28 sushovan podder
Hi Wasim any light on what the issues were... Everything working fine in my system but getting TLE.. I have even tested with a 9000 digit input
2014-07-08 08:45:45 kumarmantri
hi, in the prob the k shud not be >1000000 or the no of digits we input not more than 1000000 like 2 value in the example?
2014-07-08 07:41:32 Bhagatram Janarthanan
smallest palindrome that is larger than K. If input is 808, next larger palindrome is 818.
2014-07-07 20:22:01 kumarmantri
why it has to diplay wihtout leading zeros as there is no palindrome that ends with zero? plz any body help me
2014-07-05 12:36:16 Wasim Thabraze
Huh! Finally AC after a 24hr struggle!

Last edit: 2014-07-06 05:59:45
2014-07-03 16:46:40 Ritesh
Example is wrong...
808 is a palindrome !!!
why would the output be 818???
2014-06-28 23:09:24 Sharath Kazipeta
works fine on my pc but after submission i'm getting run time error "SIGABRT".. donno why ... !!
according to SIGABRT error compiler is calling abort ... but why , in my case??
http://ideone.com/uMQELu

any help would be greatly helpfull ... thanks :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.