Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXS (5000 + 5)
#define MAXN (25000000 + 5)
#define MAXC (26)
#define cint const int 
#define rint register int
#define LL long long
#define pii pair<int, int>
#define pci pair<char, int>
using namespace std;
cint root = 0;
struct node
{
    int sum, next[MAXC], is_end, fa;
    node(): sum(0), is_end(0)
    { memset(next, -1, sizeof(next)); }
    node(int dqs, int dqi): sum(dqs), is_end(dqi)
    {
        memset(next, -1, sizeof(next));
    }
};
vector<node> b;
void ins(char* s, int n)
{
    static int cnt = 0;
    int dq = root;
    for (int i = 0; i < n; i++)
    {
        if (b[dq].next[s[i] - 'a'] == -1)
        {
            b.push_back(node());
            b[dq].next[s[i] - 'a'] = ++cnt;
        }
        b[b[dq].next[s[i] - 'a']].fa = dq;
        dq = b[dq].next[s[i] - 'a'];
    }
    int zh = 1 - b[dq].is_end;
    b[dq].is_end = 1;
    for (; dq != root; dq = b[dq].fa)
        b[dq].sum += zh;
    b[root].sum += zh;
}
void solve(int dq, int k)
{
    if (b[dq].is_end == 1 && k == 1)
        return ;
    int dqs = b[dq].is_end;
    for (int i = 0; i < MAXC; i++)
    {
        if (b[dq].next[i] != -1 && dqs + b[b[dq].next[i]].sum >= k)
        {
            printf("%c", 'a' + i);
            solve(b[dq].next[i], k - dqs);
            return ;
        }
        if (b[dq].next[i] != -1)
            dqs += b[b[dq].next[i]].sum;
    }
}
int main()
{
	freopen("in.in", "r", stdin);#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXS (5000 + 5)
#define MAXN (25000000 + 5)
#define MAXC (26)
#define cint const int 
#define rint register int
#define LL long long
#define pii pair<int, int>
#define pci pair<char, int>
using namespace std;
cint root = 0;
struct node
{
    int sum, next[MAXC], is_end, fa;
    node(): sum(0), is_end(0)
    { memset(next, -1, sizeof(next)); }
    node(int dqs, int dqi): sum(dqs), is_end(dqi)
    {
        memset(next, -1, sizeof(next));
    }
};
vector<node> b;
void ins(char* s, int n)
{
    static int cnt = 0;
    int dq = root;
    for (int i = 0; i < n; i++)
    {
        if (b[dq].next[s[i] - 'a'] == -1)
        {
            b.push_back(node());
            b[dq].next[s[i] - 'a'] = ++cnt;
        }
        b[b[dq].next[s[i] - 'a']].fa = dq;
        dq = b[dq].next[s[i] - 'a'];
    }
    int zh = 1 - b[dq].is_end;
    b[dq].is_end = 1;
    for (; dq != root; dq = b[dq].fa)
        b[dq].sum += zh;
    b[root].sum += zh;
}
void solve(int dq, int k)
{
    if (b[dq].is_end == 1 && k == 1)
        return ;
    int dqs = b[dq].is_end;
    for (int i = 0; i < MAXC; i++)
    {
        if (b[dq].next[i] != -1 && dqs + b[b[dq].next[i]].sum >= k)
        {
            printf("%c", 'a' + i);
            solve(b[dq].next[i], k - dqs);
            return ;
        }
        if (b[dq].next[i] != -1)
            dqs += b[b[dq].next[i]].sum;
    }
}
int main()
{
	char s[MAXS];
	b.push_back(node());
	pci sors[MAXS];
	int k, n;
	scanf("%s%d", s, &k);
	n = strlen(s);
	for (int i = 0; i < n; i++)
		sors[i] = make_pair(s[i], i);
	sort(sors, sors + n);
	for (int i = 0; i < n; i++)
		for (int j = sors[i].second; j < n; j++)
		{
			if (b[root].sum >= k * 10)
			{
				solve(root, k);
				return 0;
			}
			ins(s + sors[i].second, j - sors[i].second + 1);
		}
	solve(root, k);
	return 0;
}
	char s[MAXS];
	b.push_back(node());
	pci sors[MAXS];
	int k, n;
	scanf("%s%d", s, &k);
	n = strlen(s);
	for (int i = 0; i < n; i++)
		sors[i] = make_pair(s[i], i);
	sort(sors, sors + n);
	for (int i = 0; i < n; i++)
		for (int j = sors[i].second; j < n; j++)
		{
			if (b[root].sum >= k * 10000)
			{
				solve(root, k);
				return 0;
			}
			ins(s + sors[i].second, j - sors[i].second + 1);
		}
	solve(root, k);
	return 0;
}

Compiler output:
a.cc:67:38: error: stray '#' in program
   67 |         freopen("in.in", "r", stdin);#include <iostream>
      |                                      ^
a.cc: In function 'int main()':
a.cc:67:39: error: 'include' was not declared in this scope
   67 |         freopen("in.in", "r", stdin);#include <iostream>
      |                                       ^~~~~~~
a.cc:67:56: error: expected primary-expression before '>' token
   67 |         freopen("in.in", "r", stdin);#include <iostream>
      |                                                        ^
a.cc:81:1: error: expected primary-expression before 'using'
   81 | using namespace std;
      | ^~~~~
a.cc:95:1: error: a function-definition is not allowed here before '{' token
   95 | {
      | ^
a.cc:115:1: error: a function-definition is not allowed here before '{' token
  115 | {
      | ^
a.cc:131:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  131 | int main()
      |         ^~
a.cc:131:9: note: remove parentheses to default-initialize a variable
  131 | int main()
      |         ^~
      |         --
a.cc:131:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:132:1: error: a function-definition is not allowed here before '{' token
  132 | {
      | ^