#include<bits/stdc++.h>
using namespace std ;
typedef long long LL ;
const LL MOD = 1000003 ;
LL POW(LL a ,LL n){
LL re=1 ;
while (n>0){
if (n&1)re=re*a%MOD ;
a=a*a%MOD ;
n>>=1 ;
}
return re ;
}
LL C(int n ,int m ){
m = min(m,n-m) ;
LL a=1 ,b=1 ;
for (int i=1 ;i<=m ;i++ ){
a=a*i%MOD ;
b=b*(n+1-i)%MOD ;
}
a = POW(a,MOD-2) ;
return a*b%MOD ;
}
int main(){
int n ,m ;
cin >> n >> m ;
cout << (C(n+m,m)+MOD-1)%MOD ;
}
<div class="header"><div class="title">D2. The Wall (medium)</div><div class="time-limit"><div class="property-title">time limit per test</div>2 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>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<span class="tex-span"><sup class="upper-index"><span style="font-size:12px;">2</span></sup></span> (Handbook of Crazy Constructions) and looks for the right chapter:</p><p><span class="tex-font-style-it">How to build a wall:</span></p><ol><li><span class="tex-font-style-it">Take a set of bricks.</span> </li><li><span class="tex-font-style-it">Select one of the possible wall designs. Computing the number of possible designs is left as an exercise to the reader.</span> </li><li><span class="tex-font-style-it">Place bricks on top of each other, according to the chosen design.</span> </li></ol><p>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 <span class="tex-span"><em>n</em></span> bricks.</p><p>A <span class="tex-font-style-it">wall</span> 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 <span class="tex-span">1</span> and at most <span class="tex-span"><em>n</em></span> bricks? Two walls are different if there exist a column <span class="tex-span"><em>c</em></span> and a row <span class="tex-span"><em>r</em></span> such that one wall has a brick in this spot, and the other does not.</p><p>Along with <span class="tex-span"><em>n</em></span>, you will be given <span class="tex-span"><em>C</em></span>, the width of the wall (as defined in the easy version). Return the number of different walls modulo <span class="tex-span">10<sup class="upper-index"><span style="font-size:12px;">6</span></sup> + 3</span>.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains two space-separated integers <span class="tex-span"><em>n</em></span> and <span class="tex-span"><em>C</em></span>, <span class="tex-span">1 ≤ <em>n</em> ≤ 500000</span>, <span class="tex-span">1 ≤ <em>C</em> ≤ 200000</span>.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print the number of different walls that Heidi could build, modulo <span class="tex-span">10<sup class="upper-index"><span style="font-size:12px;">6</span></sup> + 3</span>.</p></div><div class="sample-tests"><div class="section-title">Examples</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre>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 106 + 3 is prime.
In the second sample case, the five walls are: