#include #include #include #include using namespace std; const int maxLength = 1000001; struct genom { const string array; genom(string str) : array(str){} void add(string &dst, const string &src, const int &num) { for(int i=0; i maxLength) { dst.resize(maxLength); break; } } } string expand(int &pos) { string ans; while(array[pos] != ')') { int product = 0; for(; isdigit(array[pos]); pos++) { product = product*10 + array[pos]-'0'; } if(product == 0) { while(isalpha(array[pos])) { ans += array[pos]; pos++; } } else { if(isalpha(array[pos])) { add(ans, array.substr(pos, 1), product); pos++; } else if(array[pos] == '(') { pos++; add(ans, expand(pos), product); pos++; } else { cout << "!!Error!!" << endl; } } } return ans; } }; int main() { string str; int num; while(cin >> str >> num && (str!="0" || num)) { str += ")"; genom g(str); int temp=0; string ans = g.expand(temp); if(ans.size() <= num) { cout << 0 << endl; } else { cout << ans[num] << endl; } } return 0; }