Language: C++

#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

struct Node {
  Node* child[26];
};

const int N = 5000 + 10;
Node pool[N * N], *last;
char s[N];

Node* new_node() {
  Node* ret = last++;
  fill(ret->child, ret->child + 26, nullptr);
  return ret;
}

void insert(Node* root, char *s) {
  int n = strlen(s);
  Node* p = root;
  for (int i = 0; i < n; ++i) {
    int k = s[i] - 'a';
    if (!p->child[k]) p->child[k] = new_node();
    p = p->child[k];
  }
}

char ret[N];
int rem;
bool DFS(Node* p, int dep) {
  // trace(dep, rem);
  if (rem == 0) {
    ret[dep] = 0;
    puts(ret);
    return true;
  }
  --rem;
  for (int k = 0; k < 26; ++k) {
    if (p->child[k]) {
      ret[dep] = 'a' + k;
      if (DFS(p->child[k], dep + 1)) return true;
    }
  }
  return false;
}

int main() {
  scanf("%s", s);
  last = pool;
  Node* root = new_node();
  for (int i = 0; s[i]; ++i) {
    insert(root, s + i);
  }
  scanf("%d", &rem);
  DFS(root, 0);
  return 0;
}


Compiler output:
/tmp/ccPOS37l.o: in function `new_node()':
a.cc:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x19): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccPOS37l.o
/tmp/ccPOS37l.o: in function `DFS(Node*, int)':
a.cc:(.text+0xef): relocation truncated to fit: R_X86_64_PC32 against symbol `rem' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0xff): relocation truncated to fit: R_X86_64_PC32 against symbol `ret' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x10a): relocation truncated to fit: R_X86_64_PC32 against symbol `ret' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x11f): relocation truncated to fit: R_X86_64_PC32 against symbol `rem' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x128): relocation truncated to fit: R_X86_64_PC32 against symbol `rem' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x158): relocation truncated to fit: R_X86_64_PC32 against symbol `ret' defined in .bss section in /tmp/ccPOS37l.o
/tmp/ccPOS37l.o: in function `main':
a.cc:(.text+0x1a4): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x1c9): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccPOS37l.o
a.cc:(.text+0x1e7): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status