MOD = 10 ** 9 + 7 T = int(input()) a, b, c, d, e = map(int, input().split()) dp = {0:1} for _ in range(T): dp2 = {} for k, v in dp.items(): for x in [a, b, c]: dp2[k + x] = dp2.get(k + x, 0) + v dp2[k - x] = dp2.get(k - x, 0) + v dp2[k + x] %= MOD dp2[k - x] %= MOD dp = dp2 ans = 0 for k, v in dp.items(): if d <= k <= e: ans += v ans %= MOD print(ans)