T = int(input()) a, b, c, d, e = map(int, input().split()) dp = [[0]*20001 for _ in range(2)] dp[0][10000] = 1 MOD = 10**9+7 for i in range(T): for j in range(20001): dp[(i+1)&1][j] = 0 for j in range(20001): if 0<=j+a<=20000: dp[(i+1)&1][j] += dp[i&1][j+a] dp[(i+1)&1][j] %= MOD if 0<=j-a<=20000: dp[(i+1)&1][j] += dp[i&1][j-a] dp[(i+1)&1][j] %= MOD if 0<=j+b<=20000: dp[(i+1)&1][j] += dp[i&1][j+b] dp[(i+1)&1][j] %= MOD if 0<=j-b<=20000: dp[(i+1)&1][j] += dp[i&1][j-b] dp[(i+1)&1][j] %= MOD if 0<=j+c<=20000: dp[(i+1)&1][j] += dp[i&1][j+c] dp[(i+1)&1][j] %= MOD if 0<=j-c<=20000: dp[(i+1)&1][j] += dp[i&1][j-c] dp[(i+1)&1][j] %= MOD ans = 0 for i in range(d+10000, e+10001): ans += dp[T&1][i] ans %= MOD print(ans)