Problem:
Score : 400 points

Problem Statement

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

Output

Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.

Sample Input 1

3 3

Sample Output 1

2

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

Sample Input 2

2 2

Sample Output 2

0

The knight cannot reach (2,2).

Sample Input 3

999999 999999

Sample Output 3

151840682

Print the number of ways modulo 10^9 + 7.

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::{fastout, input};

const MO: u64 = 1_000_000_007;
const LIM: usize = 1_000_050;

#[fastout]
fn main() {
    input! {
        x: usize,
        y: usize,
    }

    let inv = {
        let mut inv = vec![1, 1];
        for i in 2..LIM {
            inv.push(MO - MO / (i as u64) * inv[(MO as usize) % i] % MO);
        }
        inv
    };

    let (fact, ifac) = {
        let mut fact = vec![1];
        let mut ifac = vec![1];
        for i in 1..LIM {
            fact.push(fact[i - 1] * (i as u64) % MO);
            ifac.push(ifac[i - 1] * inv[i] % MO);
        }
        (fact, ifac)
    };

    let comb = |n, r| fact[n] * ifac[r] % MO * ifac[n - r] % MO;

    println!(
        "{}",
        (0..x + 1)
            .filter(|a| (x - *a) % 2 == 0 && 2 * *a + (x - *a) / 2 == y)
            .map(|a| comb((x - a) / 2 + a, a))
            .sum::<u64>()
            % MO
    )
}

*/

fn main() {
    let exe = "./binXXXXXX";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";