#Lutece0553. Awkward Digits

Awkward Digits

Migrated from Lutece 553 Awkward Digits

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Bessie the cow is just learning how to convert numbers between different bases, but she keeps making errors since she cannot easily hold a pen between her two front hooves.

Whenever Bessie converts a number to a new base and writes down the result, she always writes one of the digits wrong. For example, if she converts the number 1414 into binary (i.e., base 22), the correct result should be 1110, but she might instead write down 0110 or 1111. Bessie never accidentally adds or deletes digits, so she might write down a number with a leading digit of 0 if this is the digit she gets wrong.

Given Bessie's output when converting a number NN into base 22 and base 33, please determine the correct original value of NN (in base 1010). You can assume NN is at most 11 billion, and that there is a unique solution for NN.

Please feel welcome to consult any on-line reference you wish regarding base-22 and base-33 numbers, if these concepts are new to you.

Input

  • Line 11: The base-22 representation of NN, with one digit written incorrectly.
  • Line 22: The base-33 representation of NN, with one digit written incorrectly.

Output

  • Line 11: The correct value of NN.

Samples

1010
212
14

Resources

USACO Nov 2011