atcoder#ARC131A. [ARC131A] Two Lucky Numbers

[ARC131A] Two Lucky Numbers

Score : 300300 points

Problem Statement

Mr. AtCoder reads in the newspaper that today's lucky number is a positive integer AA and tomorrow's is a positive integer BB.

Here, he defines a positive integer xx that satisfies both of the following conditions as a super-lucky number.

  • The decimal notation of xx contains AA as a contiguous substring.
  • The decimal notation of 2x2x contains BB as a contiguous substring.

Actually, under the Constraints of this problem, there is always a super-lucky number less than 101810^{18}. Find one such number.

Constraints

  • 1A<1081 \leq A < 10^8
  • 1B<1081 \leq B < 10^8
  • AA and BB have no leading 0s.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

AA

BB

Output

Print one super-lucky number less than 101810^{18}. If multiple solutions exist, you may print any of them.

13
62
131

One super-lucky number is x=131x = 131, because:

  • x=131x = 131 contains 1313 as a substring. (11-st through 22-nd characters)
  • 2x=2622x = 262 contains 6262 as a substring. (22-nd through 33-rd characters)

Some other super-lucky numbers are 313313, 81358135, and 135797531135797531, which would also be accepted.

69120
824
869120

One super-lucky number is x=869120x = 869120, because:

  • x=869120x = 869120 contains 6912069120 as a substring. (22-nd through 66-th characters)
  • 2x=17382402x = 1738240 contains 824824 as a substring. (44-th through 66-th characters)

The smallest super-lucky number is 6912069120, but note that any lucky number with at most 1818 digits would be accepted.

6283185
12566370
6283185

When x=6283185x = 6283185, xx is AA itself, and 2x2x is BB itself. In such a case too, xx is a super-lucky number.