#include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; int const MOD = 1e9+7; namespace Matrix { typedef vector Vec; typedef vector Mat; Mat operator * (Mat& A, Mat& B) { Mat C(A.size(), Vec(B[0].size())); rep(i, A.size()) rep(k, B.size()) rep(j, B[0].size()) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD; return C; } void operator *= (Mat& A, Mat& B) { A = A*B; } Mat operator ^ (Mat& A, ll n) { Mat B(A.size(), Vec(A.size())); rep(i, A.size()) { B[i][i] = 1; } while(n > 0) { if(n & 1) { B *= A; } A *= A; n >>= 1; } return B; } } int dp_p[6][70]; int dp_q[6][70]; int dp_r[200]; int main() { constexpr array P = {2,3,5,7,11,13}, Q = {4,6,8,9,10,12}; ll N; cin >> N; int p, q; cin >> p >> q; dp_p[0][0] = 1; rep(i, P.size()) rep(time, p) { rep(sum, P.back()*time+1) dp_p[time+1][sum+P[i]] += dp_p[time][sum]; } dp_q[0][0] = 1; rep(i, Q.size()) rep(time, q) { rep(sum, Q.back()*time+1) dp_q[time+1][sum+Q[i]] += dp_q[time][sum]; } rep(i, P.back()*p+1) rep(j, Q.back()*q+1) { dp_r[i+j] += dp_p[p][i] * dp_q[q][j]; } const int Max = p * 13 + q * 12; Matrix::Mat mat(Max, Matrix::Vec(Max)); rep(i, Max-1) mat[i][i+1] = 1; REP(i, 1, Max+1) mat[Max-1][Max-i] = dp_r[i]; mat = Matrix::operator^(mat,N+Max-1); ll ans = 0; rep(i, Max) (ans += mat[0][i]) %= MOD; cout << ans << endl; return 0; }