#include #include #include #include using namespace std; string input; int cnt; int target; int solve(int pos) { int n = 0, endPos = INT_MAX; while (input[pos] >= '0' && input[pos] <= '9') { n = 10 * n + (input[pos] - '0'); pos++; } if (n == 0) n = 1; if (input[pos] >= 'A'&& input[pos] <= 'Z') { endPos = pos+1; } else { pos++; } for (int i= 0 ; i < n ; i++) { for (int p=pos; p < endPos; ) { if (input[p] == ')') { endPos = p+1; break; } else if (input[p] >= '0' && input[p] <= '9') { p = solve(p); } else if (input[p] >= 'A' && input[p] <= 'Z') { // cout << input[p] << " " << p << endl; cnt++; if (cnt == target) { throw input[p]; } p++; } } } return endPos; } int main() { while (true) { cin >> input >> target; if (input == "0" && target == 0) { break; } // cout << "ip: " << input << endl; // cout << "t: " << target << endl; cnt = -1; try { for (int p=0 ; p < input.length() ;) { p = solve(p); // cout << "p: " << p << endl; } cout << 0 << endl; } catch (char c) { cout << c << endl; } } return 0; }