Digit Sum
Given an integer N, find the smallest integer with the same digit sum which is greater than N.
The digit sum of an integer is the sum of its digits, For exempel, the digit sum of $9550$ is $9 + 5 + 5 + 0 = 19$ and the digit sum of $999$ is $9 + 9 + 9 = 27$.
Input
An integer, N.
Output
Output the smallets integer greater than N with the same digit sum as N.
Scoring
Group |
Points |
Limits |
1 |
20 |
$1 \le N \le 10$ |
2 |
20 |
$1 \le N \le 100$ |
3 |
40 |
$1 \le N < 10\, 000$ |
4 |
20 |
$1 \le N < 10^{20}$ |
Sample Input 1 | Sample Output 1 |
---|---|
8 |
17 |
Sample Input 2 | Sample Output 2 |
---|---|
92 |
119 |
Sample Input 3 | Sample Output 3 |
---|---|
9550 |
9604 |
Sample Input 4 | Sample Output 4 |
---|---|
200 |
1001 |