from collections import defaultdict t=int(input()) a,b,c,d,e=map(int,input().split()) md=10**9+7 dp=defaultdict(int) dp[0]=1 for i in range(t): ndp=defaultdict(int) for s,k in dp.items(): ndp[s+a]+=k ndp[s-a]+=k ndp[s+b]+=k ndp[s-b]+=k ndp[s+c]+=k ndp[s-c]+=k for s in ndp.keys():ndp[s]%=md dp=ndp ans=0 for s in range(d,e+1):ans=(ans+dp[s])%md print(ans)