This page is still under construction.

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

Powers of Three Walk

Interview

Time limit2sMemory limit512 MB

Summary
Given a target point, decide whether it is reachable if stage k moves exactly 3^k in one of the four axis directions.
Level

Medium5 of 10

Topics
Math, Number theory, Bit manipulation
Solved
No attempts yet

Problem

Donghyeok stands at the origin (0,0)(0, 0) of a plane of infinite size.

He moves in numbered stages and wants to arrive at the point (x,y)(x, y). Stage numbers start at 00 and grow by 11.

At stage kk he picks one of four directions, right (xx increases), left (xx decreases), up (yy increases), or down (yy decreases), and then moves exactly 3k3^k in that direction. He cannot skip a stage.

He performs as many stages as he wants and then stops. Stopping at the origin without performing a single stage is allowed.

Given xx and yy, write a program that decides whether (x,y)(x, y) can be reached from (0,0)(0, 0).

Input

The first line contains two integers xx and yy separated by a space. (−109≤x,y≤109-10^9 \le x, y \le 10^9)

Output

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

If xx and yy are both 00, he is already there before any stage, so print 11.

Examples5

  1. Example 1

    Input
    1 3
    
    Expected output
    1
    
  2. Example 2

    Input
    0 2
    
    Expected output
    1
    
  3. Example 3

    Input
    1 9
    
    Expected output
    0
    
  4. Example 4

    Input
    3 0
    
    Expected output
    0
    
  5. Example 5

    Input
    1 1
    
    Expected output
    0