Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main {before_main() {cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

typedef shared_ptr<struct tree> tree_ptr;

struct tree {
  string s;
  vector<tree_ptr> children;
  ll num = 1;
  tree() noexcept = default;
  tree(string s, ll num): s(s), num(num) {}
};

ll read_k(string& s) {
  stringstream ss(s);
  int x; string t; ss >> x >> t;
  s = t;
  return x;
}

string read_s(string& s) {
  int n = s.size();
  string t;
  int last = -1;
  bool br = 0;
  rep(i, n) {
    last = i;
    if (s[i] == ')') { br = 1; break; }
    t.push_back(s[i]);
  }
  if (br) s = s.substr(last);
  else s = "";
  return t;
}

void consume(string& s, char expected) {
  if (s[0] != expected) {
    cout << "Expected: " << expected << endl;
    cout << "Remain: " << s << endl;
    assert(0);
  }
  s = s.substr(1);
}

void dfs(string& s, tree_ptr curr) {
  for (; !s.empty();) {
    if (isdigit(s[0])) {
      ll ck = read_k(s);
      if (isalpha(s[0])) {
        auto c = make_shared<tree>();
        c->num = ck;
        c->s = read_s(s);
        curr->children.push_back(c);
        return;
      }
      else {
        consume(s, '(');
        auto c = make_shared<tree>();
        c->num = ck;
        curr->children.push_back(c);
        dfs(s, c);
        consume(s, ')');
      }
    }
    else {
      curr->s = read_s(s);
      return;
    }
  }
}

int stop;
string ans;

void visit(tree_ptr curr, ll num) {

  if(stop == 2) { return; }
  num *= curr->num;
  if(num >= 1000000) { num = 1000000; stop = 1; }

  if (curr->children.empty()) {
    rep(i, num) ans += curr->s;
    if(stop) { stop ++; }
  }

  rep(i, curr->children.size()) {
    visit(curr->children[i], num);
  }
}

char solve(string& s, int idx) {
  auto root = make_shared<tree>();
  dfs(s, root);
  stop = 0; ans.clear();
  visit(root, 1);
  if(ans.size() <= idx) { return '0'; }
//  cout << ans.size() << " / " << idx << endl;
  return ans[idx];
}

int main() {

  while (1) {
    string s; cin >> s;
    int idx; cin >> idx;
    if (s == "0" && idx == 0) { break; }
    cout << solve(s, idx) << endl;
  }

  return 0;
}

Compiler output:
a.cc:31:9: error: 'shared_ptr' does not name a type
   31 | typedef shared_ptr<struct tree> tree_ptr;
      |         ^~~~~~~~~~
a.cc:35:10: error: 'tree_ptr' was not declared in this scope
   35 |   vector<tree_ptr> children;
      |          ^~~~~~~~
a.cc:35:18: error: template argument 1 is invalid
   35 |   vector<tree_ptr> children;
      |                  ^
a.cc:35:18: error: template argument 2 is invalid
a.cc:72:21: error: 'tree_ptr' has not been declared
   72 | void dfs(string& s, tree_ptr curr) {
      |                     ^~~~~~~~
a.cc: In function 'void dfs(std::string&, int)':
a.cc:77:18: error: 'make_shared' was not declared in this scope
   77 |         auto c = make_shared<tree>();
      |                  ^~~~~~~~~~~
a.cc:21:1: note: 'std::make_shared' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
   20 | #include <bitset>
  +++ |+#include <memory>
   21 | 
a.cc:77:34: error: expected primary-expression before '>' token
   77 |         auto c = make_shared<tree>();
      |                                  ^
a.cc:77:36: error: expected primary-expression before ')' token
   77 |         auto c = make_shared<tree>();
      |                                    ^
a.cc:80:13: error: base operand of '->' is not a pointer
   80 |         curr->children.push_back(c);
      |             ^~
a.cc:85:18: error: 'make_shared' was not declared in this scope
   85 |         auto c = make_shared<tree>();
      |                  ^~~~~~~~~~~
a.cc:85:18: note: 'std::make_shared' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
a.cc:85:34: error: expected primary-expression before '>' token
   85 |         auto c = make_shared<tree>();
      |                                  ^
a.cc:85:36: error: expected primary-expression before ')' token
   85 |         auto c = make_shared<tree>();
      |                                    ^
a.cc:87:13: error: base operand of '->' is not a pointer
   87 |         curr->children.push_back(c);
      |             ^~
a.cc:93:11: error: base operand of '->' is not a pointer
   93 |       curr->s = read_s(s);
      |           ^~
a.cc: At global scope:
a.cc:102:6: error: variable or field 'visit' declared void
  102 | void visit(tree_ptr curr, ll num) {
      |      ^~~~~
a.cc:102:12: error: 'tree_ptr' was not declared in this scope
  102 | void visit(tree_ptr curr, ll num) {
      |            ^~~~~~~~
a.cc:102:30: error: expected primary-expression before 'num'
  102 | void visit(tree_ptr curr, ll num) {
      |                              ^~~
a.cc: In function 'char solve(std::string&, int)':
a.cc:119:15: error: 'make_shared' was not declared in this scope
  119 |   auto root = make_shared<tree>();
      |               ^~~~~~~~~~~
a.cc:119:15: note: 'std::make_shared' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
a.cc:119:31: error: expected primary-expression before '>' token
  119 |   auto root = make_shared<tree>();
      |                               ^
a.cc:119:33: error: expected primary-expression before ')' token
  119 |   auto root = make_shared<tree>();
      |                                 ^
a.cc:122:3: error: 'visit' was not declared in this scope
  122 |   visit(root, 1);
      |   ^~~~~
a.cc:21:1: note: 'std::visit' is defined in header '<variant>'; this is probably fixable by adding '#include <variant>'
   20 | #include <bitset>
  +++ |+#include <variant>
   21 |