P27055 [AtCoder] Jumping!!
普及
题目描述

Problem Description

Score: $ 200 $ points

Alice is on a coordinate plane. Her current coordinates are $ (0,0) $.

Can she reach the coordinates $ (x,y) $ using only "Knight's moves"? If she can, find the minimum number of Knight's moves required to reach there.

A "Knight's move" refers to the following movements:

  • When at coordinates $ (a,b) $, move to either $ (a+1,b+2) $ or $ (a-1,b+2) $.

Input Format

The input is given from the standard input in the following format:

$ x $ $ y $

Output Format

If Alice can reach the coordinates $ (x,y) $, output the minimum number of Knight's moves required. If she cannot reach there, output $ -1 $.

Sample Input and Output

Sample Input #1

1 6

Sample Output #1

3

Sample Input #2

6 1

Sample Output #2

-1

Sample Input #3

869 -120

Sample Output #3

-1

Notes/Hints

Constraints

  • All inputs are integers.
  • $-10^5\ \leq\ x,\ y\ \leq\ 10^5$

Sample Explanation 1

She can reach $ (1,6) $ by jumping to $ (1,2) $ in the first move, then to $ (0,4) $ in the second move, and finally to $ (1,6) $ in the third move. The movement is illustrated in the following image: ![](https://img.atcoder.jp/tkppc4-2/1a9d0ec0c05411619f92b013a90c95b4.png)

Sample Explanation 2

No matter how she moves, she cannot reach the coordinates $ (6, 1) $ using only Knight's moves.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 6
样例输出
3