Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.

A k-tree is an infinite rooted tree where:

  each vertex has exactly k children;  each edge has some weight;  if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k. 

The picture below shows a part of a 3-tree.

 

 [Image]

    As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".

Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7). 


-----Input-----

A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).


-----Output-----

Print a single integer — the answer to the problem modulo 1000000007 (10^9 + 7). 


-----Examples-----
Input
3 3 2

Output
3

Input
3 3 3

Output
1

Input
4 3 2

Output
6

Input
4 5 2

Output
7

Difficulty: interview

Starter code:

Solutions:
ans = {}

def gen(n, k, d, used = False):
    if not ans.get((n, k, d, used)):
        if not n and used:
            ans[(n, k, d, used)] = 1
        else:
            ans[(n, k, d, used)] = sum(gen(n - x, k, d, used or x >= d) for x in range(1, min(n, k) + 1) if max(x, n - x) >= d or used)
    return ans[(n, k, d, used)]


n, k, d = list(map(int, input().split()))
print(gen(n, k, d)  % 1000000007)


n, k, d = list(map(int,input().split()))
f = [0]*(n+k+1)
f_ = [0]*(n+k+1)
f_[0] = 1
for i in range(1,n+1):
    for j in range(1,k+1):
        f[i] += f[i-j]
    for j in range(d,k+1):
        f[i] += f_[i-j]
    for j in range(1,d):
        f_[i] += f_[i-j]
print(f[n]%(10**9 +7))


import collections


def count(n, k):

    m = collections.defaultdict(lambda: 0)
    m[0] = 1
    for i in range(1, n + 1):

        for j in range(1, k + 1):

            if i - j in m:

                m[i] += m[i - j]

    return m[n]

n, k, d = tuple(map(int, str.split(input())))
print((count(n, k) - count(n, d - 1)) % (10 ** 9 + 7))


import random
import sys
Q = 10 ** 9 + 7
n, k, d = map(int, input().split())
dp = [0] * 105
dp1 = [0] * 105
dp[0] = 1
dp1[0] = 1 
for i in range(1, n + 1):
    for j in range(max(0, i - k), i):
        dp[i] = (dp[i] + dp[j]) % Q
    for j in range(max(0, i - d + 1), i):
        dp1[i] = (dp1[i] + dp1[j]) % Q
print((dp[n] - dp1[n] + Q) % Q)

import random
import sys
Q = 10 ** 9 + 7
n, k, d = map(int, input().split())
dp = [0] * 105
dp1 = [0] * 105
dp[0] = 1
dp1[0] = 1 
for i in range(1, n + 1):
    for j in range(max(0, i - k), i):
        dp[i] = (dp[i] + dp[j])
    for j in range(max(0, i - d + 1), i):
        dp1[i] = (dp1[i] + dp1[j])
print((dp[n] - dp1[n])% Q)

import sys

f = sys.stdin
n, k, d = list(map(int, f.readline().strip().split()))

Nd = [[1]*(n+1), [1]*(n+1)]
Nd[1][0] = 0
Nd[1][1] = 0

for i in range(2,n+1):
    N = 0
    for j in range(1,k+1):
        if i>=j:
            N += Nd[0][i-j]
    Nd[0][i] = N

    # if i==2: continue
    N = 0
    for j in range(1,k+1):
        if i>=j:
            if j>=d:
                N += Nd[0][i-j]
            else:
                N += Nd[1][i-j]
    Nd[1][i] = N
    
    #print(Nd)

if d>1:
    print(Nd[1][n] % 1000000007)
else:
    print(Nd[0][n] % 1000000007)    



n, k, d = map(int, input().split())
f, g, d, m = [0] * (n + 1), [1] * (n + 1), 1 - d, 1000000007
for i in range(1, n + 1):
    f[i] = (sum(g[j] for j in range(max(0, i - k), d + i)) + sum(f[j] for j in range(max(0, d + i), i))) % m
    g[i] = sum(g[j] for j in range(max(0, i - k), i)) % m
print(f[n])

n, k, d = map(int, input().split())
a = [1]
b = [0]
for i in range(1, n + 1):
    a.append(sum(a[max(i - d + 1, 0):]))
    b.append(sum(a[max(i - k, 0):max(i - d + 1, 0)]) + sum(b[max(i - k, 0):]))
print(b[n] % 1000000007)

n, k, d = map(int, input().split())
M = 1000000007
a = [1] + [0] * n
for i in range(1, n + 1):
  for j in range(max(0, i - k), i):
    a[i] = (a[i] + a[j]) % M
# print(a)
b = [1] + [0] * n
for i in range(1, n + 1):
  for j in range(max(0, i - d + 1), i):
    b[i] = (b[i] + b[j]) % M
# print(b)
print((a[n] - b[n]) % M)

n, k, d = map(int, input().split())
a = [1]
b = [0]
for i in range(1, n + 1):
    a.append(sum(a[max(i - d + 1, 0):]))
    b.append(sum(a[max(i - k, 0):max(i - d + 1, 0)]) + sum(b[max(i - k, 0):]))
print(b[n] % (10**9+7))

__author__ = 'epeshk'
def admod(a,b):
    a+=b
    if a>1e9+7:
        a-=1e9+7
    return a
n,k,d=list(map(int,input().split()))
Dp=[[1,0]]
for i in range(1,n+1):
    Dp.append([0,0])
    for j in range (1,k+1):
        if i-j<0:   break
        if j<d:
            Dp[i][0]=admod(Dp[i][0],Dp[i-j][0])
            Dp[i][1]=admod(Dp[i][1],Dp[i-j][1])
        else:
            Dp[i][1]=admod(Dp[i][1],Dp[i-j][0])
            Dp[i][1]=admod(Dp[i][1],Dp[i-j][1])
print(int(Dp[n][1]))

n,k,d=list(map(int, input().split()))
dp={}
vis=[]

def F(curr, poss):
    if curr<0:
        return 0
    if curr==0 and poss==1:
        return 1
    if (curr, poss) in vis:
        return dp[(curr, poss)]
    i=1
    vis.append((curr, poss))
    dp[(curr, poss)]=0
    while i<d:
        dp[(curr, poss)]+=F(curr-i, poss)
        i+=1
    i=d
    while i<=k:
        dp[(curr, poss)]+=F(curr-i, 1)
        i+=1
    return dp[(curr, poss)]%1000000007
    
print(F(n, 0))


# -*- coding: utf-8 -*-

(n, k, d) = list(map(int, input().split()))

def get_ways(n, upper_bound):
    ways = [1] + [0] * n
    for i in range(1, n + 1):
        ways[i] = sum(ways[max(0, i - upper_bound):i])
    return ways[n]

print((get_ways(n, k) - get_ways(n, d - 1)) % (10 ** 9 + 7))


b = [False] * 101
x = [0] * 101
def count(w, k1):
    if w == 0:
        return 1
    elif w < 0:
        return 0

    ans = 0
    for i in range(1, k1+1):
        if w-i < 0:
            break
        if b[w - i]:
            ans = ans + x[w - i];
        else:
            x[w-i] =  count(w - i, k1)
            ans = ans + x[w - i];
            b[w - i] = True;
    b[w] = True;
    x[w] = ans;
    return ans;

n, k, d = map(int,input().split())
x[0] = 1;
ans = count(n, k);
b = [False] * 101
x = [0] * 101
x[0] = 1;
ans = ans - count(n, min(k, d-1));
print(ans % 1000000007)

import random
import sys
Q = 10 ** 9 + 7
n, k, d = map(int, input().split())
dp = [0] * 105
dp1 = [0] * 105
dp[0] = 1
dp1[0] = 1 
for i in range(1, n + 1):
    for j in range(max(0, i - k), i):
        dp[i] = (dp[i] + dp[j])
    for j in range(max(0, i - d + 1), i):
        dp1[i] = (dp1[i] + dp1[j])
print((dp[n] - dp1[n])% Q)

def solve(n, k, d, e, memo):
	if n < 0:
		return 0
	if n == 0:
		return e
	if (n, e) in memo:
		return memo[(n, e)]
	ans = 0
	for i in range(1, d):
		ans += solve(n - i, k, d, e, memo)
	for i in range(d, k + 1):
		ans += solve(n - i, k, d, 1, memo)
	memo[(n, e)] = ans % 1000000007
	return ans % 1000000007

n, k, d = (int(x) for x in input().split())
print(solve(n, k, d, 0, dict()))


mem = [[-1 , -1] for x in range(0 , 103)]

n , k , d = list(map(int , input().split()))

def dp(remain,has_d):
    if remain == 0:
        return has_d
    if remain < 0:
        return 0
    if mem[remain][has_d] != -1:
        return mem[remain][has_d]
    mem[remain][has_d] = 0
    for i in range(1 , min(remain,k)+1):
        if i >= d :
            mem[remain][has_d] += dp(remain - i , 1)
        else :
            mem[remain][has_d] += dp(remain - i , has_d)
    return mem[remain][has_d]

print(dp(n,0)%(10**9 + 7))


#!/usr/bin/env python3

total_weight, children, at_least_one = [int(x) for x in input().split()]
# print("Total weight: ", total_weight)
# print("Total children: ", children)
# print("At least one of these: ", at_least_one)



# from math import factorial
# def combination(n,r):
# 	return factorial(n)//factorial(n-r)// factorial(n-r)
at_least_weights = [0] * (total_weight + 1)
not_least_weights = [0] * (total_weight + 1)
if total_weight < at_least_one:
	print(0)
elif total_weight == at_least_one:
	print(1)
else:
	not_least_weights[0] = 1
	for x in range(1, total_weight + 1):
		for y in range(1, at_least_one):
			if x - y >= 0:
				not_least_weights[x] += not_least_weights[x-y]
				at_least_weights[x] += at_least_weights[x-y]
		for z in range(at_least_one, children + 1):
			if x - z >= 0:
				at_least_weights[x] += at_least_weights[x-z]
				at_least_weights[x] += not_least_weights[x-z]				
	# print(at_least_weights)
	print(at_least_weights[total_weight] % 1000000007)




MOD = 10**9 + 7
n, k, d = [int(k) for k in input().split()]

ways1 = [0]*(n+1)
ways1[0] = 1
ways1[1] = 1
for i in range(2,n+1):
    for j in range(max(0,i-k),i):
        ways1[i] += ways1[j]
    ways1[i] %= MOD
#print(ways1)

ways2 = [0]*(n+1)
ways2[0] = 1
ways2[1] = 1

if d ==1:
    ways2[0] = 0
    ways2[1] = 0
    
for i in range(2,n+1):
    for j in range(max(0,i-(d-1)),i):
        ways2[i] += ways2[j]
    ways2[i] %= MOD
#print(ways2)
print((ways1[n]-ways2[n]) % MOD)

# 431C

from sys import stdin
import math

__author__ = 'artyom'


def read_int_ary():
  return map(int, stdin.readline().strip().split())


n, k, d = read_int_ary()

cache = {0: {}, 1: {}}


def f(a, has_d):
  calced = cache[has_d].get(a)
  if calced:
    return calced
  if a < d and not has_d:
    return 0
  if a <= 1 or (a <= d and not has_d):
    return 1
  sum = 0
  x = 1
  while x <= k and a - x >= 0:
    sum += f(a - x, has_d or x >= d)
    x += 1
  cache[has_d][a] = sum
  return sum


print(f(n, 0) % 1000000007) if n >= d else print(0)

inputs = [int(x) for x in input().split()]
 
desired_weight = inputs[0]
k = inputs[1]
min_weight = inputs[2]

# desired_weight = 38
# k = 16
# min_weight = 15
# 

# desired_weight = 3
# k = 3
# min_weight = 3

saved = [{True: None, False: None} for i in range(desired_weight + 1)]
saved[desired_weight] = {True: 0, False: 0}

modulo = 1000000007

for i in reversed(range(0, desired_weight)):
#     print('*** ' + str(i) + ' ***')
    range_to_work_with = i + k
    hit_min_value = 0
    fail_to_hit_min_value = 0

    
    travel_range = range(i + 1, i + k + 1 if i + k + 1 <= desired_weight + 1 else desired_weight + 1)
#     print(travel_range)
    for j in travel_range:
        if j - i >= min_weight:
            fail_to_hit_min_value += saved[j][True]
        else:
            fail_to_hit_min_value += saved[j][False]
    fail_to_hit_min_value += 1 if desired_weight - i <= k and desired_weight - i >= min_weight else 0
            
    for j in travel_range:
        hit_min_value += saved[j][True]
    hit_min_value += 1 if desired_weight - i <= k else 0
    
    saved[i][True] = hit_min_value
    saved[i][False] = fail_to_hit_min_value
            

# print(saved)     
print(saved[0][False] % modulo)

n, k, d = map(int, input().split())
dp = [[0 for j in range(2)] for i in range(105)]
dp[0][1] = 1

for i in range(1, n+1):
    for j in range(1, min(i, k)+1):
        dp[i][0] = (dp[i][0] + dp[i-j][j >= d]) % 1000000007
        dp[i][1] = (dp[i][1] + dp[i-j][1]) % 1000000007

print(dp[n][0])

#!/usr/bin/env python3

def F(n, k):
    if k < 2:
        return k
    b = [0] * (k - 1) + [1]
    for i in range(n):
        b.append(sum(b[-k:]) % (10 ** 9 + 7))
    return b[-1]

n, k, d = list(map(int, input().split()))

ans = F(n, k) - F(n, d - 1)
if ans < 0:
    ans += 10 ** 9 + 7

print(ans)