/* -*- coding: utf-8 -*- * * 612.cc: No.612 Move on grid - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_T = 500; const int MAX_A = 20; const int MAX_X = MAX_T * MAX_A * 2 + 1; typedef long long ll; const ll MOD = 1000000007; /* typedef */ /* global variables */ ll dp[2][MAX_X]; /* subroutines */ inline void addmod(ll &a, ll b) { a = (a + b) % MOD; } /* main */ int main() { int t, a, b, c, d, e; scanf("%d%d%d%d%d%d", &t, &a, &b, &c, &d, &e); a = abs(a), b = abs(b), c = abs(c); int ox = max(max(a, b), c) * t; int maxx = ox * 2 + 1; dp[0][ox] = 1; int cur = 0, nxt = 1; for (int i = 0; i < t; i++) { memset(dp[nxt], 0, sizeof(dp[nxt])); for (int x = 0; x < maxx; x++) if (dp[cur][x] > 0) { if (x - a >= 0) addmod(dp[nxt][x - a], dp[cur][x]); if (x + a < maxx) addmod(dp[nxt][x + a], dp[cur][x]); if (x - b >= 0) addmod(dp[nxt][x - b], dp[cur][x]); if (x + b < maxx) addmod(dp[nxt][x + b], dp[cur][x]); if (x - c >= 0) addmod(dp[nxt][x - c], dp[cur][x]); if (x + c < maxx) addmod(dp[nxt][x + c], dp[cur][x]); } cur ^= 1, nxt ^= 1; } ll sum = 0; for (int x = d + ox; x <= e + ox; x++) addmod(sum, dp[cur][x]); printf("%lld\n", sum); return 0; }