Problem:
Score : 1600 points

Problem Statement

There are N zeros and M ones written on a blackboard.
Starting from this state, we will repeat the following operation: select K of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those K numbers.
Here, assume that N + M - 1 is divisible by K - 1.

Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.

Find the number of the different possible values taken by this rational number, modulo 10^9 + 7.

Constraints

1 ≦ N, M ≦ 2000

2 ≦ K ≦ 2000

N + M - 1 is divisible by K - 1.

Input

The input is given from Standard Input in the following format:

N M K

Output

Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo 10^9 + 7.

Sample Input 1

2 2 2

Sample Output 1

5

There are five possible values for the number that will be eventually left on the blackboard: \frac{1}{4}, \frac{3}{8}, \frac{1}{2}, \frac{5}{8} and \frac{3}{4}.

For example, \frac{3}{8} can be eventually left if we:

Erase 0 and 1, then write \frac{1}{2}.

Erase \frac{1}{2} and 1, then write \frac{3}{4}.

Erase 0 and \frac{3}{4}, then write \frac{3}{8}.

Sample Input 2

3 4 3

Sample Output 2

9

Sample Input 3

150 150 14

Sample Output 3

937426930

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=2009,mod=1e9+7;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}
	inline int sub(int x,int y){return x>=y?x-y:x+mod-y;}
	inline int qpow(int x,int y){
		int ret=1;
		while(y){
			if(y&1) ret=1LL*x*ret%mod;
			x=1LL*x*x%mod,y>>=1;
		}
		return ret;
	}

	int f[N][N<<1][2],n,m,k,len;
	int main(){
		n=read<int>(),m=read<int>(),k=read<int>();
		if(!n || !m) puts("1"),exit(0);
		len=(n+m-1)/(k-1),f[0][0][0]=1;

		int ans=0;
		for(int i=1;i<=len;i++){
			for(int p=0;p<=min((i-1)*(k-1),m);p++){
				f[i][p][0]=add(f[i][p][0],add(f[i-1][p][1],f[i-1][p][0]));
				for(int j=1;j<k;j++) f[i][j+p][1]=add(f[i][j+p][1],add(f[i-1][p][0],f[i-1][p][1]));
			}

			for(int j=0;j<=min(m,i*(k-1));j++){
				int tmp=i*(k-1)-j+1;
				if(tmp<=n && j%(k-1)==m%(k-1) && tmp%(k-1)==n%(k-1)) ans=add(ans,f[i][j][1]);
			}
		}
		printf("%d\n",ans);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}