#P1555. Bessie's Faulty Conversions
Bessie's Faulty Conversions
Bessie's Faulty Conversions
Bessie converts a positive integer \(N\) into different bases. However, each time she performs a conversion she writes exactly one digit incorrectly. For example, when converting \(14\) to base \(2\), the correct result is \(1110\) but she might write it as \(0110\) or \(1111\). Note that Bessie never adds or removes digits accidentally, so an erroneous representation may contain leading zeros.
You are given two strings:
- An erroneous base-2 representation of \(N\).
- An erroneous base-3 representation of \(N\).
Your task is to determine the correct value of \(N\) (in decimal). It is guaranteed that \(N\) does not exceed \(10^9\) and that the solution is unique.
inputFormat
The input consists of two lines:
- The first line contains the erroneous binary (base-2) representation of \(N\) as a string.
- The second line contains the erroneous ternary (base-3) representation of \(N\) as a string.
Note that the erroneous representations differ from the correct ones by exactly one digit.
outputFormat
Output the correct value of \(N\) in decimal.
sample
1010
212
14