t = int(input()) a, b, c, d, e = map(int, input().split()) M = 1000000007 m = 20020 s = 10010 dp = [0 for i in range(m)] dp[s] = 1 for i in range(t): nex = [0 for i in range(m)] for j in range(m): if dp[j] > 0: nex[j + a] = (nex[j + a] + dp[j]) % M nex[j - a] = (nex[j - a] + dp[j]) % M nex[j + b] = (nex[j + b] + dp[j]) % M nex[j - b] = (nex[j - b] + dp[j]) % M nex[j + c] = (nex[j + c] + dp[j]) % M nex[j - c] = (nex[j - c] + dp[j]) % M dp = nex ans = 0 for i in range(s + d, s + e + 1): ans = (ans + dp[i]) % M print(ans)