local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
-- returns (b^n) % m
local function modpow(b, n, m)
    if n == 0 then
        return 1
    elseif n % 2 == 0 then
        -- be careful about overflow of b*b
        return modpow(b * b % m, n//2, m)
    else
        return b * modpow(b, n - 1, m) % m
    end
end
local function make_mod_nCr(max, m)
    -- Create n! table
    local mfac = {}
    mfac[0] = 1
    for i=1,max do
        mfac[i] = mfac[i-1] * i % m
    end
    -- Create (n!)^(-1) table
    -- (n!)^(-1) ≡ (n!)^(m - 2)  <mod m>
    local invmfac = {}
    invmfac[max] = modpow(mfac[max], m - 2, m)
    for i=max,1,-1 do
        -- ((a-1)!)^(-1) ≡ a * (a!)^(-1)  <mod m>
        invmfac[i-1] = i * invmfac[i] % m
    end
    -- returns nCr % m
    local function mod_nCr(n, r)
        -- nCr ≡ n! * (r!)^(-1) * ((n-r)!)^(-1)  <mod m>
        local a = mfac[n] * invmfac[r] % m
        a = a * invmfac[n-r] % m
        return a
    end
    return mod_nCr
end
----
local MOD = math.floor(10^9) + 7
local mod_nCr = make_mod_nCr(math.floor(10^6) + 1, MOD)
local X, Y = read.nn()
if (X/2) <= Y and Y <= 2*X then
    if (X+Y) % 3 == 0 then
        local num = (X+Y) // 3 + 1
        local basex = (X+Y) // 3
        local fromL = X - basex + 1
        print(mod_nCr(num-1, fromL-1))
    else
        print(0)
    end
else
    print(0)
end

