P6387 [COCI 2007/2008 #4] VECI
Description
Given a positive integer $x$, find the smallest integer $y$ such that the number of occurrences of each digit $0$ to $9$ in $y$ is respectively equal to that in $x$, and $x \lt y$.
Input Format
The input contains only one line with an integer $x$.
Output Format
Output one line with an integer representing the answer. If such a $y$ does not exist, output $0$.
Explanation/Hint
#### Constraints
For all testdata, it is guaranteed that $1 \leq x \lt 10^6$.
#### Notes
**Translated from [COCI2007-2008](https://hsin.hr/coci/archive/2007_2008/) [CONTEST #4](https://hsin.hr/coci/archive/2007_2008/contest4_tasks.pdf) *T2 VECI***.
Translated by ChatGPT 5