import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) t = int(input()) a,b,c,d,e = list(map(int, input().split())) m = 10000 dp = [0]*(2*m+1) dp[m] = 1 M = 10**9+7 for i in range(t): ndp = [0]*(2*m+1) for j in range(2*m+1): val = dp[j] if val==0: continue ndp[j+a] = (ndp[j+a] + val) % M ndp[j-a] = (ndp[j-a] + val) % M ndp[j+b] = (ndp[j+b] + val) % M ndp[j-b] = (ndp[j-b] + val) % M ndp[j+c] = (ndp[j+c] + val) % M ndp[j-c] = (ndp[j-c] + val) % M dp = ndp ans = 0 for i in range(d, e+1): ans += dp[i+m] ans %= M print(ans%M)