class ModCombination
  attr_reader :fac, :inv, :finv, :mod

  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]

    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
      @inv[i] = mod - inv[mod % i] * (mod / i) % mod
      @finv[i] = finv[i - 1] * inv[i] % mod
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end

  def repeated_combination(n, k)
    combination(n + k - 1, k)
  end
end

MOD = 10 ** 9 + 7
X, Y = gets.split.map(&:to_i)
N = [X, Y].max

mc = ModCombination.new(10 ** 6)
ans = 0

(0..N).each do |one_x_cnt|
  two_x_cnt = (X - one_x_cnt) / 2

  n = two_x_cnt + one_x_cnt
  # p [n, one_x_cnt, two_x_cnt]

  break if two_x_cnt < 0
  next if (one_x_cnt + 2 * two_x_cnt) != X
  next if (2 * one_x_cnt + two_x_cnt) != Y

  ans = (ans + mc.combination(n, two_x_cnt)) % MOD
end

puts ans
