#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#if __cplusplus >= 201103L //#include //#include //#include //#include // //#define cauto const auto& //#else //#endif using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vint; typedef vector > vvint; typedef vector vll, vLL; typedef vector > vvll, vvLL; #define VV(T) vector > template void initvv(vector > &v, int a, int b, const T &t = T()){ v.assign(a, vector(b, t)); } template void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } #define reep(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) reep((i),0,(n)) #define ALL(v) (v).begin(),(v).end() #define PB push_back #define F first #define S second #define mkp make_pair #define RALL(v) (v).rbegin(),(v).rend() // #define DEBUG #ifdef DEBUG #define dump(x) cout << #x << " = " << (x) << endl; #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #else #define dump(x) #define debug(x) #endif #define MOD 1000000007LL #define EPS 1e-8 static const int INF=1<<24; ll add(ll a,ll b){ ll ret=a+b; ret%=MOD; return ret; } ll n; ll K; vvll vv; vvll tt; vvll calc(vvll a,vvll b){ vvll ret=a; rep(i,n+1){ rep(j,n+1){ ret[i][j]=0LL; rep(k,n+1){ ret[i][j]=add(ret[i][j],a[i][k]*b[k][j]); } } } return ret; } void foo(ll x){ while(x){ if(x&1){ tt=calc(tt,vv); } x>>=1; vv=calc(vv,vv); } } void solve(){ initvv(vv,n+1,n+1,0LL); vll a(n+1,0LL); rep(i,n) cin>>a[n-1-i]; ll ts=0LL; rep(i,n){ ts=add(ts,a[i]); } a[n]=ts; rep(i,n){ vv[0][i]=1LL; } reep(i,1,n){ vv[i][i-1]=1LL; } rep(i,n+1) vv[n][i]=1LL; initvv(tt,n+1,n+1,0LL); rep(i,n+1) tt[i][i]=1LL; rep(i,n+1){ rep(j,n+1){ // cout<>n>>K; if(K>=(1e6)+10) return solve(); vll f(K+1,0); rep(i,n) cin>>f[i+1]; vll s(K+1,0); rep(i,n){ s[i+1]=s[i]+f[i+1]; s[i+1]%MOD; } reep(i,n+1,K+1){ // cout<