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:9s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2013-06-08 10:18:01 vinod kumar
could anybody please help me??
why it is showing runtime error.
program is correctly working in my pc also it is showing output on ideone
2013-05-22 07:20:29 Kartik Khare
This site is just testing my patience...
i just don't understand what is wrong with my program.It runs perfectly on my system
Plz provide me with tricky cases if any
(i have done it using string input)

Last edit: 2013-05-22 07:21:57
2013-05-09 01:22:40 Prodigy
1000000 digits??? ...
2013-05-03 17:21:35 Bernardo de Freitas Zamperetti
make sure that your program can accept numbers with at least 1000000 *DIGITS*

Last edit: 2013-05-03 17:22:37
2013-05-01 11:15:28 Shruti Sah
the programme is working correctly on Ideone.com for the given inputs but here it is showing runtime error help me out plz?
2013-04-30 09:23:50 gowrishankar
the programme is working correctly on Ideone.com for the given inputs but here it is showing runtime error help me out plz?
2013-04-30 09:03:46 gowrishankar
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Fifth1.main(Main.java:11)
what is this can any one help me when i am giving input its displaying correct output but when i uploaded in spoj i am getting runtime error can any one help me out
2013-04-25 08:49:47 arjun
I am getting TLE . how do i make it right ? what could have happened?
2013-04-22 22:06:24 Mohamed Ramadan Mohamed
what about the zero in input ????
help plz ?
2013-04-22 22:00:49 Omar Ahmed
All I/Os is right ! .. so why WA !!! \(-_-)/
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.