COCI '07 Contest 4 #2 Veci

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type

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

Input Specification

The first line of input contains the integer X (1 \le X \le 999\,999).

The first digit in X will not be a zero.

Output Specification

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

Sample Input 1

156

Sample Output 1

165

Sample Input 2

330

Sample Output 2

0

Sample Input 3

27711

Sample Output 3

71127

Comments

There are no comments at the moment.