#include using namespace std; #include namespace mp=boost::multiprecision; template class field{ int MOD=1000000007; public: function add=[this](int a,int b){ long long A=a,B=b; return (A+B)%MOD; }; function product=[this](int a,int b){ long long A=a,B=b; return (A*B)%MOD; }; function in=[this](type a){ int comp; return typeid(comp)==typeid(a) && 0<=a && a add_inverse=[this](int a){ return (-a+MOD)%MOD; }; function product_inverse=[this](int a){ return pow(a,MOD-2); }; type one=1,zero=0; field(){ } }; template class matrix{ public: vector> value; field f; matrix(vector> value,field f){ this->value=value; this->f=f; } matrix operator + (matrix a){ vector> ret(value.size(),vector(a.value[0].size())); type temp; for(int i=value.size()-1;i>=0;--i){ for(int j=value[0].size()-1;j>=0;--j){ ret[i][j]=f.add(value[i][j],a.value[i][j]); } } return matrix(ret,f); } matrix operator * (matrix a){ vector> ret(value.size(),vector(a.value[0].size())); type temp; for(int i=value.size()-1;i>=0;i--){ for(int j=a.value[0].size()-1;j>=0;j--){ temp=f.zero; for(int k=a.value.size()-1;k>=0;k--){ temp=f.add(temp,f.product(value[i][k],a.value[k][j])); } ret[i][j]=temp; } } return matrix(ret,f); } matrix pow(long long p){ matrix temp(value,f); matrix ans=temp; bool flg=false; while(p>0){ if(p%2){ if(flg){ ans=ans*temp; }else{ flg=true; ans=temp; } } p=p/2; temp=temp*temp; } return ans; } }; int main(){ long long N; cin>>N; field f; vector> a(3,vector(3,0)); for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(i==j){ a[i][j]=1; } if((j-i+2)%3==0){ a[i][j]=1000000006; } } } vector> b(3,vector(1,0)); for(int i=0;i<3;i++){ cin>>b[i][0]; } matrix m(a,f); matrix init(b,f); matrix ans=m.pow(N-1)*init; for(int i=0;i<3;i++){ cout<