prithivMLmods/Coder-Stat huggingface dataset:
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool mini(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define y0 y3487465 // j0
#define y1 y1347829 // j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main() {

  string S;
  cin >> S;
  int K;
  cin >> K;

  int N = S.length();

  set<string> st;

  rep(i, N) {
    reps(j, i, max(N, i + 5)) { st.insert(S.substr(i, j - i + 1)); }
  }

  cout << *next(st.begin(), K - 1) << "\n";
}

//-----------------------------------
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Fixed submission:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool mini(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define y0 y3487465 // j0
#define y1 y1347829 // j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main() {

  string S;
  cin >> S;
  int K;
  cin >> K;

  int N = S.length();

  set<string> st;

  rep(i, N) {
    reps(j, i, min(N, i + 5)) { st.insert(S.substr(i, j - i + 1)); }
  }

  cout << *next(st.begin(), K - 1) << "\n";
}

//-----------------------------------
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
using namespace std;

int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;

  set<string> str;
  int size = s.size();
  for (int i = 0; i < size; i++) {
    for (int j = 1; i + j <= size; j++) {
      str.insert(s.substr(i, j));
    }
  }

  auto itr = str.begin();
  for (int i = 1; i <= k; i++) {
    if (i == k)
      cout << *itr << endl;
    itr++;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <set>
using namespace std;

int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;

  set<string> str;
  int size = s.size();
  for (int i = 0; i < size; i++) {
    for (int j = 1; j <= k; j++) {
      str.insert(s.substr(i, j));
    }
  }

  auto itr = str.begin();
  for (int i = 1; i <= k; i++) {
    if (i == k)
      cout << *itr << endl;
    itr++;
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int K;
  scanf("%d", &K);

  vector<string> ans;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i; j++) {
      ans.push_back(s.substr(i, j));
    }
  }

  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());

  printf("%s", ans.at(K - 1).c_str());
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int K;
  scanf("%d", &K);

  vector<string> ans;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i; j++) {
      if (s.substr(i, j).length() <= K)
        ans.push_back(s.substr(i, j));
    }
  }

  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());

  printf("%s", ans.at(K - 1).c_str());
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.length();
  vector<string> ans;
  string tmp;
  for (int i = 0; i < N; i++) {
    tmp = S[i];
    ans.push_back(tmp);
    for (int j = i + 1; j < N; j++) {
      if (j - i >= K)
        break;
      tmp += S[j];
      ans.push_back(tmp);
    }
  }
  sort(ans.begin(), ans.end());
  int now = 0, cnt = 0;
  if (K == 1) {
    cout << ans[0] << endl;
    return 0;
  }
  while (cnt < K) {
    if (ans[now] != ans[now + 1]) {
      cnt++;
      if (cnt == K)
        break;
    }
    now++;
  }
  cout << ans[now] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.length();
  vector<string> ans;
  string tmp;
  for (int i = 0; i < N; i++) {
    tmp = S[i];
    ans.push_back(tmp);
    for (int j = i + 1; j < N; j++) {
      if (j - i >= K)
        break;
      tmp += S[j];
      ans.push_back(tmp);
    }
  }
  sort(ans.begin(), ans.end());
  int now = 0, cnt = 0;
  if (K == 1) {
    cout << ans[0] << endl;
    return 0;
  }
  while (cnt < K) {
    if (now + 1 >= ans.size())
      break;
    if (ans[now] != ans[now + 1]) {
      cnt++;
      if (cnt == K)
        break;
    }
    now++;
  }
  cout << ans[now] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
//
//  main.cpp
//  Exercise
//
//

#include "string.h"
#include <algorithm>
#include <array>
#include <iostream>
#include <limits>
#include <math.h>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using int_t = long long;

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  unordered_set<string> substrSet;
  substrSet.reserve(s.length() * s.length());
  vector<string> substrs;
  substrs.reserve(s.length() * s.length());
  for (int i = 0; i < s.length(); i++) {
    for (int len = 1; len <= s.length(); len++) {
      string sub = s.substr(i, len);
      if (substrSet.find(sub) == substrSet.end()) {
        substrs.push_back(sub);
      }
      substrSet.insert(sub);
    }
  }
  sort(substrs.begin(), substrs.end());
  printf("%s", substrs[K - 1].c_str());
  printf("\n");
  return 0;
}


Fixed submission:
//
//  main.cpp
//  Exercise
//
//

#include "string.h"
#include <algorithm>
#include <array>
#include <iostream>
#include <limits>
#include <math.h>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using int_t = long long;

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  unordered_set<string> substrSet;
  substrSet.reserve(s.length() * s.length());
  vector<string> substrs;
  substrs.reserve(s.length() * s.length());
  for (int i = 0; i < s.length(); i++) {
    for (int len = 1; len <= min(K, (int)s.length()); len++) {
      string sub = s.substr(i, len);
      if (substrSet.find(sub) == substrSet.end()) {
        substrs.push_back(sub);
      }
      substrSet.insert(sub);
    }
  }
  sort(substrs.begin(), substrs.end());
  printf("%s", substrs[K - 1].c_str());
  printf("\n");
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x "=" << (x) << endl
#define dbgv(x)                                                                \
  cout << #x << endl;                                                          \
  reps(y, x) { cout << y << " "; }                                             \
  cout << endl

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  set<string> st;
  rep(i, s.size()) {
    FOR(j, 1, s.size() - i + 1) { st.insert(s.substr(i, j)); }
  }
  ll cnt = 0;
  reps(x, st) {
    cnt++;
    if (cnt == k) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x "=" << (x) << endl
#define dbgv(x)                                                                \
  cout << #x << endl;                                                          \
  reps(y, x) { cout << y << " "; }                                             \
  cout << endl

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  set<string> st;
  rep(i, s.size()) {
    FOR(j, 1, min(ll(s.size() - i + 1), 6ll)) { st.insert(s.substr(i, j)); }
  }
  ll cnt = 0;
  reps(x, st) {
    cnt++;
    if (cnt == k) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 *    created: 30.06.2020 16:31:50
 **/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  rep(i, s.size()) rep(j, i + 1) {
    if (j - i + 1 > 5)
      continue;
    st.insert(s.substr(j, i - j + 1));
  }
  auto itr = st.begin();
  advance(itr, k - 1);
  cout << *itr << endl;
  return 0;
}


Fixed submission:
/**
 *    created: 30.06.2020 16:31:50
 **/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  rep(i, s.size()) rep(j, i + 1) {
    if (i - j + 1 > 5)
      continue;
    st.insert(s.substr(j, i - j + 1));
  }
  auto itr = st.begin();
  advance(itr, k - 1);
  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt) {
  string s;
  for (int i = 0; i < tgt.size(); i++) {
    s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
  }
  out << s;
  return out;
}

int main() {
  int k;
  string s;
  string ans = "";
  vector<string> ss;
  cin >> s;
  cin >> k;
  rep(i, s.size()) {
    range(j, i, s.size()) { ss.push_back(s.substr(i, j - i + 1)); }
  }
  sort(all(ss));
  int t = 0;
  rep(i, k) {
    while (1) {
      if (ans != ss[t]) {
        ans = ss[t];
        t++;
        break;
      }
      t++;
    }
  }
  cout << ans << endl;
  ;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt) {
  string s;
  for (int i = 0; i < tgt.size(); i++) {
    s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
  }
  out << s;
  return out;
}

int main() {
  int k;
  string s;
  string ans = "";
  vector<string> ss;
  cin >> s;
  cin >> k;
  rep(i, s.size()) {
    range(j, i, s.size()) {
      if (j - i + 1 > k)
        continue;
      ss.push_back(s.substr(i, j - i + 1));
    }
  }
  sort(all(ss));
  int t = 0;
  rep(i, k) {
    while (1) {
      if (ans != ss[t]) {
        ans = ss[t];
        t++;
        break;
      }
      t++;
    }
  }
  cout << ans << endl;
  ;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

set<string> st;

int main() {
  ios_base::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    string curr;
    for (int j = i; j < n; j++) {
      curr += s[j];
      st.insert(curr);
    }
  }
  int ct = 0;
  for (auto i : st) {
    ct += 1;
    if (ct == k) {
      cout << i;
      break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

set<string> st;

int main() {
  ios_base::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    string curr;
    for (int j = i; j < min(i + 5, n); j++) {
      curr += s[j];
      st.insert(curr);
    }
  }
  int ct = 0;
  for (auto i : st) {
    ct += 1;
    if (ct == k) {
      cout << i;
      break;
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;

const long long INF = 1LL << 60;

int main() {
  string s;
  int K;
  cin >> s >> K;

  vector<string> sub;
  map<string, int> match;

  rep(i, s.size()) {
    string substring = "";
    substring += s[i];
    if (match.count(substring) == 0) {
      match[substring] = 1;
      sub.push_back(substring);
    }
    repd(j, i + 1, s.size()) {
      substring += s[j];
      if (match.count(substring) == 0) {
        match[substring] = 1;
        sub.push_back(substring);
      }
    }
  }

  sort(sub.begin(), sub.end());

  cout << sub[K - 1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;

const long long INF = 1LL << 60;

int main() {
  string s;
  int K;
  cin >> s >> K;

  vector<string> sub;
  map<string, int> match;

  rep(i, s.size()) {
    string substring = "";
    substring += s[i];
    if (match.count(substring) == 0) {
      match[substring] = 1;
      sub.push_back(substring);
    }
    repd(j, i + 1, min(i + 6, (int)s.size())) {
      substring += s[j];
      if (match.count(substring) == 0) {
        match[substring] = 1;
        sub.push_back(substring);
      }
    }
  }

  sort(sub.begin(), sub.end());

  cout << sub[K - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  set<string> pos;
  rep(i, n) repn(j, 1, n - i + 1) {
    string cur = s.substr(i, j);
    pos.insert(cur);
  }
  int cnt = 0;
  for (string x : pos) {
    cnt++;
    if (cnt == k) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}
/*
Things to look out for:
        - Integer overflows
        - Array bounds
        - Special cases
Be careful!
*/


Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  set<string> pos;
  rep(i, n) repn(j, 1, min(100, n - i + 1)) {
    string cur = s.substr(i, j);
    pos.insert(cur);
  }
  int cnt = 0;
  for (string x : pos) {
    cnt++;
    if (cnt == k) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}
/*
Things to look out for:
        - Integer overflows
        - Array bounds
        - Special cases
Be careful!
*/
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template <typename T> vector<T> uni(vector<T> v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> cand;
  for (int i = 0; i < n; i++)
    for (int j = 1; i + j <= n; j++) {
      cand.emplace_back(s.substr(i, j));
    }
  cout << uni(cand)[k - 1] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template <typename T> vector<T> uni(vector<T> v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> cand;
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= k && i + j <= n; j++) {
      cand.emplace_back(s.substr(i, j));
    }
  cout << uni(cand)[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <assert.h>
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int size = s.size();
  vector<string> p;
  set<string> se;
  for (int i = 0; i < size; i++)
    for (int j = 1; j < size - i + 1; j++)
      if (se.count(s.substr(i, j)) == 0) {
        p.push_back(s.substr(i, j));
        se.insert(s.substr(i, j));
      }
  sort(p.begin(), p.end());
  cout << p[k - 1] << endl;

  return 0;
}


Fixed submission:
#include <assert.h>
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int size = s.size();
  vector<string> p;
  set<string> se;
  for (int i = 0; i < size; i++)
    for (int j = 1; j < size - i + 1 && j < 6; j++)
      if (se.count(s.substr(i, j)) == 0) {
        p.push_back(s.substr(i, j));
        se.insert(s.substr(i, j));
      }
  sort(p.begin(), p.end());
  cout << p[k - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  string s;
  cin >> s >> k;
  priority_queue<string, vector<string>, greater<string>> v;
  unordered_set<string> st;
  int ss = s.size();
  for (int i = 0; i < ss; ++i) {
    for (int j = 1; i + j <= ss; ++j) {
      string ss = s.substr(i, j);
      if (st.find(ss) == st.end()) {
        st.insert(ss);
        v.push(ss);
      }
    }
  }

  rep(i, k - 1) v.pop();
  cout << v.top() << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  string s;
  cin >> s >> k;
  priority_queue<string, vector<string>, greater<string>> v;
  unordered_set<string> st;
  int ss = s.size();
  for (int i = 0; i < ss; ++i) {
    for (int j = 1; i + j <= ss; ++j) {
      if (j > k)
        continue;
      string ss = s.substr(i, j);
      if (st.find(ss) == st.end()) {
        st.insert(ss);
        v.push(ss);
      }
    }
  }

  rep(i, k - 1) v.pop();
  cout << v.top() << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main() {
  string s;
  int k;
  vector<string> ans;

  cin >> s;
  cin >> k;
  REP(i, s.length()) {
    if (ans.size() >= k) {
      if (s[i] > ans[ans.size() - 1][0]) {
        continue;
      }
    }
    FOR(j, i, s.length()) {
      bool flag = false;
      string sub = s.substr(i, j - i + 1);
      REP(l, ans.size()) {
        if (ans[l] == sub)
          flag = true;
      }
      if (flag)
        continue;
      if (ans.size() < k) {
        ans.push_back(sub);
        sort(ans.begin(), ans.end());
      } else {
        REP(l, ans.size()) {
          if (sub < ans[l]) {
            ans.insert(ans.begin() + l, sub);
            if (ans.size() >= k)
              ans.pop_back();
            break;
          }
        }
      }
    }
  }
  cout << ans[k - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main() {
  string s;
  int k;
  vector<string> ans;

  cin >> s;
  cin >> k;
  REP(i, s.length()) {
    if (ans.size() >= k) {
      if (s[i] > ans[ans.size() - 1][0]) {
        continue;
      }
    }
    FOR(j, i, s.length()) {
      bool flag = false;
      string sub = s.substr(i, j - i + 1);
      if (!ans.empty() && ans.size() >= k && sub > ans[ans.size() - 1])
        continue;
      REP(l, ans.size()) {
        if (ans[l] == sub)
          flag = true;
      }
      if (flag)
        continue;
      if (ans.size() < k) {
        ans.push_back(sub);
        sort(ans.begin(), ans.end());
      } else {
        REP(l, ans.size()) {
          if (sub < ans[l]) {
            ans.insert(ans.begin() + l, sub);
            if (ans.size() >= k)
              ans.pop_back();
            break;
          }
        }
      }
    }
  }
  cout << ans[k - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  set<string> st;
  for (int size = 1; size <= s.size(); size++) {
    for (int i = 0; i < s.size() - size + 1; i++) {
      st.insert(s.substr(i, size));
    }
  }

  // for (auto elem : st) cout << elem << " "; cout << endl;

  vector<string> ks(st.begin(), st.end());
  // for (auto elem : ks) cout << elem << " "; cout << endl;

  cout << ks[k - 1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  set<string> st;
  for (int size = 1; size <= k; size++) {
    for (int i = 0; i < s.size() - size + 1; i++) {
      st.insert(s.substr(i, size));
    }
  }

  // for (auto elem : st) cout << elem << " "; cout << endl;

  vector<string> ks(st.begin(), st.end());
  // for (auto elem : ks) cout << elem << " "; cout << endl;

  cout << ks[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  vector<string> vec;
  rep(i, s.size()) for (int j = 0; i + j < s.size(); j++) {
    string t = s;
    rep(k, i) t.erase(t.begin());
    rep(k, j) t.erase(t.end() - 1);
    vec.push_back(t);
  }
  sort(vec.begin(), vec.end());
  int cnt = 1;
  rep(i, vec.size() - 1) {
    if (vec.at(i) != vec.at(i + 1))
      cnt++;
    if (cnt == k) {
      cout << vec.at(i + 1) << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  vector<string> vec;
  rep(i, s.size()) for (int j = 1; j <= 5 && i + j <= s.size(); j++) {
    string t;
    t = s.substr(i, j);
    vec.push_back(t);
  }
  sort(vec.begin(), vec.end());
  int cnt = 1;
  rep(i, vec.size() - 1) {
    if (vec.at(i) != vec.at(i + 1))
      cnt++;
    if (cnt == k) {
      cout << vec.at(i + 1) << endl;
      return 0;
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> se;
  rep(i, s.size()) {
    for (int j = 1; j <= s.size(); j++) {
      string t = s.substr(i, j);
      se.insert(t);
    }
  }
  auto itr = se.begin();
  k--;
  while (k--)
    itr++;
  cout << *itr << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> se;
  rep(i, s.size()) {
    for (int j = 1; j <= min((int)s.size(), k); j++) {
      string t = s.substr(i, j);
      se.insert(t);
    }
  }
  auto itr = se.begin();
  k--;
  while (k--)
    itr++;
  cout << *itr << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  std::string S;
  std::cin >> S;

  int K;
  std::cin >> K;

  std::vector<std::string> memo;
  for (int i = 0; i < S.length(); i++) {
    for (int d = 1; d <= S.length() - i; d++) {
      memo.emplace_back(S.substr(i, d));
    }
  }

  std::sort(memo.begin(), memo.end());
  memo.erase(std::unique(memo.begin(), memo.end()), memo.end());

  std::cout << memo[K - 1] << '\n';
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  std::string S;
  std::cin >> S;

  int K;
  std::cin >> K;

  std::vector<std::string> memo;
  for (int i = 0; i < S.length(); i++) {
    for (int d = 1; d <= std::min(K, (int)S.length() - i); d++) {
      memo.emplace_back(S.substr(i, d));
    }
  }

  std::sort(memo.begin(), memo.end());
  memo.erase(std::unique(memo.begin(), memo.end()), memo.end());

  std::cout << memo[K - 1] << '\n';
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  int K;
  vector<string> substrings;

  cin >> s >> K;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= s.size(); ++j) {
      substrings.push_back(s.substr(i, j));
    }
  }
  sort(substrings.begin(), substrings.end());
  substrings.erase(unique(substrings.begin(), substrings.end()),
                   substrings.end());
  //    for(auto hoge : substrings) cout << hoge << endl;
  cout << substrings[K - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  int K;
  vector<string> substrings;

  cin >> s >> K;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= 5; ++j) {
      substrings.push_back(s.substr(i, j));
    }
  }
  sort(substrings.begin(), substrings.end());
  substrings.erase(unique(substrings.begin(), substrings.end()),
                   substrings.end());
  //    for(auto hoge : substrings) cout << hoge << endl;
  cout << substrings[K - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>

using namespace std;

int main() {
  string S;
  int K;
  cin >> S >> K;

  priority_queue<string, vector<string>, greater<string>> q;
  unordered_map<string, bool> m;
  for (int i = 0; i < S.size(); i++) {
    for (int l = 1; l <= K && i + K <= S.size(); l++) {
      string s(S, i, l);
      if (m.find(s) == m.end()) {
        m.emplace(s, true);
        q.push(s);
      }
    }
  }

  for (int i = 0; i < K - 1; i++)
    q.pop();
  cout << q.top() << endl;
}


Fixed submission:
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>

using namespace std;

int main() {
  string S;
  int K;
  cin >> S >> K;

  priority_queue<string, vector<string>, greater<string>> q;
  unordered_map<string, bool> m;
  for (int i = 0; i < S.size(); i++) {
    for (int l = 1; l <= K && i + l <= S.size(); l++) {
      string s(S, i, l);
      if (m.find(s) == m.end()) {
        m.emplace(s, true);
        q.push(s);
      }
    }
  }

  for (int i = 0; i < K - 1; i++)
    q.pop();
  cout << q.top() << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long int

int main() {
  string s;
  int k;
  cin >> s >> k;

  int m = s.size();
  set<string> sub;
  for (int i = 0; i < m; i++) {
    for (int j = i; j < m; j++) {
      sub.insert(s.substr(i, j - i + 1));
    }
  }
  auto itr = sub.begin();
  for (int i = 0; i < k - 1; i++) {
    ++itr;
  }
  cout << *itr << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long int

int main() {
  string s;
  int k;
  cin >> s >> k;

  int m = s.size();
  set<string> sub;
  for (int i = 0; i < m; i++) {
    for (int j = i; j < m && j < i + 5; j++) {
      sub.insert(s.substr(i, j - i + 1));
    }
  }
  auto itr = sub.begin();
  for (int i = 0; i < k - 1; i++) {
    ++itr;
  }
  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
using namespace std;
int main(void) {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  for (int i = 0; i < s.size(); ++i) {
    string subs;
    for (int j = i; j < s.size(); ++j) {
      subs += s[j];
      st.insert(subs);
    }
  }
  int cnt = 0;
  for (auto x : st) {
    ++cnt;
    if (cnt == k) {
      cout << x << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <set>
using namespace std;
int main(void) {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  for (int i = 0; i < s.size(); ++i) {
    string subs;
    for (int j = i; j < s.size(); ++j) {
      subs += s[j];
      if (subs.size() > k)
        break;
      st.insert(subs);
    }
  }
  int cnt = 0;
  for (auto x : st) {
    ++cnt;
    if (cnt == k) {
      cout << x << endl;
      break;
    }
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  string ss = s;
  vector<string> z;
  vector<string> ans;
  sort(ss.begin(), ss.end());
  ss.erase(unique(ss.begin(), ss.end()), ss.end());
  for (int i = 0; ss.size() > i; i++) {
    for (int j = 0; s.size() > j; j++) {
      if (s[j] == ss[i]) {
        z.push_back(s.substr(j));
      }
    }
    for (int i = 0; z.size() > i; i++) {
      for (int j = 0; z[i].size() > j; j++) {
        ans.push_back(z[i].substr(0, j + 1));
      }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    if (ans.size() >= k) {
      cout << ans[k - 1] << endl;
      return 0;
    }
    z.clear();
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  string ss = s;
  vector<string> z;
  vector<string> ans;
  sort(ss.begin(), ss.end());
  ss.erase(unique(ss.begin(), ss.end()), ss.end());
  for (int i = 0; ss.size() > i; i++) {
    for (int j = 0; s.size() > j; j++) {
      if (s[j] == ss[i]) {
        z.push_back(s.substr(j));
      }
    }
    for (int i = 0; z.size() > i; i++) {
      for (int j = 0; min(k + 1, (int)z[i].size()) > j; j++) {
        ans.push_back(z[i].substr(0, j + 1));
      }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    if (ans.size() >= k) {
      cout << ans[k - 1] << endl;
      return 0;
    }
    z.clear();
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  string s;
  int K;
  cin >> s >> K;

  map<string, int> m;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; i + j <= s.size(); ++j) {
      string temp = s.substr(i, j);
      m[temp] = 1;
    }
  }

  int count = 1;
  for (auto const &entry : m) {
    if (count == K) {
      cout << entry.first << endl;
      break;
    }
    count++;
  }

  return 0;
}

Fixed submission:
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  string s;
  int K;
  cin >> s >> K;

  map<string, int> m;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= 5; ++j) {
      string temp = s.substr(i, j);
      m[temp] = 1;
    }
  }

  int count = 1;
  for (auto const &entry : m) {
    if (count == K) {
      cout << entry.first << endl;
      break;
    }
    count++;
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX     // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init()                                                                 \
  std::ios::sync_with_stdio(false);                                            \
  std::cin.tie(0);                                                             \
  std::cout << fixed << setprecision(15);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  Init();
  string s;
  ll k;
  cin >> s >> k;
  set<string> st;
  for (ll i = 0; i < s.size(); i++) {
    for (ll j = i + 1; j <= s.size(); j++) {
      st.insert(s.substr(i, j - i));
    }
  }
  auto it = st.begin();
  rep(i, k - 1) it++;
  cout << *it << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX     // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init()                                                                 \
  std::ios::sync_with_stdio(false);                                            \
  std::cin.tie(0);                                                             \
  std::cout << fixed << setprecision(15);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  Init();
  string s;
  ll k;
  cin >> s >> k;
  set<string> st;
  for (ll i = 0; i < s.size(); i++) {
    for (ll j = 1; j <= k; j++)
      st.insert(s.substr(i, j));
  }
  auto it = st.begin();
  rep(i, k - 1) it++;
  cout << *it << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <vector>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for (auto i = f; i < t; i++)

using namespace std;
using ll = long long;

string s;
int k;

int dfs(vector<string> &subs, string str, vector<int> indexes) {
  if (!str.empty())
    subs.push_back(str);
  if (subs.size() == k)
    return true;
  vector<char> minCs;
  while (true) {
    vector<int> nIndexes;
    char minC = INFINITY;
    for (auto i : indexes) {
      cerr << i << ' ';
      if (i + 1 < s.size() && (minC == char(INFINITY) || s[i + 1] < minC)) {
        bool able = true;
        if (!minCs.empty()) {
          if (find(minCs.begin(), minCs.end(), s[i + 1]) != minCs.end())
            able = false;
        }
        if (able)
          minC = s[i + 1];
      }
    }
    for (auto i : indexes) {
      if (s[i + 1] == minC) {
        nIndexes.push_back(i + 1);
      }
    }
    cerr << minC << endl;
    if (minC == char(INFINITY))
      return false;
    if (dfs(subs, str + minC, nIndexes))
      return true;
    minCs.push_back(minC);
  }
}

int main() {
  cin >> s;
  cin >> k;
  vector<int> indexes;
  for (auto i = 0; i < s.size(); i++) {
    indexes.push_back(i);
  }

  vector<string> subs;
  dfs(subs, "", indexes);
  for (auto s : subs)
    cerr << s << endl;
  cout << subs.back() << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <vector>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for (auto i = f; i < t; i++)

using namespace std;
using ll = long long;

string s;
int k;

int dfs(vector<string> &subs, string str, vector<int> indexes) {
  if (!str.empty())
    subs.push_back(str);
  if (subs.size() == k)
    return true;
  vector<char> minCs;
  while (true) {
    vector<int> nIndexes;
    char minC = INFINITY;
    for (auto i : indexes) {
      cerr << i << ' ';
      if (i + 1 < s.size() && (minC == char(INFINITY) || s[i + 1] < minC)) {
        bool able = true;
        if (!minCs.empty()) {
          if (find(minCs.begin(), minCs.end(), s[i + 1]) != minCs.end())
            able = false;
        }
        if (able)
          minC = s[i + 1];
      }
    }
    for (auto i : indexes) {
      if (s[i + 1] == minC) {
        nIndexes.push_back(i + 1);
      }
    }
    cerr << minC << endl;
    if (minC == char(INFINITY))
      return false;
    if (dfs(subs, str + minC, nIndexes))
      return true;
    minCs.push_back(minC);
  }
}

int main() {
  cin >> s;
  cin >> k;
  vector<int> indexes;
  for (int i = 0; i < s.size(); i++) {
    indexes.push_back(i - 1);
  }

  vector<string> subs;
  dfs(subs, "", indexes);
  for (auto s : subs)
    cerr << s << endl;
  cout << subs.back() << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

string s;
int k;

set<string> str_set;
string ans;

int main(void) {
  cin >> s;
  scanf("%d", &k);

  for (int i = 0; i < s.size(); ++i) {
    string cur("");
    for (int j = i; j < s.size(); ++j) {
      cur.push_back(s[j]);
      str_set.insert(cur);
    }
  }

  int i = 0;
  for (auto str : str_set) {
    if (i == k - 1) {
      ans = str;
      break;
    }
    i += 1;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

string s;
int k;

set<string> str_set;
string ans;

int main(void) {
  cin >> s;
  scanf("%d", &k);

  for (int i = 0; i < s.size(); ++i) {
    string cur("");
    int size = s.size();
    int bound = min(i + k, size);
    for (int j = i; j < bound; ++j) {
      cur.push_back(s[j]);
      str_set.insert(cur);
    }
  }

  int i = 0;
  for (auto str : str_set) {
    if (i == k - 1) {
      ans = str;
      break;
    }
    i += 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int s;
  string k;
  cin >> k >> s;

  vector<string> ss;

  for (int i = 0; i < k.size(); i++) {
    string temp;
    for (int j = i; j < k.size(); j++) {
      temp.push_back(k[j]);

      ss.push_back(temp);
    }
  }

  auto func = [&](string a, string b) { return a < b; };

  sort(ss.begin(), ss.end(), func);
  ss.erase(unique(ss.begin(), ss.end()), ss.end());

  cout << ss[s - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
// #include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int s;
  string k;
  cin >> k >> s;

  vector<string> ss;

  for (int i = 0; i < k.size(); i++) {
    string temp;
    for (int j = i; j < k.size(); j++) {
      temp.push_back(k[j]);

      if (temp.size() <= s)
        ss.push_back(temp);
    }
  }

  auto func = [&](string a, string b) { return a < b; };

  sort(ss.begin(), ss.end(), func);
  ss.erase(unique(ss.begin(), ss.end()), ss.end());

  cout << ss[s - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string s;
int k;
vector<string> vec;

// DFS
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      vec.push_back(s.substr(i, j));
    }
  }
  sort(vec.begin(), vec.end());
  decltype(vec)::iterator result = unique(vec.begin(), vec.end());
  vec.erase(result, vec.end());
  // for (int t = 0; t < vec.size(); t++) cout << vec[t] << endl;
  cout << vec[k - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string s;
int k;
vector<string> vec;

// DFS
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k; j++) {
      vec.push_back(s.substr(i, j));
    }
  }
  sort(vec.begin(), vec.end());
  decltype(vec)::iterator result = unique(vec.begin(), vec.end());
  vec.erase(result, vec.end());
  // for (int t = 0; t < vec.size(); t++) cout << vec[t] << endl;
  cout << vec[k - 1] << endl;
  return 0;
}