def solve():

    mod = 10 ** 9 + 7



    x, y = list(map(int, input().split()))



    sum_ = x + y



    q, r = divmod(sum_, 3)

    if r != 0:

        return 0



    a = (x * 2 - y) // 3



    b = (y * 2 - x) // 3



    if a < 0 or b < 0:

        return 0



    def cmb(n, r):

        return (fact[n] * finv_t[r] * finv_t[n - r]) % mod



    fact = [1, 1]

    inv_t = [0, 1]

    finv_t = [1, 1]

    for i in range(2, q + 1):

        fact.append((fact[-1] * i) % mod)

        inv_t.append((-inv_t[mod % i] * (mod // i)) % mod)

        finv_t.append((finv_t[-1] * inv_t[-1]) % mod)



    return cmb(q, a)





print((solve()))

def main():

    mod = 10 ** 9 + 7



    def choose(n, a, mod=mod):

        x, y = 1, 1

        for i in range(a):

            x = x * (n - i) % mod

            y = y * (i + 1) % mod

        return x * pow(y, mod - 2, mod) % mod



    x, y = list(map(int, input().split()))



    q, r = divmod(x + y, 3)

    if r != 0:

        print((0))

        return



    # b:=(+2,+1)

    d = x * 2 - y

    if d < 0 or d % 3 != 0:

        print((0))

        return



    b = d // 3

    if q < b:

        print((0))

        return

    res = choose(q, min(b, q - b), mod)

    print(res)





if __name__ == '__main__':

    main()

def solve():
    mod = 10**9 + 7
    x, y = list(map(int, input().split()))
    sum_ = x + y
    q, r = divmod(sum_, 3)
    if r != 0:
        return 0
    a = (x * 2 - y) // 3
    b = (y * 2 - x) // 3
    if a < 0 or b < 0:
        return 0

    def cmb(n, r):
        return (fact[n] * finv_t[r] * finv_t[n - r]) % mod

    fact = [1, 1]
    inv_t = [0, 1]
    finv_t = [1, 1]
    for i in range(2, q + 1):
        fact.append((fact[-1] * i) % mod)
        inv_t.append((-inv_t[mod % i] * (mod // i)) % mod)
        finv_t.append((finv_t[-1] * inv_t[-1]) % mod)
    return cmb(q, a)


print((solve()))

def main():
    mod = 10**9 + 7

    def choose(n, a, mod=mod):
        x, y = 1, 1
        for i in range(a):
            x = x * (n - i) % mod
            y = y * (i + 1) % mod
        return x * pow(y, mod - 2, mod) % mod

    x, y = list(map(int, input().split()))
    q, r = divmod(x + y, 3)
    if r != 0:
        print((0))
        return
    # b:=(+2,+1)
    d = x * 2 - y
    if d < 0 or d % 3 != 0:
        print((0))
        return
    b = d // 3
    if q < b:
        print((0))
        return
    res = choose(q, min(b, q - b), mod)
    print(res)


if __name__ == "__main__":
    main()

-def solve(): +def main(): + +    def choose(n, a, mod=mod): +        x, y = 1, 1 +        for i in range(a): +            x = x * (n - i) % mod +            y = y * (i + 1) % mod +        return x * pow(y, mod - 2, mod) % mod + -    sum_ = x + y -    q, r = divmod(sum_, 3) +    q, r = divmod(x + y, 3) -        return 0 -    a = (x * 2 - y) // 3 -    b = (y * 2 - x) // 3 -    if a < 0 or b < 0: -        return 0 - -    def cmb(n, r): -        return (fact[n] * finv_t[r] * finv_t[n - r]) % mod - -    fact = [1, 1] -    inv_t = [0, 1] -    finv_t = [1, 1] -    for i in range(2, q + 1): -        fact.append((fact[-1] * i) % mod) -        inv_t.append((-inv_t[mod % i] * (mod // i)) % mod) -        finv_t.append((finv_t[-1] * inv_t[-1]) % mod) -    return cmb(q, a) +        print((0)) +        return +    # b:=(+2,+1) +    d = x * 2 - y +    if d < 0 or d % 3 != 0: +        print((0)) +        return +    b = d // 3 +    if q < b: +        print((0)) +        return +    res = choose(q, min(b, q - b), mod) +    print(res) -print((solve())) +if __name__ == "__main__": +    main()