P1555 [USACO11NOV] Awkward Digits B
Background
Bessie has just learned how to convert numbers between different bases, but she often makes mistakes because her two front hooves cannot easily hold a pen.
Description
Every time Bessie converts a number to a new base, she always writes exactly one digit incorrectly. For example, when she converts `14` to base $2$, the correct result is `1110`, but she might write `0110` or `1111`. Bessie never accidentally inserts or deletes digits, so she might write an incorrect number that starts with `0`.
Given Bessie's base $2$ form of $N$ and base $3$ form of $N$ after her conversion, compute the correct value of $N$ (in decimal). $N$ may be as large as $10^9$, and the input guarantees that the solution exists and is unique.
Input Format
The first line contains the base $2$ representation of $N$ (with exactly one incorrect digit).
The second line contains the base $3$ representation of $N$ (with exactly one incorrect digit).
Output Format
Output a single line with the correct value of $N$.
Explanation/Hint
Translated by ChatGPT 5