Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC^2 (Handbook of Crazy Constructions) and looks for the right chapter:

How to build a wall:  Take a set of bricks.  Select one of the possible wall designs. Computing the number of possible designs is left as an exercise to the reader.  Place bricks on top of each other, according to the chosen design. 

This seems easy enough. But Heidi is a Coding Cow, not a Constructing Cow. Her mind keeps coming back to point 2b. Despite the imminent danger of a zombie onslaught, she wonders just how many possible walls she could build with up to n bricks.

A wall is a set of wall segments as defined in the easy version. How many different walls can be constructed such that the wall consists of at least 1 and at most n bricks? Two walls are different if there exist a column c and a row r such that one wall has a brick in this spot, and the other does not.

Along with n, you will be given C, the width of the wall (as defined in the easy version). Return the number of different walls modulo 10^6 + 3.


-----Input-----

The first line contains two space-separated integers n and C, 1 ≤ n ≤ 500000, 1 ≤ C ≤ 200000.


-----Output-----

Print the number of different walls that Heidi could build, modulo 10^6 + 3.


-----Examples-----
Input
5 1

Output
5

Input
2 2

Output
5

Input
3 2

Output
9

Input
11 5

Output
4367

Input
37 63

Output
230574



-----Note-----

The number 10^6 + 3 is prime.

In the second sample case, the five walls are: 

            B        B

B., .B, BB, B., and .B



In the third sample case, the nine walls are the five as in the second sample case and in addition the following four: 

B    B

B    B  B        B

B., .B, BB, and BB

Difficulty: interview

Starter code:

Solutions:
import math
import operator as op

from functools import reduce

from operator import mul    # or mul=lambda x,y:x*y
from fractions import Fraction

def nCk(n,k): 
  return int( reduce(mul, (Fraction(n-i, i+1) for i in range(k)), 1) )


def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, list(range(n, n-r, -1)))
    denom = reduce(op.mul, list(range(1, r+1)))
    return numer//denom

def modPow(a, x, p):
    #calculates a^x mod p in logarithmic time.
    res = 1
    while(x > 0):
        if( x % 2 != 0):
            res = (res * a) % p
            
        a = (a * a) % p
        x = int(x/2)
    return res

def modInverse(a, p):
    #calculates the modular multiplicative of a mod m.
    #(assuming p is prime).
    return modPow(a, p-2, p)

def modBinomial(n, k, p):
    #calculates C(n,k) mod p (assuming p is prime).

    # n * (n-1) * ... * (n-k+1)
    numerator = 1 
    for i in range(k):
        numerator = (numerator * (n-i) ) % p

    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % p

    # numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p


n, c = input().split()
n = int(n)
c = int(c)

#test = [0 for x in range (n+1)]
#test[1] = c

#for i in range(2, n+1):
#    test[i] = (test[i-1] + modBinomial((i+c-1),i, 1000003))%1000003

#ans = solve(n, c)
#ans =test[n]
ans = modBinomial((c+n),c,1000003) - 1
print(int(ans))


import math 
m = int(1e6 + 3)
a,b = input().split()
a = int(a)
b = int(b)
A = 1
B = 1
for i in range(2,a + b + 1):
    A=(A*i)%m
    if i<=a:
        B=(B*i)%m
    if i<=b:
        B=(B*i)%m
print((A*pow(B,m-2,m)-1)%m)

n, c = list(map(int, input().split()))
mod = 10 ** 6 +3
inv = [0, 1]
for i in range(2, max(n, c) + 1):
    inv.append(inv[mod % i] * (mod - mod // i) % mod)
ans = 1
for i in range(1, n + c + 1):
    ans = ans * i % mod
for i in range(1, c + 1):
    ans = ans * inv[i] % mod
for i in range(1, n + 1):
    ans = ans * inv[i] % mod
ans += mod - 1
ans %= mod
print(ans)



import sys
#with open(filename, 'r') as f:
with sys.stdin as f:
    n, C = f.readline().split(" ")
    n, C = int(n), int(C)
p = 1000003

def compute_mod_fact(n, p):
    # n! (mod p)
    res = 1
    for i in range(1, n+1):
        res = (res * i) % p
    return res
def compute_mod_mult(n, a, p):
    # n**a (mod p)
    res = 1
    for _ in range(a):
        res = (res * n) % p
    return res
res = compute_mod_fact(n+C, p)
res1 = compute_mod_fact(n, p)
res1 = compute_mod_mult(res1, p-2, p)
res2 = compute_mod_fact(C, p)
res2 = compute_mod_mult(res2, p-2, p)
#print(res, res1, res2)
res = (res * res1 * res2 - 1) % p 
print(res)