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

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i, a, b) for (Int i = a; i < b; ++i)
#define rrep(i, a, b) for (Int i = a; i >= b; --i)
using namespace std;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  Int K;
  cin >> K;

  set<string> substr;
  rep(len, 1, s.size() + 1) {
    rep(L, 0, s.size() + 1 - len) { substr.insert(s.substr(L, len)); }
  }

  auto itr = substr.begin();
  rep(i, 0, K - 1)++ itr;
  cout << *itr << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i, a, b) for (Int i = a; i < b; ++i)
#define rrep(i, a, b) for (Int i = a; i >= b; --i)
using namespace std;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  Int K;
  cin >> K;

  set<string> substr;
  rep(len, 1, K + 1) {
    rep(L, 0, s.size() + 1 - len) { substr.insert(s.substr(L, len)); }
  }

  auto itr = substr.begin();
  rep(i, 0, K - 1)++ itr;
  cout << *itr << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>

#define N 100010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define PI 3.1415926535897932384626433832795

using namespace std;

int k;
string s;
set<string> S;

int main() {
  cin >> s >> k, k--;

  for (int i = 0; i < s.length(); i++) {
    string t;

    for (int h = i; h < s.length(); h++)
      t += s[h], S.insert(t);
  }

  while (k--)
    S.erase(*S.begin());

  cout << *S.begin();
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>

#define N 100010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define PI 3.1415926535897932384626433832795

using namespace std;

int k;
string s;
set<string> S;

int main() {
  cin >> s >> k, k--;

  for (int i = 0; i < s.length(); i++) {
    string t;

    for (int h = i; h < i + 100 && h < s.length(); h++)
      t += s[h], S.insert(t);
  }

  while (k--)
    S.erase(*S.begin());

  cout << *S.begin();
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main(void) {
  string s;
  int K;
  cin >> s >> K;
  size_t N = s.size();
  set<string> st;
  for (int i = 0; i < N; i++) {
    for (int j = 1; i + j <= N; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto itr = st.begin();
  cout << *next(itr, K - 1) << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main(void) {
  string s;
  int K;
  cin >> s >> K;
  size_t N = s.size();
  set<string> st;
  for (int i = 0; i < N; i++) {
    for (int j = 1; i + j <= N && j <= 5; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto itr = st.begin();
  cout << *next(itr, K - 1) << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
vector<int> posi[30];
set<string> ans;
int main() {
  string s;
  int k;
  cin >> s >> k;
  for (int i = 0; s[i]; ++i) {
    posi[s[i] - 'a'].emplace_back(i);
  }
  for (int i = 0; i < 26; ++i) {
    for (auto j : posi[i]) {
      string tmp = "";
      for (int k = j; s[k]; ++k) {
        tmp += s[k];
        ans.insert(tmp);
      }
    }
    if (ans.size() >= 5)
      break;
  }
  for (auto i : ans) {
    k--;
    if (k == 0) {
      cout << i << endl;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
vector<int> posi[30];
set<string> ans;
int main() {
  string s;
  int k;
  cin >> s >> k;
  for (int i = 0; s[i]; ++i) {
    posi[s[i] - 'a'].emplace_back(i);
  }
  for (int i = 0; i < 26; ++i) {
    for (auto j : posi[i]) {
      string tmp = "";
      for (int k = j; s[k] && k - j <= 4; ++k) {
        tmp += s[k];
        ans.insert(tmp);
      }
    }
    if (ans.size() >= 5)
      break;
  }
  for (auto i : ans) {
    k--;
    if (k == 0) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(int argc, char *argv[]) {
  map<string, int> mp;
  string S;
  vector<string> sub;
  cin >> S;
  int K;
  cin >> K;
  int flag = -1;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= K; j++) {
      string t = S.substr(i, j);
      // cout<<t<<endl;
      if (mp.count(t))
        continue;
      else {

        mp[t] = 1;

        sub.push_back(t);
        sort(sub.begin(), sub.end());
      }
    }
  }

  sort(sub.begin(), sub.end());
  cout << sub[K - 1] << endl;
  // for(int i=0; i<K; i++) cout<<sub[i]<<endl;
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(int argc, char *argv[]) {
  map<string, int> mp;
  string S;
  vector<string> sub;
  cin >> S;
  int K;
  cin >> K;
  int flag = -1;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= K; j++) {
      string t = S.substr(i, j);
      // cout<<t<<endl;
      if (mp.count(t))
        continue;
      else {

        mp[t] = 1;

        sub.push_back(t);
      }
    }
  }

  sort(sub.begin(), sub.end());
  cout << sub[K - 1] << endl;
  // for(int i=0; i<K; i++) cout<<sub[i]<<endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
vector<string> ans;

int main() {
  cin >> s >> k;
  int slen = s.length();
  for (int i = 0; i < slen; ++i) {
    for (int j = 1; j <= slen - i; ++j) {
      string now = s.substr(i, j);
      ans.push_back(now);
    }
  }
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());

  cout << ans.at(k - 1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
vector<string> ans;

int main() {
  cin >> s >> k;
  int slen = s.length();
  for (int i = 0; i < slen; ++i) {
    for (int j = 1; j <= min(k, slen - i); ++j) {
      string now = s.substr(i, j);
      ans.push_back(now);
    }
  }
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());

  cout << ans.at(k - 1) << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

string solve(string &s, int k) {
  set<string> ss;
  for (int i = 0; i < s.size(); ++i) {
    for (int k = 1; k <= s.size(); ++k) {
      ss.insert(s.substr(i, k));
    }
  }
  int pos{};
  for (auto e : ss) {
    if (pos == k - 1)
      return e;
    ++pos;
  }
  return "-1";
}

int main() {
  string s;
  int k;
  cin >> s >> k;
  cout << solve(s, k) << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

string solve(string &s, int k) {
  set<string> ss;
  for (int i = 0; i < s.size(); ++i) {
    for (int k = 1; k <= 5; ++k) {
      ss.insert(s.substr(i, k));
    }
  }
  int pos{};
  for (auto e : ss) {
    if (pos == k - 1)
      return e;
    ++pos;
  }
  return "-1";
}

int main() {
  string s;
  int k;
  cin >> s >> k;
  cout << solve(s, k) << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int k, l;
vector<string> v;
string s, a;
int main() {
  cin >> a >> k;
  l = a.size();
  for (int i = 0; i < l; i++) {
    s = "";
    for (int j = i; j < l; j++) {
      s += a[j];
      v.push_back(s);
    }
  }
  sort(v.begin(), v.end());
  int i = 0;
  while (i < k) {
    if (i == k - 1)
      break;
    if (v[i] < v[i + 1])
      i++;
    else
      i++, k++;
  }
  cout << v[i];
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int k, l;
vector<string> v;
string s, a;
int main() {
  cin >> a >> k;
  l = a.size();
  for (int i = 0; i < l; i++) {
    s = "";
    for (int j = i; j < l; j++) {
      if (s.size() > 5)
        break;
      s += a[j];
      v.push_back(s);
    }
  }
  sort(v.begin(), v.end());
  int i = 0;
  while (i < k) {
    if (i == k - 1)
      break;
    if (v[i] < v[i + 1])
      i++;
    else
      i++, k++;
  }
  cout << v[i];
  return 0;
}
Problem p03353 (C++)

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

int main() {
  int k;
  string s;
  cin >> s >> k;
  int n = s.length();
  set<string> s_set;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j + i <= n; ++j) {
      s_set.insert(s.substr(j, i));
    }
  }
  vector<string> s_vec(s_set.begin(), s_set.end());
  sort(s_vec.begin(), s_vec.end());

  cout << s_vec[k - 1] << endl;
}

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

int main() {
  int k;
  string s;
  cin >> s >> k;
  int n = s.length();
  set<string> s_set;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; ++j) {
      s_set.insert(s.substr(i, j));
    }
  }
  vector<string> s_vec(s_set.begin(), s_set.end());
  sort(s_vec.begin(), s_vec.end());

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  int K;
  int Num = 0;
  vector<string> ss;
  cin >> s >> K;
  FOR(k, 'a', 'z' + 1) {
    FOR(i, 0, s.size()) {
      if (int(s[i]) == k) {
        for (int(j) = 1; j + i <= s.size(); j++) {
          ss.push_back(s.substr(i, j));
        }
      }
    }
    sort(ss.begin(), ss.end());
    if (ss.size() != 0) {
      Num++;
      if (Num == K) {
        cout << ss[0];
        return 0;
      }
    }
    FOR(i, 1, ss.size()) {
      if (ss[i - 1] != ss[i])
        Num++;
      if (Num == K) {
        cout << ss[i];
        return 0;
      }
    }
    ss.clear();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  int K;
  int Num = 0;
  vector<string> ss;
  cin >> s >> K;
  FOR(k, 'a', 'z' + 1) {
    FOR(i, 0, s.size()) {
      if (int(s[i]) == k) {
        for (int(j) = 1; j + i <= s.size() && j < 6; j++) {
          ss.push_back(s.substr(i, j));
        }
      }
    }
    sort(ss.begin(), ss.end());
    if (ss.size() != 0) {
      Num++;
      if (Num == K) {
        cout << ss[0];
        return 0;
      }
    }
    FOR(i, 1, ss.size()) {
      if (ss[i - 1] != ss[i])
        Num++;
      if (Num == K) {
        cout << ss[i];
        return 0;
      }
    }
    ss.clear();
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
typedef long long ll;
ll mod = 1000000007;
string s;

int main() {
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 0; j < s.size() - i + 1; ++j) {
      string sub = s.substr(j, i);
      st.insert(sub);
    }
  }
  vector<string> vt;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    vt.push_back(*itr);
  }
  sort(vt.begin(), vt.end());
  cout << vt[k - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
typedef long long ll;
ll mod = 1000000007;
string s;

int main() {
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < s.size() - i + 1; ++j) {
      string sub = s.substr(j, i);
      st.insert(sub);
    }
  }
  vector<string> vt;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    vt.push_back(*itr);
  }
  sort(vt.begin(), vt.end());
  cout << vt[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++)
#define INF 1000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main() {
  string str;
  int k;
  cin >> str >> k;
  set<string> st;
  st.insert(str);
  for (int i = 0; i < str.size(); i++) {
    for (int j = 0; j < str.size(); j++) {
      st.insert(str.substr(i, j));
      // cout << str.substr(i, j) << endl;
    }
  }
  /*for(auto x : st)
  {
          cout << x << endl;
          //vec.push_back(x);
  }*/
  auto ans = st.begin();
  for (int i = 0; i < k; i++)
    ans++;
  cout << *ans << endl;
  // sort(vec.begin(), vec.end());
  // for(int i = 0; i < vec.size(); i++)
  //{
  //	cout << vec[i] << endl;
  // }
  // cout << vec[k] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main() {
  string str;
  int k;
  cin >> str >> k;
  set<string> st;
  st.insert(str);
  for (int i = 0; i < str.size(); i++) {
    for (int j = 0; j <= k; j++) {
      st.insert(str.substr(i, j));
      // cout << str.substr(i, j) << endl;
    }
  }
  /*for(auto x : st)
  {
          cout << x << endl;
          //vec.push_back(x);
  }*/
  auto ans = st.begin();
  for (int i = 0; i < k; i++)
    ans++;
  cout << *ans << endl;
  // sort(vec.begin(), vec.end());
  // for(int i = 0; i < vec.size(); i++)
  //{
  //	cout << vec[i] << endl;
  // }
  // cout << vec[k] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>

using namespace std;

int main() {
  string str;
  int num;
  set<string> list;

  int i, j;

  cin >> str;
  cin >> num;

  for (i = 0; i < str.size() && num; i++) {
    for (j = 1; j <= str.size() && num; j++) {
      list.insert(str.substr(i, j));
    }
  }

  set<string>::iterator it = list.begin();
  advance(it, num - 1);

  cout << *it << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <set>

using namespace std;

int main() {
  string str;
  int num;
  set<string> list;

  int i, j;

  cin >> str;
  cin >> num;

  for (i = 0; i < str.size() && num; i++) {
    for (j = 1; j <= num && (i + j); j++) {
      list.insert(str.substr(i, j));
    }
  }

  set<string>::iterator it = list.begin();
  advance(it, num - 1);

  cout << *it << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  set<string> substr;
  rep(i, N) {
    rep1(j, N) {
      string s = S.substr(i, j);
      auto res = substr.insert(s);
      if (res.second) {
        auto pos = std::distance(substr.begin(), res.first);
        if (pos >= K) {
          break;
        }
      }
    }
  }
  auto it = substr.cbegin();
  rep(i, K - 1) { ++it; }
  cout << *it << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  set<string> substr;
  rep(i, N) {
    rep1(j, K) {
      string s = S.substr(i, j);
      auto res = substr.insert(s);
      if (res.second) {
        auto pos = std::distance(substr.begin(), res.first);
        if (pos >= K) {
          break;
        }
      }
    }
  }
  auto it = substr.cbegin();
  rep(i, K - 1) { ++it; }
  cout << *it << endl;
  return 0;
}
Problem p03353 (C++)

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

int main() {
  int K, k = 0;
  std::string s, temp;
  std::vector<std::string> vec1, min;

  std::cin >> s;
  std::cin >> K;

  for (unsigned long i = 0; i < s.length(); i++)
    for (unsigned long j = 0; j < s.length() - i; j++) {
      temp = s.substr(i, j + 1);
      vec1.push_back(temp);
    }

  std::sort(vec1.begin(), vec1.end());

  while (min.size() < K) {
    if (min.empty())
      min.push_back(vec1[k]);
    else if (min.size() < K && vec1[k] != min.back())
      min.push_back(vec1[k]);
    k++;
  }

  std::cout << min[K - 1] << std::endl;
  return 0;
}

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

int main() {
  int K, k = 0;
  std::string s, temp;
  std::vector<std::string> vec1, min;

  std::cin >> s;
  std::cin >> K;

  for (unsigned long i = 0; i < s.length(); i++)
    for (unsigned long j = 0; j < K; j++) {
      temp = s.substr(i, j + 1);
      vec1.push_back(temp);
    }

  std::sort(vec1.begin(), vec1.end());

  while (min.size() < K) {
    if (min.empty())
      min.push_back(vec1[k]);
    else if (min.size() < K && vec1[k] != min.back())
      min.push_back(vec1[k]);
    k++;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  string s;
  cin >> s;
  int N = s.size();
  int K;
  cin >> K;

  vector<string> st;
  rep(start, N) {
    repp(end, start, N - 1) { st.pb(s.substr(start, end - start + 1)); }
  }
  sort(all(st));
  int cnt = 0;
  string temp = "";

  rep(i, st.size()) {
    if (temp != st[i]) {
      cnt++;
      temp = st[i];
    }
    if (cnt == K) {
      cout << st[i] << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  string s;
  cin >> s;
  int N = s.size();
  int K;
  cin >> K;

  vector<string> st;
  rep(start, N) {
    repp(end, start, min(N - 1, start + 4)) {
      st.pb(s.substr(start, end - start + 1));
    }
  }
  sort(all(st));
  int cnt = 0;
  string temp = "";

  rep(i, st.size()) {
    if (temp != st[i]) {
      cnt++;
      temp = st[i];
    }
    if (cnt == K) {
      cout << st[i] << endl;
      return 0;
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int k;
  string s;
  map<string, int> m;
  cin >> s >> k;
  for (int i = 1; i <= 5; i++) {
    for (int j = 0; j <= s.length() - i; j++) {
      string t = s.substr(j, i);
      m[t] = 1;
    }
  }
  auto itr = m.begin();
  itr = next(itr, k - 1);
  cout << itr->first << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int k;
  string s;
  map<string, int> m;
  cin >> s >> k;
  for (int i = 1; i <= 5; i++) {
    if (s.length() < i)
      continue;
    for (int j = 0; j <= s.length() - i; j++) {
      string t = s.substr(j, i);
      m[t] = 1;
    }
  }
  auto itr = m.begin();
  itr = next(itr, k - 1);
  cout << itr->first << endl;
  return 0;
}
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
K = int(input())

S = set([])
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        # print(f'{s[i:j]=}')
        S.add(s[i:j])
# print(f'{S=}')
# print(f'{sorted(S)=}')
ans = sorted(S)[K - 1]
print(ans)


Fixed submission:
s = input()
K = int(input())

S = set([])
for i in range(len(s)):
    for j in range(i + 1, i + 1 + K):
        # print(f'{s[i:j]=}')
        S.add(s[i:j])
# print(f'{S=}')
# print(f'{sorted(S)=}')
ans = sorted(S)[K - 1]
print(ans)
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
k = int(input())
n = len(s)

s = list(s)
ans = []
for i in range(n + 1):
    for j in range(i + 1, n + 1):
        ans.append(str("".join(s[i:j])))

ans = sorted(list(set(ans)))
print(ans[k - 1])


Fixed submission:
s = input()
k = int(input())
n = len(s)

s = list(s)
ans = []
for i in range(n + 1):
    for j in range(i + 1, min(i + 1 + k, n + 1)):
        ans.append(str("".join(s[i:j])))

ans = sorted(list(set(ans)))
print(ans[k - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
K = int(input())

s_set = set()
for i in range(len(s) + 1):
    for j in range(i + 1, len(s) + 1):
        s_set.add(s[i:j])
s_list = list(s_set)
s_list.sort()
print(s_list[K - 1])


Fixed submission:
s = input()
K = int(input())

s_set = set()
for i in range(len(s)):
    for j in range(i + 1, i + K + 1):
        if j > len(s) + 1:
            break
        s_set.add(s[i:j])
s_list = list(s_set)
s_list.sort()
print(s_list[K - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
k = int(input())
a = set()
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        a.add(s[i:j])
print(sorted(list(a))[k - 1])


Fixed submission:
s = input()
k = int(input())
a = set()
for i in range(len(s) + 1):
    for j in range(1, 6):
        a.add(s[i : i + j])
print(sorted(list(a))[k])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10**9)

S = input()
K = int(input())

chars = sorted(set(S))
checked = set()


def dfs(s):
    for c in chars:
        next_s = s + c
        if next_s not in checked and next_s in S:
            checked.add(next_s)
            if len(checked) == K:
                print(next_s)
                return
            elif len(next_s) <= len(S):
                dfs(next_s)


dfs("")


Fixed submission:
import sys

sys.setrecursionlimit(10**9)

S = input()
K = int(input())

chars = sorted(set(S))
checked = set()


def dfs(s):
    for c in chars:
        if len(checked) >= K:
            return
        next_s = s + c
        if next_s not in checked and next_s in S:
            checked.add(next_s)
            if len(checked) == K:
                print(next_s)
                return
            elif len(next_s) <= len(S):
                dfs(next_s)


dfs("")
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
K = int(input())

subList = set([])

for front in range(0, len(S)):
    for length in range(1, len(S) + 1):
        subList.add(S[front : front + length])

subList = list(subList)
subList.sort()

print(subList[K - 1])


Fixed submission:
S = input()
K = int(input())

subList = set([])

for front in range(0, len(S)):
    for length in range(1, K + 1):
        subList.add(S[front : front + length])

subList = list(subList)
subList.sort()

print(subList[K - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = str(input())
k = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        subs.add(s[i:j])
print(sorted(list(subs))[k - 1])


Fixed submission:
s = str(input())
k = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, i + k + 1):
        subs.add(s[i:j])
print(sorted(list(subs))[k - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, N):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])


Fixed submission:
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
from heapq import nsmallest

s = input()
K = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        subs.add(s[i:j])
arr = list(subs)
print(nsmallest(K, arr)[-1])


Fixed submission:
from heapq import nsmallest

s = input()
K = int(input())
subs = set()
for i in range(len(s)):
    for j in range(i + 1, min(i + 6, len(s) + 1)):
        subs.add(s[i:j])
arr = list(subs)
print(nsmallest(K, arr)[-1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == "__main__":
    s = input()
    k = int(input())
    extracted = list()
    s_len = len(s)

    for i in range(1, s_len + 1):
        start = 0
        ended = i

        for j in range(s_len - i + 1):
            sub_str = s[start:ended]

            if sub_str not in extracted:
                extracted.append(sub_str)

            start += 1
            ended += 1

    sorted_extracted = sorted(extracted)
    print(sorted_extracted[k - 1])


Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == "__main__":
    s = input()
    k = int(input())
    extracted = list()
    s_len = len(s)

    for i in range(1, min(k, s_len) + 1):
        start = 0
        ended = i

        for j in range(s_len - i + 1):
            sub_str = s[start:ended]

            if sub_str not in extracted:
                extracted.append(sub_str)

            start += 1
            ended += 1

    sorted_extracted = sorted(extracted)
    print(sorted_extracted[k - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = input()
    K = int(input())
    result = set()

    for i in range(len(S) + 1):
        for j in range(i + 1, len(S) + 1):
            result.add(S[i:j])

    print(sorted(result)[K - 1])


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = input()
    K = int(input())
    result = set()

    for i in range(5):
        for j in range(len(S)):
            result.add(S[j : j + i + 1])

    print(sorted(result)[K - 1])


if __name__ == "__main__":
    main()
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
K = int(input())

sub = set()
for i in range(1, len(s) + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k : i + k])

print(sorted([i for i in sub])[K - 1])


Fixed submission:
s = input()
K = int(input())

sub = set()
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k : i + k])

print(sorted([i for i in sub])[K - 1])
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
K = int(input())

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, len(s) - i):
        substring = s[i : i + slen + 1]
        substr_set.add(substring)

print(sorted(substr_set)[K - 1])


Fixed submission:
s = input()
K = int(input())

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, K):
        substring = s[i : i + slen + 1]
        substr_set.add(substring)

print(sorted(substr_set)[K - 1])
Problem p03353 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  int k;
  cin >> s >> k;

  set<string> subs;

  for (int i = 0; i < s.size(); i++) {
    string c{s.at(i)};
    subs.insert(c);
    for (int j = i + 1; j < s.size(); j++) {
      c += s.at(j);
      subs.insert(c);
    }
  }

  int counter = 0;
  for (auto itr = subs.begin(); counter < k; ++itr, ++counter) {
    if (counter == k - 1) {
      cout << *itr << endl;
    }
  }

  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  int k;
  cin >> s >> k;

  set<string> subs;

  for (int i = 0; i < s.size(); i++) {
    string c{s.at(i)};
    subs.insert(c);
    for (int j = i + 1; j < s.size(); j++) {
      c += s.at(j);
      subs.insert(c);
      if (c.size() == k) {
        break;
      }
    }
  }

  int counter = 0;
  for (auto itr = subs.begin(); counter < k; ++itr, ++counter) {
    if (counter == k - 1) {
      cout << *itr << endl;
    }
  }

  return 0;
}
Problem p03353 (C++)

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

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

  cout << *itr << endl;
  return 0;
}

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

int main(void) {
  set<string> st;
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 1; i <= min(5, (int)s.size()); i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      st.insert(s.substr(j, i));
    }
  }
  auto itr = st.begin();
  for (int i = 1; i < k; i++) {
    itr++;
  }

  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  int N, K;
  cin >> S >> K;
  N = S.size();
  vector<string> A;
  rep(i, 0, N) {
    string s;
    rep(j, i, min(j + K, N)) A.push_back(s += S[j]);
  }
  sort(begin(A), end(A));
  A.erase(unique(begin(A), end(A)), end(A));
  cout << A[K - 1] << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  int N, K;
  cin >> S >> K;
  N = S.size();
  vector<string> A;
  rep(i, 0, N) {
    string s;
    rep(j, i, min(i + K, N)) A.push_back(s += S[j]);
  }
  sort(begin(A), end(A));
  A.erase(unique(begin(A), end(A)), end(A));
  cout << A[K - 1] << '\n';
}
Problem p03353 (C++)

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> ST;
  for (int i = 0; i <= n - k; ++i) {
    for (int j = 1; j <= 5; ++j) {
      ST.push_back(s.substr(i, j));
    }
  }
  sort(ST.begin(), ST.end());
  unique(ST.begin(), ST.end());
  cout << ST[k - 1] << endl;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> ST;
  for (int i = 0; i <= n - 1; ++i) {
    for (int j = 1; j <= 5; ++j) {
      ST.push_back(s.substr(i, j));
    }
  }
  sort(ST.begin(), ST.end());
  unique(ST.begin(), ST.end());
  cout << ST[k - 1] << endl;
}
Problem p03353 (C++)

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  int N = S.size();
  set<string> a;
  rep(i, N) {
    for (int j = 1; j <= 5; j++) {
      if (i + j >= N)
        continue;
      a.insert(S.substr(i, j));
    }
  }
  auto itr = a.begin();
  rep(i, K - 1) itr++;
  cout << *itr << endl;
  return 0;
}

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  int N = S.size();
  set<string> a;
  rep(i, N) {
    for (int j = 1; j <= 5; j++) {
      if (i + j > N)
        continue;
      a.insert(S.substr(i, j));
    }
  }
  auto itr = a.begin();
  rep(i, K - 1) itr++;
  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  cin >> s;
  map<string, int> vec;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      vec[s.substr(i, j)] = 1;
    }
  }
  int k;
  cin >> k;
  int cnt = 1;
  for (auto p : vec) {
    if (cnt == k) {
      cout << p.first << endl;
      return 0;
    }
    cnt++;
  }
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  map<string, int> vec;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      vec[s.substr(i, j)] = 1;
    }
  }
  int k;
  cin >> k;
  int cnt = 1;
  for (auto p : vec) {
    if (cnt == k) {
      cout << p.first << endl;
      return 0;
    }
    cnt++;
  }
  return 0;
}
Problem p03353 (C++)

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

int main() {
  vector<string> st;
  string s;
  cin >> s;
  int kk;
  cin >> kk;
  int kp = s.size();
  for (int i = 1; i <= min(kk, kp); i++) {
    for (int j = 0; j < s.size() - i; j++) {
      string str(i, 'a');
      for (int k = 0; k < i; k++) {
        str[k] = s[j + k];
      }
      st.push_back(str);
    }
  }
  if (s.size() == 1)
    st.push_back(s);
  sort(st.begin(), st.end());
  unique(st.begin(), st.end());
  // for(int i=0;i<st.size();i++)cout<<st[i]<<endl;
  kk--;
  cout << st[kk] << endl;
}


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

int main() {
  vector<string> st;
  string s;
  cin >> s;
  int kk;
  cin >> kk;
  int kp = s.size();
  for (int i = 1; i <= min(kk, kp); i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      string str(i, 'a');
      for (int k = 0; k < i; k++) {
        str[k] = s[j + k];
      }
      st.push_back(str);
    }
  }
  if (s.size() == 1)
    st.push_back(s);
  sort(st.begin(), st.end());
  unique(st.begin(), st.end());
  // for(int i=0;i<st.size();i++)cout<<st[i]<<endl;
  kk--;
  cout << st[kk] << endl;
}
Problem p03353 (C++)

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

int cnt = 0, K_tmp;
string s;
bool flag = false;

void dfs(string subs) {
  if (cnt == K_tmp) {
    cout << subs << endl;
  } else if (subs.size() <= K_tmp) {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (s.find(subs + c) >= 0 && s.find(subs + c) < s.size()) {
        cnt++;
        dfs(subs + c);
      }
    }
  }
}

int main() {
  cin >> s;
  int K;
  cin >> K;
  K_tmp = K;
  dfs("");
}

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

int cnt = 0, K_tmp;
string s;
bool flag = false;

void dfs(string subs) {
  if (cnt == K_tmp) {
    cout << subs << endl;
  } else if (cnt <= K_tmp) {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (s.find(subs + c) >= 0 && s.find(subs + c) < s.size()) {
        cnt++;
        dfs(subs + c);
      }
    }
  }
}

int main() {
  cin >> s;
  int K;
  cin >> K;
  K_tmp = K;
  dfs("");
}
Problem p03353 (C++)

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.length();
  vector<string> subs;
  vector<vector<int>> index(26);
  for (int i = 0; i < n; i++) {
    index[s[i] - 97].push_back(i);
  }
  vector<int> priority;
  for (int i = 0; i < 26; i++) {
    priority.insert(priority.end(), index[i].begin(), index[i].end());
  }
  for (int i = 0; i < n; i++) {
    string tmp = "";
    for (int j = priority[i]; j < n; j++) {
      if (!tmp.empty() && tmp[j - 1] != tmp[j]) {
        tmp += s[j];
        subs.push_back(tmp);
      }
      if (tmp.length() > k)
        break;
    }
  }
  sort(subs.begin(), subs.end());
  unique(subs.begin(), subs.end());
  cout << subs[k - 1] << endl;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.length();
  vector<string> subs;
  vector<vector<int>> index(26);
  for (int i = 0; i < n; i++) {
    index[s[i] - 97].push_back(i);
  }
  vector<int> priority;
  for (int i = 0; i < 26; i++) {
    priority.insert(priority.end(), index[i].begin(), index[i].end());
  }
  for (int i = 0; i < n; i++) {
    string tmp = "";
    for (int j = priority[i]; j < n; j++) {
      tmp += s[j];
      subs.push_back(tmp);
      if (tmp.length() > k)
        break;
    }
  }
  sort(subs.begin(), subs.end());
  unique(subs.begin(), subs.end());
  cout << subs[k - 1] << endl;
}
Problem p03353 (C++)

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

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

  vector<string> arr;
  map<string, int> m;
  int cnt = 0;
  for (char i = 'a'; i <= 'z'; i++) {
    if (cnt > k) {
      break;
    }
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == i) {
        string S = "";
        for (int z = j; z < s.size(); z++) {
          S += s[z];
          if (m[S] == 0) {
            arr.push_back(S);
            cnt++;
            m[S]++;
          }
        }
      }
    }
  }
  sort(arr.begin(), arr.end());
  cout << arr[k - 1] << endl;
}

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

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

  vector<string> arr;
  map<string, int> m;
  int cnt = 0;
  for (char i = 'a'; i <= 'z'; i++) {
    if (cnt > k) {
      break;
    }
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == i) {
        string S = "";
        for (int z = j; z < s.size() && z < j + k; z++) {
          S += s[z];
          if (m[S] == 0) {
            arr.push_back(S);
            cnt++;
            m[S]++;
          }
        }
      }
    }
  }
  sort(arr.begin(), arr.end());
  cout << arr[k - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define MEM(a, b) memset(a, b, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      v.push_back(s.substr(j, i));
    }
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

  cout << v[k - 1] << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define MEM(a, b) memset(a, b, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  int unko = min(k, (int)s.size());
  for (int i = 1; i <= unko; i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      v.push_back(s.substr(j, i));
    }
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

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

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

typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)2e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos(-1.0);

#define all(V) V.begin(), V.end()
#define Unique(a) sort(all(a)), a.erase(unique(all(a)), a.end())

vector<string> V;

int main(int argc, char const *argv[]) {
  string s;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    string ret = "";
    for (int j = i; j < s.size(); j++) {
      ret += s[j];
      V.push_back(ret);
    }
  }
  Unique(V);
  cout << V[k - 1] << endl;
  // for( auto x : V ) cout << x << " ";
  return 0;
}


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

typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)2e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos(-1.0);

#define all(V) V.begin(), V.end()
#define Unique(a) sort(all(a)), a.erase(unique(all(a)), a.end())

vector<string> V;

int main(int argc, char const *argv[]) {
  string s;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    string ret = "";
    for (int j = i; j < s.size(); j++) {
      ret += s[j];
      if (ret.size() > k)
        break;
      V.push_back(ret);
    }
  }
  Unique(V);
  cout << V[k - 1] << endl;
  // for( auto x : V ) cout << x << " ";
  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 < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;

int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> v;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i; j++) {
      v.insert(s.substr(i, j));
    }
  }
  string x = *next(v.begin(), K - 1);
  cout << x << endl;
}

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

int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> v;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1, lim = min((int)(s.length() - i), K); j <= lim; j++) {
      v.insert(s.substr(i, j));
    }
  }
  string x = *next(v.begin(), K - 1);
  cout << x << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  string str;
  set<string> st;
  cin >> str;
  cin >> n;
  for (int i = 0; i < str.size(); i++) {
    string sub = "";
    for (int j = i; j < str.size(); j++) {
      sub += str[j];
      st.insert(sub);
    }
  }
  auto it = st.begin();
  n--;
  while (n--)
    it++;
  cout << *it << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  string str;
  set<string> st;
  cin >> str;
  cin >> n;
  for (int i = 0; i < str.size(); i++) {
    string sub = "";
    for (int j = i; j <= n + i && j < str.size(); j++) {
      sub += str[j];
      st.insert(sub);
    }
  }
  auto it = st.begin();
  n--;
  while (n--)
    it++;
  cout << *it << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(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 tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
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;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  int n = s.size();
  rep(i, n) rep2(j, 1, n - i + 1) { v.pb(s.substr(i, j)); }
  sort(all(v));
  int cnt = 1;
  string ns = v[0];
  if (k == 1) {
    cout << ns << endl;
    return 0;
  }
  rep2(i, 1, v.size()) {
    if (ns == v[i])
      continue;
    cnt++;
    if (cnt == k) {
      cout << v[i] << endl;
      return 0;
    }
    ns = v[i];
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(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 tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
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;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  int n = s.size();
  rep(i, n) rep2(j, 1, min(n - i + 1, 6)) { v.pb(s.substr(i, j)); }
  sort(all(v));
  int cnt = 1;
  string ns = v[0];
  if (k == 1) {
    cout << ns << endl;
    return 0;
  }
  rep2(i, 1, v.size()) {
    if (ns == v[i])
      continue;
    cnt++;
    if (cnt == k) {
      cout << v[i] << endl;
      return 0;
    }
    ns = v[i];
  }
}