import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int[] arr = new int[6]; int count = 0; int max = 0; for (int i = 0; i < 3; i++) { arr[i] = sc.nextInt(); arr[i + 3] = -arr[i]; max = Math.max(max, Math.abs(arr[i])); } int d = sc.nextInt(); int e = sc.nextInt(); HashMap[] maps = new HashMap[t + 1]; maps[0] = new HashMap<>(); maps[0].put(0, 1); for (int i = 1; i <= t; i++) { maps[i] = new HashMap<>(); for (Map.Entry entry : maps[i - 1].entrySet()) { int x = entry.getKey(); int y = entry.getValue(); for (int z : arr) { if (x + z + max * (t - i) < d) { continue; } if (x + z - max * (t - i) > e) { continue; } if (maps[i].containsKey(x + z)) { maps[i].put(x + z, (maps[i].get(x + z) + y) % MOD); } else { maps[i].put(x + z, y); } } } } int total = 0; for (int i = d; i <= e; i++) { if (maps[t].containsKey(i)) { total += maps[t].get(i); total %= MOD; } } System.out.println(total); } }