Problem:
Score : 800 points

Problem Statement

Snuke has a string x of length N.
Initially, every character in x is 0.

Snuke can do the following two operations any number of times in any order:

Choose A consecutive characters in x and replace each of them with 0.

Choose B consecutive characters in x and replace each of them with 1.

Find the number of different strings that x can be after Snuke finishes doing operations.
This count can be enormous, so compute it modulo (10^9+7).

Constraints

1 \leq N \leq 5000

1 \leq A,B \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).

Sample Input 1

4 2 3

Sample Output 1

11

For example, x can be 0011 or 1111 in the end, but cannot be 0110.

Sample Input 2

10 7 2

Sample Output 2

533

Sample Input 3

1000 100 10

Sample Output 3

828178524

Solution in PyPy3 (7.3.0) (judge verdict: Time Limit Exceeded)

n,aa,bb = list(map(int, input().split()))

a = max(aa,bb)
b = min(aa,bb)
p = 1000000007

def calc(a,b,p):

    xs0 = [0]*(n+1)
    os0 = [0]*(n+1)
    
    os0[0] = 1
    
    for i in range(b,a-1):
        for j in range(b,i+1):
            xs0[i] += os0[i-j]
            xs0[i] %= p
        for j in range(1,i+1):
            os0[i] += xs0[i-j]
            os0[i] %= p
    
    
    #print(xs0[:50])
    #print(os0[:50])
    
    os = [0]*a
    
    for i in range(b,a-2): #number-x
        for j in range(2,a-i): # adding o
            os[i+j] += xs0[i] * (j-1)
    
    x = [0]*(n+1)
    o = [0]*(n+1)
    
    for i in range(b+1,a): # adding distination
        for j in range(b,i): # length of xs
            o[i] += xs0[j]
            o[i] %= p
    
    x[0] = 1
    o[0] = 1
    
    for i in range(1,n+1):
        for j in range(1,min(b,i+1)):
            x[i] += o[i-j]
        for j in range(1,min(a,i+1)):
            o[i] += x[i-j]
        for j in range(b+2,min(a,i+1)):
            o[i] += x[i-j]*os[j]
        x[i] %= p
        o[i] %= p
    
    for i in range(b+1,a):
        for j in range(b,i):
            o[n] += xs0[j] * x[n-i]
            o[i]%=p
    
    ans = o[n] + x[n]
    ans %= p
    
    #print(ans)
    
    beki2 = [1]*5001
    
    for i in range(5000):
        beki2[i+1] = beki2[i]*2
        beki2[i+1] %= p
    
    ans = beki2[n] - ans
    ans += p
    ans %= p
    return ans

print(calc(a,b,p))