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++14 (GCC 5.4.1) (judge verdict: Accepted)

// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int dp[4111][2111],n,m,k,t;
int main()
{
	get3(n,m,k);
	t=(n+m-1)/(k-1);
	dp[0][0]=1;
	for(int i=0;i<=t;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(dp[i][j]==0)continue;
			for(int k2=0;k2<k;k2++)
			{
				int nj=j+k2,nj2=(i+1)*(k-1)-nj;
				if(nj>n||nj2>m)continue;
				dp[i+1][nj]+=dp[i][j];
				if(dp[i+1][nj]>=mod)dp[i+1][nj]-=mod;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=t;i++)
	{
		for(int j=n;j>0;j-=k-1)
		{
			if(i==t&&j!=n)continue;
			int j2=i*(k-1)-j;
			if(j2>=m)continue;
			ans+=dp[i][j];if(ans>=mod)ans-=mod;
			ans-=dp[i-1][j];if(ans<0)ans+=mod;
		}
	}
	printendl(ans);
	return 0;
}