using System; using System.Collections.Generic; using System.Linq; using System.IO; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; static void Main() { int t = sc.Int; if (t < 1 || 500 < t) throw new Exception(); int a, b, c, d, e; sc.Multi(out a, out b, out c, out d, out e); if (a < -20 || 20 < a) throw new Exception(); if (b < -20 || 20 < b) throw new Exception(); if (c < -20 || 20 < c) throw new Exception(); if (a == 0 && b == 0 && c == 0) throw new Exception(); if (d > e || d < -10000 || e > 10000) throw new Exception(); int m = 22000; var dp = new int[m]; int s = 11000; dp[s] = 1; for (int i = 0; i < t; i++) { var next = new int[m]; for (int j = 0; j < m; j++) { if (dp[j] > 0) { next[j + a] = (next[j + a] + dp[j]) % M; next[j - a] = (next[j - a] + dp[j]) % M; next[j + b] = (next[j + b] + dp[j]) % M; next[j - b] = (next[j - b] + dp[j]) % M; next[j + c] = (next[j + c] + dp[j]) % M; next[j - c] = (next[j - c] + dp[j]) % M; } } dp = next; } int ans = 0; for (int i = s + d; i <= s + e; i++) ans = (ans + dp[i]) % M; Prt(ans); sw.Flush(); } static void Prt(string a) => sw.WriteLine(a); static void Prt(IEnumerable a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq() => typeof(T).Equals(typeof(U)); T ct(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv(string s) => eq() ? ct(int.Parse(s)) : eq() ? ct(long.Parse(s)) : eq() ? ct(double.Parse(s)) : eq() ? ct(s[0]) : ct(s); public void Multi(out T a) => a = cv(Str); public void Multi(out T a, out U b) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); } public void Multi(out T a, out U b, out V c) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); } public void Multi(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); } public void Multi(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); e = cv(ar[4]); } }