Restore an Addition Equation
Time limit2sMemory limit128 MB
Fill the ? digits in an addition equation A+B=C with digits (no leading zeros) so the sum holds, maximizing C then A.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, String, Math
- Solved
- No attempts yet
Problem
An addition equation has the form A+B=C. The values A, B, and C are nonnegative integers. A number may not start with 0, unless the number has exactly one digit. Some digits in the equation are written as ?.
Restore the equation by replacing every ? with a digit so that the equation is true. If several restorations are possible, output one with the largest value of C. If there is still more than one, output one with the largest value of A.
Input
The first line contains the equation. Its length is at most 50 characters.
Output
Print the restored equation. If it is impossible, print -1.