This page is still under construction.

Parts of this page are still being built. What you see may change.

Movement 3

Interview

Time limit2sMemory limit512 MB

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

Medium5 of 10

Topics
Math, Bit manipulation, Recursion
Solved
No attempts yet

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. (0≤x≤1090 \le x \le 10^9, 0≤y≤1090 \le y \le 10^9)

Output

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

Examples5

  1. Example 1

    Input
    1 3
    
    Expected output
    1
    
  2. Example 2

    Input
    1 1
    
    Expected output
    0
    
  3. Example 3

    Input
    3 0
    
    Expected output
    0
    
  4. Example 4

    Input
    1 9
    
    Expected output
    0
    
  5. Example 5

    Input
    3 10
    
    Expected output
    1