Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=30000005;
int size[N],ch[N][26],tot=0;
void ins(char *s)
{
	int n=strlen(s),now=0;
	for(int i=0;i<n;i++)
	{
		if(!ch[now][s[i]-'a'])ch[now][s[i]-'a']=++tot;
		now=ch[now][s[i]-'a'];
	}
}
void find(int k)
{
	int now=0;
	while(k>0)
	{
		//cout <<now<<' '<<k<<endl;
		for(int i=0;i<26;i++)
			if(ch[now][i])
			{
				if(size[ch[now][i]]==k)
				{
					cout <<(char)(i+'a');
					//cout <<now<<' '<<k<<endl;
					//cout <<"fuck";
					return;	
				}
				if(size[ch[now][i]]>k)
				{
					cout <<(char)(i+'a');
					k--;
					//cout <<now<<' '<<k<<endl;
					now=ch[now][i];
					break;
				}
				else k-=size[ch[now][i]];//cout <<now<<' '<<k<<endl;
			}
	}
}
char s[N];
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >>(s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++)ins(s+i);
	for(int i=tot;i>=0;i--)
	{
		size[i]=1;
		for(int j=0;j<26;j++)if(ch[i][j])size[i]+=size[ch[i][j]];
	}
	int k;
	cin >>k;
	//cout <<k<<endl;
	find(k);
	cout <<endl;
	return 0;
}

Compiler output:
a.cc: In function 'void find(int)':
a.cc:27:36: error: reference to 'size' is ambiguous
   27 |                                 if(size[ch[now][i]]==k)
      |                                    ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:5: note:                 'int size [30000005]'
    8 | int size[N],ch[N][26],tot=0;
      |     ^~~~
a.cc:34:36: error: reference to 'size' is ambiguous
   34 |                                 if(size[ch[now][i]]>k)
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:5: note:                 'int size [30000005]'
    8 | int size[N],ch[N][26],tot=0;
      |     ^~~~
a.cc:42:41: error: reference to 'size' is ambiguous
   42 |                                 else k-=size[ch[now][i]];//cout <<now<<' '<<k<<endl;
      |                                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:5: note:                 'int size [30000005]'
    8 | int size[N],ch[N][26],tot=0;
      |     ^~~~
a.cc: In function 'int main()':
a.cc:57:17: error: reference to 'size' is ambiguous
   57 |                 size[i]=1;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:5: note:                 'int size [30000005]'
    8 | int size[N],ch[N][26],tot=0;
      |     ^~~~
a.cc:58:50: error: reference to 'size' is ambiguous
   58 |                 for(int j=0;j<26;j++)if(ch[i][j])size[i]+=size[ch[i][j]];
      |                                                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:5: note:                 'int size [30000005]'
    8 | int size[N],ch[N][26],tot=0;
      |     ^~~~
a.cc:58:59: error: reference to 'size' is ambiguous
   58 |                 for(int j=0;j<26;j++)if(ch[i][j])size[i]+=size[ch[i][j]];
      |                                                           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:8:5: note:                 'int size [30000005]'
    8 | int size[N],ch[N][26],tot=0;
      |     ^~~~