P8801 [Lanquiao Cup 2022 National B] Maximum Number

Description

Given a positive integer $N$. You may perform the following two operations any number of times on any digit of $N$: 1. Increase that digit by $1$. If the digit is already $9$, after adding $1$ it becomes $0$. 2. Decrease that digit by $1$. If the digit is already $0$, after subtracting $1$ it becomes $9$. Overall, you can perform operation 1 at most $A$ times, and operation 2 at most $B$ times. What is the maximum value you can turn $N$ into?

Input Format

The first line contains three integers: $N$, $A$, $B$.

Output Format

Output one integer representing the answer.

Explanation/Hint

**[Sample Explanation]** Perform operation 2 twice on the hundreds digit, and perform operation 1 once on the tens digit. **[Test Case Scale and Constraints]** For $30\%$ of the testdata, $1 \leq N \leq 100$; $0 \leq A, B \leq 10$. For $100\%$ of the testdata, $1 \leq N \leq 10^{17}$; $0 \leq A, B \leq 100$. Lanqiao Cup 2022 National Contest, Group B, Problem D. Translated by ChatGPT 5