#include using namespace std; typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; typedef pair PLL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FF first #define SS second template istream& operator>>(istream& is, pair& p){ return is >> p.FF >> p.SS; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9+7; typedef vector Col; typedef vector Matrix; Matrix mul(const Matrix& A, const Matrix& B){ const int R = A.size(), C = B[0].size(), sz = B.size(); Matrix AB(R, Col(C)); for(int i=0;i0){ if(n&1) p = mul(p, w); w = mul(w, w); n >>= 1; } return p; } Matrix kitamasa(const Matrix& A, LL n){ const int K = SZ(A); Matrix u(1, Col(K,0)); u[0][0] = 1; Matrix p = A; for(;n>0;n>>=1){ if(n%2 == 1){ u = mul(u, p); } Matrix next_e1(1, Col(K)); for(int i=0;i> N >> P >> C; dp1[0][0][0] = 1; for(int i=0;i<6;++i) for(int j=0;j<=P;++j) for(int k=j;k<=P;++k){ int tmp = ps[i]*(k-j); for(int n=0;n+tmp pat(D); REP(n1,MAX) REP(n2,MAX) (pat[n1+n2] += dp1[6][P][n1] * dp2[6][C][n2]) %= MOD; Matrix p(D, Col(D)); REP(i,D-1) p[i][i+1] = 1; FOR(i,1,D) p[D-1][D-i] = pat[i]; p = kitamasa(p, N); Matrix init(D, Col(1)); init[0][0] = 1; REP(y,D){ for(int x=0;y+x