def main(): import sys input = sys.stdin.read().split() ptr = 0 T = int(input[ptr]) ptr += 1 a, b, c, d, e = map(int, input[ptr:ptr+5]) ptr +=5 mod = 10**9 +7 delta_options = [a, -a, b, -b, c, -c] offset = 10000 # since T*max_abs_delta (20*500=10000) current = [0] * (2 * offset +1) current[offset] = 1 # initial sum 0 for _ in range(T): next_dp = [0] * (2 * offset +1) for s in range(2 * offset +1): if current[s] ==0: continue for delta in delta_options: new_s_real = (s - offset) + delta if -offset <= new_s_real <= offset: new_s = new_s_real + offset next_dp[new_s] = (next_dp[new_s] + current[s]) % mod current = next_dp result = 0 for s in range(2 * offset +1): sum_val = s - offset if d <= sum_val <= e: result = (result + current[s]) % mod print(result % mod) if __name__ == "__main__": main()