// Template {{{ #include #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef long long LL; #ifdef LOCAL #include "contest.h" #else #define dump(x) #endif class range { struct Iterator { int val, inc; int operator*() {return val;} bool operator!=(Iterator& rhs) {return val < rhs.val;} void operator++() {val += inc;} }; Iterator i, n; public: range(int e) : i({0, 1}), n({e, 1}) {} range(int b, int e) : i({b, 1}), n({e, 1}) {} range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {} Iterator& begin() {return i;} Iterator& end() {return n;} }; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; inline bool valid(int x, int w) { return 0 <= x && x < w; } void iostream_init() { ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(12); } //}}} // ModInt (ref. anta) {{{ template struct ModInt{ static const int Mod = MOD; unsigned val; ModInt():val(0){} ModInt(unsigned x):val(x%MOD){} ModInt(signed x) { int y = x % MOD; if(y < 0) y += MOD; val = y; } ModInt(signed long long x) { int y = x % MOD; if(y < 0) y += MOD; val = y; } ModInt &operator+=(ModInt rhs) { val += rhs.val; if(val >= MOD) val -= MOD; return *this; } ModInt &operator-=(ModInt rhs) { val += MOD - rhs.val; if(val >= MOD) val -= MOD; return *this; } ModInt &operator*=(ModInt rhs) { val = (unsigned long long)val * rhs.val % MOD; return *this; } ModInt &operator/=(ModInt rhs) { return *this *= rhs.inv(); } ModInt inv() const { signed a = val, b = MOD, u = 1, v = 0; while(b) { signed t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } if(u < 0) u += MOD; ModInt res; res.val = u; return res; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } // compare bool operator==(ModInt rhs) const { return val == rhs.val; } bool operator!=(ModInt rhs) const { return val != rhs.val; } bool operator< (ModInt rhs) const { return val < rhs.val; } bool operator<=(ModInt rhs) const { return val <= rhs.val; } bool operator> (ModInt rhs) const { return val > rhs.val; } bool operator>=(ModInt rhs) const { return val >= rhs.val; } }; template ostream& operator << (ostream& os, const ModInt m) { return os << m.val; } template ModInt pow(ModInt a, T b) { if(b == 0) { return 1; } else { auto w = pow(a*a, b/2); if(b&1) w *= a; return w; } } // }}} typedef ModInt<1000000007> mint; // {{{ http://nitcoder000.hatenablog.com/entry/kitamasa #define MAX_LOGN 64 #define reE(i,a,b) for(auto (i)=(a);(i)<=(b);(i)++) #define rE(i,b) reE(i,0,b) #define reT(i,a,b) for(auto (i)=(a);(i)<(b);(i)++) #define rT(i,b) reT(i,0,b) #define rep(i,a,b) reE(i,a,b); #define rev(i,a,b) for(auto (i)=(b)-1;(i)>=(a);(i)--) #define itr(i,b) for(auto (i)=(b).begin();(i)!=(b).end();++(i)) #define all(b) (b).begin(),(b).end() template struct Mr{ vector first; vector C; vector> bin; T zero,one; int M; //n(1,,,2M)をn(1,,,M)に修正、O(M^2) void form(vector &n){ rev(i, M + 1, 2 * M + 1){ reE(j, 1, M)n[i - j] = (n[i - j] + (C[M - j] * n[i])); n[i] = zero; } } //lとrを足し合わせる、O(M^2) void add(vector &l, vector &r, vector &ans){ reE(i, 1, 2 * M)ans[i] = zero; reE(i, 1, M)reE(j, 1, M)ans[i + j] = (ans[i + j] + (l[i] * r[j])); form(ans); } //初期化、O(M*MAX_LOGN) Mr(const vector& f,const vector& c,int m,T e1,T e0){ M = m; first.reserve(M + 1);C.reserve(M); zero = e0, one = e1; first.push_back(zero); rT(i, M){ first.push_back(f[i]); C.push_back(c[i]); } bin.resize(MAX_LOGN); rT(i, MAX_LOGN)bin[i].resize(2*M+1); rE(i, 2*M)bin[0][i] = zero; bin[0][1] = one; reT(i,1, MAX_LOGN){ add(bin[i - 1], bin[i - 1], bin[i]); } } //N項目の計算、戻り値がTの形であることに注意、O(M^2*logN) pair> calc(LL n){ n--; vector tmp,result = bin[0]; for (int b = 0; n; b++,n>>=1) if (1 & n){ tmp = result; add(tmp, bin[b], result); } T ans = zero; reE(i, 1, M)ans = ans + (result[i] * first[i]); return make_pair(ans, result); } pair> next(vector result) { vector tmp = result; add(tmp, bin[0], result); T ans = zero; reE(i, 1, M)ans = ans + (result[i] * first[i]); return make_pair(ans, result); } }; // }}} // vector generate(int P, vector a) { assert(a.size() == 6); int K = P * a.back() + 1; const int MAX_S = 651; mint dp[MAX_S][6] = {}; dp[0][0] = 1; REP(_, P) { mint ndp[MAX_S][6] = {}; REP(s, MAX_S) REP(i, 6) { for(int j = i; j < 6; j++) { int ns = s + a[j]; int ni = j; if(ns < MAX_S) { ndp[ns][ni] += dp[s][i]; } } } REP(i, MAX_S) REP(j, 6) dp[i][j] = ndp[i][j]; } vector res(K); REP(i, K) REP(j, 6) res[i] += dp[i][j]; return res; } int main(){ iostream_init(); LL n; while(cin >> n) { int P, C; cin >> P >> C; vector dp1 = generate(P, {2, 3, 5, 7, 11, 13}); vector dp2 = generate(C, {4, 6, 8, 9, 10, 12}); vector dp(dp1.size() + dp2.size() - 2); REP(i, dp1.size()) REP(j, dp2.size())if(i+j > 1) dp[i+j-1] += dp1[i] * dp2[j]; int K = dp.size(); vector first(K); first[K-1] = 1; vector cof(K); for(int i = 0; i < K; i++) cof[i] = dp[K-1-i]; Mr kitamasa(first, cof, K, mint(1), mint(0)); vector ps(K); vector result; bool isfirst = true; for(LL i = n-1-(K-1), j=K-1; i <= n-1; i++, j--) { assert(n-1-j == i); assert(j < ps.size() && j >= 0); if(i > 0) { if(isfirst) { isfirst = false; auto p = kitamasa.calc(i + K); ps[j] = p.first; result = p.second; } else { auto p = kitamasa.next(result); ps[j] = p.first; result = p.second; } } else { ps[j] = (i == 0 ? 1 : 0); } } mint ans = 0; REP(i, ps.size()) { for(int j = i; j < K; j++) { ans += dp[j] * ps[i]; } } cout << ans << endl; } return 0; } /* vim:set foldmethod=marker: */