Movement 3

Decide whether (x, y) is reachable by moving 3^k right or up on each step k, starting at the origin.

Medium5MathBit manipulationRecursionInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Donghyuk stands at the origin (0,0)(0, 0) of an infinitely large plane.

He moves toward (x,y)(x, y) one step at a time. Steps are numbered from 00, and the number goes up by 11 after each finished step.

On step kk he picks one of two directions, right (the direction in which xx grows) or up (the direction in which yy grows), and moves exactly 3k3^k in the direction he picked. He cannot stay in place and he cannot skip a step.

Once he arrives at (x,y)(x, y) he stops there. Given xx and yy, write a program that decides whether he can reach (x,y)(x, y) starting from (0,0)(0, 0).

Input

The first line contains xx and yy, separated by a space. (0x1090 \le x \le 10^9, 0y1090 \le y \le 10^9)

Output

Print 11 if (x,y)(x, y) can be reached from (0,0)(0, 0), and 00 otherwise.