Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
typedef string::const_iterator State;
string s;
int ref;
string expr(State& be){
	string ret;
	while(true){
		int x=1;
		if(isdigit(*be)){
			x=0;
			while(isdigit(*be)){
				x*=10;
				x+=(*be)-'0';
				be++;
			}
		}
		if(*be=='('){
			be++;
			string t=expr(be);
			rep(i,x){
				if(ret.size()>ref) break;
				ret+=t;
			}
			be++;
		}else if('A'<=*be && *be<='Z'){
			rep(i,x){
				if(ret.size()>ref) break;
				ret+=(*be);
			}
			be++;
		}else break;
		if(ret.size()>ref) break;
	}
	return ret;
}
int main(){
	while(true){
		cin>>s>>ref;
		if(s[0]=='0') break;
		State be=s.begin();
		string t=expr(be);
		if(t.size()<=ref) cout << "0\n";
		else cout << t[ref]<<endl;
	}
}

Compiler output:
a.cc: In function 'std::string expr(State&)':
a.cc:35:47: error: reference to 'ref' is ambiguous
   35 |                                 if(ret.size()>ref) break;
      |                                               ^~~
In file included from /usr/include/c++/14/string:52,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:5: note:                 'int ref'
   18 | int ref;
      |     ^~~
a.cc:41:47: error: reference to 'ref' is ambiguous
   41 |                                 if(ret.size()>ref) break;
      |                                               ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:5: note:                 'int ref'
   18 | int ref;
      |     ^~~
a.cc:46:31: error: reference to 'ref' is ambiguous
   46 |                 if(ret.size()>ref) break;
      |                               ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:5: note:                 'int ref'
   18 | int ref;
      |     ^~~
a.cc: In function 'int main()':
a.cc:52:25: error: reference to 'ref' is ambiguous
   52 |                 cin>>s>>ref;
      |                         ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:5: note:                 'int ref'
   18 | int ref;
      |     ^~~
a.cc:56:30: error: reference to 'ref' is ambiguous
   56 |                 if(t.size()<=ref) cout << "0\n";
      |                              ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:5: note:                 'int ref'
   18 | int ref;
      |     ^~~
a.cc:57:32: error: reference to 'ref' is ambiguous
   57 |                 else cout << t[ref]<<endl;
      |                                ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:5: note:                 'int ref'
   18 | int ref;
      |     ^~~