#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- ll mo=1000000007; const int MAT=3; struct Mat { ll v[MAT][MAT]; }; Mat mulmat(Mat& a,Mat& b,int n=MAT) { int x,y,z; Mat r; FOR(x,n) FOR(y,n) r.v[x][y]=0; FOR(x,n) FOR(z,n) FOR(y,n) r.v[x][y] += (a.v[x][z]*b.v[z][y]) % mo; FOR(x,n) FOR(y,n) r.v[x][y]%=mo; return r; } Mat def={.v={{1,0,0},{0,1,0},{0,0,1}}}; Mat zero={.v={{0,0,0},{0,0,0},{0,0,0}}}; template class SegTree_A { public: vector val; virtual V comp(V l,V r){ return mulmat(r,l);}; SegTree_A(){val=vector(NV*2,def);}; V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]); } }; template class SegTree_B { public: vector val; V comp(V l,V r){ return mulmat(l,r);}; SegTree_B(){val=vector(NV*2,def);}; V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]); } }; int N,Q; SegTree_A AS; SegTree_B BS; template class SegTree_S{ public: vector val; SegTree_S(){val=vector(NV*2,zero);}; V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i=(l+r)/2) return getval(x,y,(l+r)/2,r,k*2+1); Mat m1=getval(x,y,l,(l+r)/2,k*2); Mat m2=getval(x,y,(l+r)/2,r,k*2+1); Mat b=BS.getval(x,y,l,(l+r)/2,k*2); Mat a=AS.getval(x,y,l,(l+r)/2,k*2); m2 = mulmat(b,m2); m2 = mulmat(m2,a); int i,j; FOR(i,3) FOR(j,3) { m1.v[i][j]+=m2.v[i][j]; if(m1.v[i][j]>=mo) m1.v[i][j]-=mo; } return m1; } void update(int x,int y,V v,int l=0,int r=NV,int k=1) { // x<=i=mo) val[k].v[i][j]-=mo; } } } }; SegTree_S SS; Mat C[101010]; ll A[3],B[3]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; cin>>A[0]>>A[1]>>A[2]; cin>>B[0]>>B[1]; FOR(i,N+1) { C[i].v[0][0]=6*i+0; C[i].v[0][1]=6*i+1; C[i].v[0][2]=6*i+2; C[i].v[1][0]=6*i+3; C[i].v[1][1]=6*i+4; C[i].v[1][2]=6*i+5; SS.update(i,i+1,C[i]); } cin>>Q; while(Q--) { cin>>s>>i; if(s=="a") { Mat m; cin>>m.v[0][0]>>m.v[0][1]>>m.v[0][2]; cin>>m.v[1][0]>>m.v[1][1]>>m.v[1][2]; cin>>m.v[2][0]>>m.v[2][1]>>m.v[2][2]; AS.update(i,m); SS.update(i,i+1,C[i]); } else if(s=="b") { Mat m; cin>>m.v[0][0]>>m.v[0][1]; cin>>m.v[1][0]>>m.v[1][1]; m.v[0][2]=m.v[1][2]=m.v[2][0]=m.v[2][1]=m.v[2][2]=0; BS.update(i,m); SS.update(i,i+1,C[i]); } else if(s=="ga") { Mat m=AS.getval(0,i); cout<<(m.v[0][0]*A[0]+m.v[0][1]*A[1]+m.v[0][2]*A[2])%mo<<" "; cout<<(m.v[1][0]*A[0]+m.v[1][1]*A[1]+m.v[1][2]*A[2])%mo<<" "; cout<<(m.v[2][0]*A[0]+m.v[2][1]*A[1]+m.v[2][2]*A[2])%mo<