mod = 10 ** 9 + 7 T = int(input()) a, b, c, d, e = map(int, input().split()) abc = (abs(a), abs(b), abs(c)) U = 10000 MAX = 2 * U + 1 dp = [0] * MAX dp[U] = 1 while T: T -= 1 newDP = [0] * MAX for i in range(MAX): for x in abc: if i + x < MAX: newDP[i + x] += dp[i] if newDP[i + x] >= mod: newDP[i + x] -= mod if i - x >= 0: newDP[i - x] += dp[i] if newDP[i - x] >= mod: newDP[i - x] -= mod dp = newDP ans = 0 for i in range(d, e + 1): ans += dp[i + U] if ans >= mod: ans -= mod print(ans)