class ModComb
  def initialize(max, mod)
    @mod = mod
    @fac = Array.new(max + 1)
    @finv = Array.new(max + 1)
    @inv = Array.new(max + 1)
    @fac[0] = @fac[1] = 1
    @finv[0] = @finv[1] = 1
    @inv[1] = 1
    (2..max).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 comb(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0
    @fac[n] * (@finv[k] * @finv[n - k] % @mod) % @mod
  end
end

MOD = 10 ** 9 + 7
X, Y = gets.split.map(&:to_i)
if X == Y && X % 3 != 0
  puts 0
  exit 0
end

if X == Y
  n = X / 3
  m = n * 2
  comb = ModComb.new(m, MOD)
  puts comb.comb(m, n)
  exit 0
end

diff = (X - Y).abs

if X < Y && X < diff
  puts 0
  exit 0
end
if Y < X && Y < diff
  puts 0
  exit 0
end

max = [X, Y].max
n = max - diff * 2
n = n / 3
m = n * 2
comb = ModComb.new(m + diff, MOD)
puts comb.comb(m + (n % 3 == 0 ? 0 : 1) + diff, n + diff)
