#include #include #include #include #include #include #include #include #include #include #include #include #include #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define DEBUG(x) cout<<#x<<": "< P; typedef long long int LL; int N,d; string S; vector form(int& i); vector dform(int& i); vector pform(int& i); vector mform(int& i); int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>N; cin>>d; d++; cin>>S; int i=0; vector res=pform(i); cout< form(int& i) { vector res(d,0); if(S[i]!='d'){ return pform(i); }else{ return dform(i); } } vector pform(int& i) { //cout<<'p'< res(d,0); while(true){ vector tmp; if(S[i]!='d') tmp=mform(i); else tmp=dform(i); REP(j,d){ res[j]+=tmp[j]; } if(S[i]!='+'){ return res; } i++; if(i>=N) return res; } } vector dform(int& i) { //cout<<'d'< res=pform(i); REP(j,d-1){ res[j]=(res[j+1])*(j+1); res[j+1]=0; } i++; return res; } vector mform(int& i) { //cout<<'m'< res(d,0); int m=1; if(S[i]!='x'){ m=S[i]-'0'; i+=2; } int c=1; i++; while(S[i]=='*'){ c++; i++; if(S[i]!='x'){ m=S[i]-'0'; i+=2; } i++; } //DEBUG(c); res[c]+=m; return res; }