import sys readline=sys.stdin.readline T=int(readline()) mod=10**9+7 a,b,c,d,e=map(int,readline().split()) m=max(abs(x) for x in (a,b,c)) M=m*T dp=[0]*(2*M+1) dp[M]=1 for t in range(T): prev=dp dp=[0]*(2*M+1) for i in range(2*M+1): for di in (a,-a,b,-b,c,-c): if 0<=i+di<2*M+1: dp[i+di]+=prev[i] dp[i+di]%=mod ans=sum(dp[max(d+M,0):min(e+M+1,2*M+1)])%mod print(ans)