#include #include #include #include #include #include #include using namespace std; struct Node{ virtual int show(int)=0; }; struct Repeat : Node{ int n; vectorpattern; Repeat(int n,vectorpattern):n(n),pattern(pattern){} virtual int show(int q){ int t=0; for(int i=0;ishow(q-t); } } return t; } }; struct Leaf : Node{ char c; Leaf(char c):c(c){} virtual int show(int n){ if(n==0)throw c; return 1; } }; Node*parseOne(const char*&p){ char*q=0; int v = strtol(p,&q,10); if(p==q){ if(!isalpha(*p))return 0; return new Leaf(*p++); }else{ vectorpat; if(*q=='('){ p=q+1; for(;Node*v=parseOne(p);){ pat.push_back(v); } assert(*p==')'); ++p; }else{ p=q; pat.push_back(parseOne(p)); } return new Repeat(v,pat); } } Node*parse(const char*p){ vectorpat; for(;Node*v=parseOne(p);){ pat.push_back(v); } return new Repeat(1,pat); } int main(){ string s; ifstream cin("./E1"); for(;;){ cin>>s; int n;cin >> n; if(s=="0" && n == 0)return 0; try{ parse(s.c_str())->show(n); cout << 0 << endl; }catch(char q){ cout << q << endl; } } }