import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): t = int(input()) a,b,c,d,e = map(int, input().split()) from collections import defaultdict mod = 10**9+7 N = 10**4+50 dp = [0]*(2*N+1) dp[N] = 1 for i in range(t): ndp = [0]*(2*N+1) for k in range(2*N+1): if dp[k] == 0: continue for dk in [a, -a, b, -b, c, -c]: if 0 <= k+dk <= 2*N: ndp[k+dk] += dp[k] ndp[k+dk] %= mod dp = ndp ans = 0 for i in range(d, e+1): ans += dp[N+i] ans %= mod print(ans) if __name__ == '__main__': main()