Problem list
Log in
#coci00056 · COCI 2007/2008 Contest 4

Veci

Silver III 1.0 s 32 MB

Your program will be given an integer $X$. Find the smallest number larger than $X$ consisting of the same digits as $X$.

Input

The first line of input contains the integer $X$ ($1 \le X \le 999999$). The first digit in $X$ will not be a zero.

Output

Output the result on a single line. If there is no such number, output $0$.

Example 1

Input
156
Output
165

Example 2

Input
330
Output
0

Example 3

Input
27711
Output
71127
Source
COCI 2007/2008 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code