Knight

AtCoder
IDabc145_d
Time2000ms
Memory256MB
Difficulty
There is a knight - the chess piece - at the origin $(0, 0)$ of a two-dimensional grid. When the knight is at the square $(i, j)$, it can be moved to either $(i+1,j+2)$ or $(i+2, j+1)$. In how many ways can the knight reach the square $(X, Y)$? Find the number of ways modulo $10^9 + 7$. ## Constraints * $1 \leq X \leq 10^6$ * $1 \leq Y \leq 10^6$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $X$ $Y$ [samples]
Samples
Input #1
3 3
Output #1
2

There are two ways: $(0,0) \to (1,2) \to (3,3)$ and $(0,0) \to (2,1) \to (3,3)$.
Input #2
2 2
Output #2
0

The knight cannot reach $(2,2)$.
Input #3
999999 999999
Output #3
151840682

Print the number of ways modulo $10^9 + 7$.
API Response (JSON)
{
  "problem": {
    "name": "Knight",
    "description": {
      "content": "There is a knight - the chess piece - at the origin $(0, 0)$ of a two-dimensional grid. When the knight is at the square $(i, j)$, it can be moved to either $(i+1,j+2)$ or $(i+2, j+1)$. In how many wa",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc145_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a knight - the chess piece - at the origin $(0, 0)$ of a two-dimensional grid.\nWhen the knight is at the square $(i, j)$, it can be moved to either $(i+1,j+2)$ or $(i+2, j+1)$.\nIn how many wa...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments