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

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

std::string s;
int K;
std::vector<std::string> res;

int main() {
  in >> s >> K;
  rep(i, s.length()) {
    for (int j = 1; j <= s.length() - i; ++j)
      res.push_back(s.substr(i, j));
  }
  std::sort(res.begin(), res.end());
  res.erase(std::unique(res.begin(), res.end()), res.end());
  out << res[K - 1] << std::endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

std::string s;
int K;
std::vector<std::string> res;

int main() {
  in >> s >> K;
  rep(i, s.length()) {
    for (int j = 1; j <= std::min<int>(K, s.length() - i); ++j)
      res.push_back(s.substr(i, j));
  }
  std::sort(res.begin(), res.end());
  res.erase(std::unique(res.begin(), res.end()), res.end());
  out << res[K - 1] << std::endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> ss;
  for (int i = 0; i < s.size(); i++)
    for (int j = i + 1; j <= s.size(); j++) {
      ss.insert(s.substr(i, j - i));
    }
  auto it = ss.begin();
  for (int i = 0; i < k - 1; i++)
    it++;
  cout << *it << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> ss;
  if (s.size() < 10) {
    for (int i = 0; i < s.size(); i++)
      for (int j = i + 1; j <= s.size(); j++) {
        ss.insert(s.substr(i, j - i));
      }
    auto it = ss.begin();
    for (int i = 0; i < k - 1; i++)
      it++;
    cout << *it << endl;
  } else {
    for (int i = 0; i < s.size(); i++)
      for (int j = i + 1; j <= s.size() && j - i < 7; j++)
        ss.insert(s.substr(i, j - i));
    auto it = ss.begin();
    for (int i = 0; i < k - 1; i++)
      it++;

    cout << *it << endl;
  }
  return 0;
}
Problem p03355 (C++)

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

using namespace std;

const int MAXN = 5007;

bool used[MAXN][MAXN];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

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

  int n = s.size();
  vector<string> a;
  for (int l = 0; l < n; ++l) {
    for (int r = l; r < min(n, r + 6); ++r) {
      a.push_back(s.substr(l, r - l + 1));
    }
  }
  sort(a.begin(), a.end());
  unique(a.begin(), a.end());
  cout << a[k - 1] << '\n';
  return 0;
}

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

using namespace std;

const int MAXN = 5007;

bool used[MAXN][MAXN];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

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

  int n = s.size();
  vector<string> a;
  for (int l = 0; l < n; ++l) {
    for (int r = l; r < min(n, l + 6); ++r) {
      a.push_back(s.substr(l, r - l + 1));
    }
  }
  sort(a.begin(), a.end());
  unique(a.begin(), a.end());
  cout << a[k - 1] << '\n';
  return 0;
}
Problem p03355 (C++)

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

using namespace std;

const int N = 1e5 + 5;
typedef long long ll;
set<string> a;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; s[i] != '\0'; i++) {
    for (int j = 0; s[j + i] != '\0'; j++) {
      string f(s, i, j + 1);
      a.insert(f);
    }
  }
  set<string>::iterator it;
  it = a.begin();
  k--;
  while (k--)
    it++;
  cout << *it << endl;
}


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

using namespace std;

const int N = 1e5 + 5;
typedef long long ll;
set<string> a;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; s[i] != '\0'; i++) {
    for (int j = 0; s[j + i] != '\0' && j <= 5; j++) {
      string f(s, i, j + 1);
      a.insert(f);
    }
  }
  set<string>::iterator it;
  it = a.begin();
  k--;
  while (k--)
    it++;
  cout << *it << endl;
}
Problem p03355 (C++)

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

priority_queue<int> q;

struct node {
  string s;
};

priority_queue<string, vector<string>, greater<string>> ans;

char ch[5500];

map<string, int> mark;
bool f[2000];

int main() {

  int i, j, l, x, k;
  string A;
  scanf("%s", ch);
  for (i = 0; ch[i]; i++)
    if (!f[ch[i]]) {
      q.push(-ch[i]);
      f[ch[i]] = true;
    }
  scanf("%d", &k);
  if (k == 1) {
    printf("%c", -q.top());
    return 0;
  }
  while (k && !q.empty()) {
    // printf("%d\n",k);
    x = -q.top();
    q.pop();
    for (i = 0; ch[i]; i++)
      if (ch[i] == x) {
        A.clear();
        for (j = i; ch[j] && i + 5 <= j; j++) {
          A += ch[j];
          ans.push(A);
        }
      }
    while (k && !ans.empty()) {
      // printf("big=%d\n",ans.size());
      //	cout<<ans.top()<<endl;
      A = ans.top();
      if (mark.find(A) == mark.end()) {
        mark[A] = 1;
        k--;
        //	cout<<A<<endl;
      }
      if (k)
        ans.pop();
      /*	if(k==1)k=0;
              printf("?=%d ",k);
              cout<<ans.top()<<' '<<A<<endl;*/
    }
    // if(k==1)break;
  }
  cout << ans.top();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

priority_queue<int> q;

struct node {
  string s;
};

priority_queue<string, vector<string>, greater<string>> ans;

char ch[5500];

map<string, int> mark;
bool f[2000];

int main() {

  int i, j, l, x, k;
  string A;
  scanf("%s", ch);
  for (i = 0; ch[i]; i++)
    if (!f[ch[i]]) {
      q.push(-ch[i]);
      f[ch[i]] = true;
    }
  scanf("%d", &k);
  if (k == 1) {
    printf("%c", -q.top());
    return 0;
  }
  while (k && !q.empty()) {
    // printf("%d\n",k);
    x = -q.top();
    q.pop();
    for (i = 0; ch[i]; i++)
      if (ch[i] == x) {
        A.clear();
        for (j = i; ch[j] && i + 5 >= j; j++) {
          A += ch[j];
          ans.push(A);
        }
      }
    while (k && !ans.empty()) {
      // printf("big=%d\n",ans.size());
      //	cout<<ans.top()<<endl;
      A = ans.top();
      if (mark.find(A) == mark.end()) {
        mark[A] = 1;
        k--;
        //	cout<<A<<endl;
      }
      if (k)
        ans.pop();
      /*	if(k==1)k=0;
              printf("?=%d ",k);
              cout<<ans.top()<<' '<<A<<endl;*/
    }
    // if(k==1)break;
  }
  cout << ans.top();
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
string u = "abcdefghijklmnopqrstuvwxyz";

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> st;
  if (s.length() <= 100) {
    for (int i = 0; i <= s.length(); i++) {
      for (int j = 0; j <= s.length(); j++) {
        st.insert(s.substr(i, j - i));
      }
    }
  } else {
    int check = 0;
    for (int i = 0; i < 26; i++) {
      bool c = false;
      for (int k = 0; k <= s.length(); k++) {
        if (s[k] == u[i]) {
          for (int j = 0; j <= s.length(); j++) {
            st.insert(s.substr(k, j - k));
          }
          c = true;
        }
      }
      if (c)
        check++;
      if (check > 3)
        break;
    }
  }
  int c = 0;
  for (auto p : st) {
    if (c == K) {
      cout << p << endl;
      return 0;
    }
    c++;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
string u = "abcdefghijklmnopqrstuvwxyz";

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> st;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j <= 6; j++) {
      st.insert(s.substr(i, j));
    }
  }
  int c = 0;
  for (auto p : st) {
    if (c == K) {
      cout << p << endl;
      return 0;
    }
    c++;
  }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int K;
  cin >> K;
  --K;
  int n = (int)s.length();

  set<string> words;
  words.clear();
  for (int len = 1; len <= n; ++len) {
    for (int i = 0; i < n; ++i) {
      string sub = s.substr(i, len);
      words.insert(sub);
    } // end for
  }   // end for

  set<string>::iterator it = words.begin();
  for (int i = 0; it != words.end(); ++it, ++i) {
    string t = (*it);
    if (i == K) {
      cout << t << endl;
      break;
    } // end if
  }   // end for

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int K;
  cin >> K;
  --K;
  int n = (int)s.length();

  set<string> words;
  words.clear();
  for (int len = 1; len <= min(5, n); ++len) {
    for (int i = 0; i < n; ++i) {
      string sub = s.substr(i, len);
      words.insert(sub);
    } // end for
  }   // end for

  set<string>::iterator it = words.begin();
  for (int i = 0; it != words.end(); ++it, ++i) {
    string t = (*it);
    if (i == K) {
      cout << t << endl;
      break;
    } // end if
  }   // end for

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

  int n = s.size();
  set<string> st;
  rep(i, n) {
    for (int j = 1; j <= n - i; j++) {
      string t = s.substr(i, j);
      st.insert(t);
    }
  }

  int num = 1;
  for (auto e : st) {
    if (num == k) {
      cout << e << endl;
      return 0;
    }
    num++;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

  int n = s.size();
  set<string> st;
  rep(i, n) {
    for (int j = 1; j <= min(n - i, k); j++) {
      string t = s.substr(i, j);
      st.insert(t);
    }
  }

  int num = 1;
  for (auto e : st) {
    if (num == k) {
      cout << e << endl;
      return 0;
    }
    num++;
  }
}
Problem p03355 (C++)

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

using namespace std;

const int maxn = 1000100;
const int base = 1e9 + 7;

int n, k;
string t;
vector<string> st;

int main() {
  // freopen("in.txt","r",stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  n = t.length();
  cin >> k;
  for (int i = 0; i < n; i++) {
    string tmp = "";
    for (int j = i; j < n; j++) {
      tmp.push_back(t[j]);
      st.push_back(tmp);
    }
  }
  sort(st.begin(), st.end());
  st.erase(unique(st.begin(), st.end()), st.end());
  cout << st[k - 1];
}


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

using namespace std;

const int maxn = 1000100;
const int base = 1e9 + 7;

int n, k;
string t;
vector<string> st;

int main() {
  // freopen("in.txt","r",stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  n = t.length();
  cin >> k;
  for (int i = 0; i < n; i++) {
    string tmp = "";
    for (int j = i; j < min(n, i + 6); j++) {
      tmp.push_back(t[j]);
      st.push_back(tmp);
    }
  }
  sort(st.begin(), st.end());
  st.erase(unique(st.begin(), st.end()), st.end());
  cout << st[k - 1];
}
Problem p03355 (C++)

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

string S;
int K;
int main() {
  cin >> S;
  cin >> K;
  int N = S.size();
  map<string, int> m;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - i; j++) {
      m[S.substr(i, j + 1)]++;
    }
  }
  vector<string> v;
  for (auto x : m) {
    v.push_back(x.first);
  }
  sort(v.begin(), v.end());
  cout << v[K - 1] << endl;
}

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

string S;
int K;
int main() {
  cin >> S;
  cin >> K;
  int N = S.size();
  map<string, int> m;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      m[S.substr(i, j + 1)]++;
    }
  }
  vector<string> v;
  for (auto x : m) {
    v.push_back(x.first);
  }
  sort(v.begin(), v.end());
  cout << v[K - 1] << endl;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri, x, n) for (int ri = (int)(n - 1); ri >= (int)(x); ri--)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  int n = s.size();
  rep(i, n) {
    string add;
    rep2(j, i, n) {
      add.push_back(s.at(j));
      se.insert(add);
    }
  }
  int co = 0;
  for (string s : se) {
    co++;
    if (co == k) {
      cout << s << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri, x, n) for (int ri = (int)(n - 1); ri >= (int)(x); ri--)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  int n = s.size();
  rep(i, n) {
    string add;
    rep2(j, i, min(i + 5, n)) {
      add.push_back(s.at(j));
      se.insert(add);
    }
  }
  int co = 0;
  for (string s : se) {
    co++;
    if (co == k) {
      cout << s << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
string s, aans;
int k, tot, last, cnt[30];
int main() {
  char mmin = 'z';
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    cnt[(int)(s[i] - 'a' + 1)]++;
  while (tot != k) {
    vector<string> ans;
    ans.clear();
    for (int i = last + 1; i <= 26; i++)
      if (cnt[i]) {
        last = i;
        break;
      }
    for (int i = 0; i < s.size(); i++)
      if (s[i] == (char)(last + 'a' - 1)) {
        for (int j = i; j < s.size(); j++) {
          string st = s.substr(i, j - i + 1);
          ans.push_back(st);
        }
      }
    sort(ans.begin(), ans.end());
    tot++;
    if (tot == k) {
      aans = ans[0];
      break;
    }
    for (int i = 1; i < ans.size(); i++) {
      if (ans[i] != ans[i - 1])
        tot++;
      if (tot == k) {
        aans = ans[i];
        break;
      }
    }
  }
  cout << aans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
string s, aans;
int k, tot, last, cnt[30];
int main() {
  char mmin = 'z';
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    cnt[(int)(s[i] - 'a' + 1)]++;
  while (tot != k) {
    vector<string> ans;
    ans.clear();
    for (int i = last + 1; i <= 26; i++)
      if (cnt[i]) {
        last = i;
        break;
      }
    for (int i = 0; i < s.size(); i++)
      if (s[i] == (char)(last + 'a' - 1)) {
        for (int j = i, sum = 1; j < s.size() && sum <= k; j++, sum++) {
          string st = s.substr(i, j - i + 1);
          ans.push_back(st);
        }
      }
    sort(ans.begin(), ans.end());
    tot++;
    if (tot == k) {
      aans = ans[0];
      break;
    }
    for (int i = 1; i < ans.size(); i++) {
      if (ans[i] != ans[i - 1])
        tot++;
      if (tot == k) {
        aans = ans[i];
        break;
      }
    }
  }
  cout << aans;
  return 0;
}
Problem p03355 (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> vec;
  for (int i = 0; i < (int)s.size(); i++) {
    for (int j = i; j < (int)s.size(); j++)
      vec.push_back(s.substr(i, j - i + 1));
  }

  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec[k - 1];
}

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

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

  vector<string> vec;
  for (int i = 0; i < (int)s.size(); i++) {
    for (int j = i; j < min((int)s.size(), i + 6); j++)
      vec.push_back(s.substr(i, j - i + 1));
  }

  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec[k - 1];
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

// #define int long long
//  typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  int K;
  cin >> K;
  string t(s);
  sort(all(t));
  t.erase(unique(all(t)), t.end());
  set<string> v;
  for (char c = 'a'; c <= 'z'; c++) {
    if (v.size() >= K) {
      break;
    }
    rep(i, 0, s.size()) {
      if (s[i] == c) {
        int j = i;
        string tmp;
        while (j < s.size()) {
          tmp.push_back(s[j++]);
          v.insert(tmp);
        }
      }
    }
  }
  auto it = v.begin();
  loop(K - 1) it = next(it);
  cout << *it << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

// #define int long long
//  typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  int K;
  cin >> K;
  string t(s);
  sort(all(t));
  t.erase(unique(all(t)), t.end());
  set<string> v;
  for (char c = 'a'; c <= 'z'; c++) {
    if (v.size() >= K) {
      break;
    }
    rep(i, 0, s.size()) {
      if (s[i] == c) {
        int j = i;
        string tmp;
        int cnt = 0;
        while (j < s.size() and cnt++ < 5) {
          tmp.push_back(s[j++]);
          v.insert(tmp);
        }
      }
    }
  }
  auto it = v.begin();
  loop(K - 1) it = next(it);
  cout << *it << endl;

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
// vector<string>str;
set<string> st;
string s;
int k;
int main() {
  cin >> s;
  cin >> k;
  for (int i = 0; i < s.size(); i++)
    for (int j = i + 1; j <= s.size(); j++)
      st.insert(s.substr(i, j - i));
  vector<string> str(st.begin(), st.end());
  //  for(int i=0;i<str.size();i++)
  cout << str[k - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// vector<string>str;
set<string> st;
string s;
int k;
int main() {
  cin >> s;
  cin >> k;
  for (int i = 0; i < s.size(); i++)
    for (int j = i + 1; j <= s.size() && j < i + 6; j++)
      st.insert(s.substr(i, j - i));
  vector<string> str(st.begin(), st.end());
  //  for(int i=0;i<str.size();i++)
  cout << str[k - 1] << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
set<string> tt;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> s >> k;
  int len = s.size();
  for (int i = 0; i < len; i++) {
    string ss = "";
    for (int j = i; j < len; j++) {
      ss += s[j];
      tt.insert(ss);
    }
  }
  auto it = tt.begin();
  int num = 1;
  while (num < k)
    it++, num++;
  cout << *it << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
set<string> tt;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> s >> k;
  int len = s.size();
  for (int i = 0; i < len; i++) {
    string ss = "";
    for (int j = i; j < len; j++) {
      ss += s[j];
      tt.insert(ss);
      auto it = tt.end();
      it--;
      if (tt.size() > k)
        tt.erase(it);
    }
  }
  auto it = tt.begin();
  int num = 1;
  while (num < k)
    it++, num++;
  cout << *it << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  rep(i, (int)s.size()) {
    for (int j = i + 1; j <= (int)s.size(); ++j) {
      st.insert(s.substr(i, j - i));
    }
  }
  int idx = 0;
  for (auto p : st) {
    if (idx == k - 1) {
      cout << p << endl;
      return 0;
    }
    ++idx;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  rep(i, (int)s.size()) {
    for (int j = 1; j <= 5; ++j) {
      st.emplace(s.substr(i, j));
    }
  }
  int idx = 0;
  for (auto p : st) {
    if (idx == k - 1) {
      cout << p << endl;
      return 0;
    }
    ++idx;
  }
  return 0;
}
Problem p03355 (C++)

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

int main() {
  std::string s;
  int K;

  std::cin >> s >> K;

  std::set<std::string> S;
  for (int i = 0; i < (int)s.length(); ++i) {
    for (int j = 1; j <= (int)s.length() - i; ++j) {
      S.insert(s.substr(i, j));
    }
  }

  int k = 1;
  for (auto ans : S) {
    if (k == K) {
      std::cout << ans << std::endl;
      return 0;
    }
    ++k;
  }
}

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

int main() {
  std::string s;
  int K;

  std::cin >> s >> K;

  std::set<std::string> S;
  for (int i = 0; i < (int)s.length(); ++i) {
    for (int j = 1; j <= std::min(K, (int)s.length() - i); ++j) {
      S.insert(s.substr(i, j));
    }
  }

  int k = 1;
  for (auto ans : S) {
    if (k == K) {
      std::cout << ans << std::endl;
      return 0;
    }
    ++k;
  }
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> S;
  string s;
  int k, n;
  cin >> s >> k;
  n = s.size();
  for (int i = 0; i < n; i++)
    for (int j = 0; i + j < n; j++)
      S.insert(s.substr(i, j + 1));
  int p = 0;
  for (auto x : S) {
    if (p == k - 1) {
      cout << x << endl;
      return 0;
    }
    p++;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> S;
  string s;
  int k, n;
  cin >> s >> k;
  n = s.size();
  for (int i = 0; i < n; i++)
    for (int j = 0; i + j < n && j < 6; j++)
      S.insert(s.substr(i, j + 1));
  int p = 0;
  for (auto x : S) {
    if (p == k - 1) {
      cout << x << endl;
      return 0;
    }
    p++;
  }
}
Problem p03355 (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 REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\n";
}

int main() {
  ll N, K;
  string S;
  cin >> S;
  cin >> K;
  N = S.size();
  // vector<string> v;
  map<string, ll> mp;
  rep(i, N) {
    rep(j, N - i) { mp[S.substr(i, j + 1)]++; }
  }
  // sort(v.begin(), v.end());
  // PR(v,10);
  ll id = 0;
  for (auto &e : mp) {
    if (id == K - 1) {
      cout << e.first << endl;
    }
    id++;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\n";
}

int main() {
  ll N, K;
  string S;
  cin >> S;
  cin >> K;
  N = S.size();
  // vector<string> v;
  map<string, ll> mp;
  rep(i, N) {
    rep(j, min(N - i, ll(5))) { mp[S.substr(i, j + 1)]++; }
  }
  // sort(v.begin(), v.end());
  // PR(v,10);
  ll id = 0;
  for (auto &e : mp) {
    if (id == K - 1) {
      cout << e.first << endl;
    }
    id++;
  }
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)

using namespace std;

string s;
int n;

set<string> S;
int k;
int main() {
  cin >> s >> k;
  n = s.length();
  //	cout << s.substr(2,3) << "\n";
  FOR(i, 1, min(n, 500)) {
    //		S.insert(s.substr(0,i));
    string t;
    FOR(h, 0, i - 1)
    t += s[h];
    S.insert(t);
    FOR(h, i, n - 1) {
      reverse(all(t));
      t.pop_back();
      reverse(all(t));
      t += s[h];
      S.insert(t);
    }
  }

  while (k > 1 && !S.empty())
    k--, S.erase(*S.begin());
  cout << *S.begin();
  //	for (auto i: S)
  //		cout << i << "\n";
}


Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)

using namespace std;

string s;
int n;

set<string> S;
int k;
int main() {
  cin >> s >> k;
  n = s.length();
  //	cout << s.substr(2,3) << "\n";
  FOR(i, 1, min(n, 100)) {
    //		S.insert(s.substr(0,i));
    string t;
    FOR(h, 0, i - 1)
    t += s[h];
    S.insert(t);
    FOR(h, i, n - 1) {
      reverse(all(t));
      t.pop_back();
      reverse(all(t));
      t += s[h];
      S.insert(t);
    }
  }

  while (k > 1 && !S.empty())
    k--, S.erase(*S.begin());
  cout << *S.begin();
  //	for (auto i: S)
  //		cout << i << "\n";
}
Problem p03355 (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 all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

  vector<string> S;
  map<string, int> m;

  rep(i, s.size()) for (int j = i; j < s.size(); j++) {
    string ans = s.substr(i, j - i + 1);
    if (m[ans] > 0)
      continue;
    m[ans]++;
    S.push_back(ans);
  }

  sort(all(S));

  cout << S[K - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

  vector<string> S;
  map<string, int> m;

  rep(i, s.size()) for (int j = i; j < s.size(); j++) {
    if (j - i > 5)
      continue;
    string ans = s.substr(i, j - i + 1);
    if (m[ans] > 0)
      continue;
    m[ans]++;
    S.push_back(ans);
  }

  sort(all(S));

  cout << S[K - 1] << endl;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

int main() {
  map<string, int> mp;
  string S;
  int K;
  cin >> S >> K;

  int i = 0;

  for (int l = 1; l <= S.length(); ++l) {
    for (int i = 0; i < S.length(); ++i) {
      mp[S.substr(i, l)] = 0;
    }
  }

  auto itr = mp.begin();
  for (int i = 1; i < K; ++i) {
    // cout << itr->first << endl;
    ++itr;
  }
  cout << itr->first << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

int main() {
  map<string, int> mp;
  string S;
  int K;
  cin >> S >> K;

  int i = 0;

  for (int l = 1; l <= K; ++l) {
    for (int i = 0; i < S.length(); ++i) {
      mp[S.substr(i, l)] = 0;
    }
  }

  auto itr = mp.begin();
  for (int i = 1; i < K; ++i) {
    // cout << itr->first << endl;
    ++itr;
  }
  cout << itr->first << endl;

  return 0;
}
Problem p03355 (C++)

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

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

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

  auto it = ss.begin();
  for (int i = 0; i < K - 1; i++) {
    it++;
  }

  cout << *it << endl;

  return 0;
}


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

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

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

  auto it = ss.begin();
  for (int i = 0; i < K - 1; i++) {
    it++;
  }

  cout << *it << endl;

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char s[5005], Str[15];
int arr[5005], chk[10005];
int K;

int Hash(char *str) {
  int hap = 37, length;
  length = strlen(str);
  for (int i = 0; i < length; i++) {
    hap = (hap * 1234731 + str[i] - 'a') % 10001;
  }
  return hap;
}

bool comp(int t, int u) {
  if (s[t] == s[u]) {
    for (int i = 1; i < 5; i++) {
      if (s[t + i] == s[u + i]) {
        continue;
      }
      return s[t + i] < s[u + i];
    }
  }
  return s[t] < s[u];
}

int main() {
  int length;
  scanf("%s %d", s, &K);
  length = strlen(s);
  s[length] = 100;
  for (int i = 0; i < length; i++) {
    arr[i] = i;
  }
  sort(arr, arr + length, comp);
  int count = 0, sidx = 0;
  for (int i = 0; i < length; i++) {
    if (count == K) {
      printf("%s", Str);
      break;
    }
    if (arr[i] + count < length) {
      Str[sidx++] = s[arr[i] + count];
      Str[sidx] = 0;
      if (chk[Hash(Str)] == 1) {
        K++;
      }
      chk[Hash(Str)] = 1;
      count++;
      i--;
    } else {
      K -= count;
      count = 0;
      sidx = 0;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char s[5005], Str[15];
int arr[5005], chk[10005];
int K;

int Hash(char *str) {
  long long hap = 37;
  int length;
  length = strlen(str);
  for (int i = 0; i < length; i++) {
    hap = (hap * 1234731 + str[i] - 'a') % 10001;
  }
  return hap;
}

bool comp(int t, int u) {
  if (s[t] == s[u]) {
    for (int i = 1; i < 5; i++) {
      if (s[t + i] == s[u + i]) {
        continue;
      }
      return s[t + i] < s[u + i];
    }
  }
  return s[t] < s[u];
}

int main() {
  int length;
  scanf("%s %d", s, &K);
  length = strlen(s);
  s[length] = 100;
  for (int i = 0; i < length; i++) {
    arr[i] = i;
  }
  sort(arr, arr + length, comp);
  int count = 0, sidx = 0;
  for (int i = 0; i < length; i++) {
    if (count == K) {
      printf("%s", Str);
      break;
    }
    if (arr[i] + count < length) {
      Str[sidx++] = s[arr[i] + count];
      Str[sidx] = 0;
      if (chk[Hash(Str)] == 1) {
        K++;
      }
      chk[Hash(Str)] = 1;
      count++;
      i--;
    } else {
      K -= count;
      count = 0;
      sidx = 0;
    }
  }
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

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

  int n;
  cin >> n;
  n--;

  map<string, int> mp;
  vec<string> p;
  rep(i, s.length()) for (int j = 0; i + j < s.length(); j++) {
    string get = s.substr(i, j + 1);
    if (mp[get])
      continue;
    mp[get] = 1;
    p.pb(get);
  }

  sort(p.begin(), p.end());
  cout << p[n] << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

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

  int n;
  cin >> n;
  n--;

  map<string, int> mp;
  vec<string> p;
  rep(i, s.length()) rep(j, 5) {
    if (i + j >= s.length())
      continue;
    string get = s.substr(i, j + 1);
    if (mp[get])
      continue;
    mp[get] = 1;
    p.pb(get);
  }

  sort(p.begin(), p.end());
  cout << p[n] << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

int in() {
  int x;
  scanf("%d", &x);
  return x;
}
ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}
#define INF 1LL << 60

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

  set<string> subs;

  int len = s.length();
  REP(i, len) {
    FOR(j, i, len) { subs.insert(s.substr(i, j - i + 1)); }
  }

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

Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

int in() {
  int x;
  scanf("%d", &x);
  return x;
}
ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}
#define INF 1LL << 60

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

  set<string> subs;

  int len = s.length();
  REP(i, len) {
    FOR(j, i, min(len, i + K + 1)) { subs.insert(s.substr(i, j - i + 1)); }
  }

  auto itr = subs.begin();
  REP(i, K - 1)++ itr;
  cout << *itr << endl;
  return 0;
}
Problem p03355 (C++)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
  set<string> str_set;

  string str;
  cin >> str;

  int K;
  cin >> K;

  int ma_r = str.size();

  for (int r = 1; r <= ma_r; r++) {
    for (int i = 0; i + r <= str.size(); i++) {
      auto s = str.substr(i, r);
      str_set.insert(s);
    }
  }

  auto itr = str_set.begin();

  REP(i, (K - 1)) itr++;

  cout << *itr << endl;

  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
  set<string> str_set;

  string str;
  cin >> str;

  int K;
  cin >> K;

  int ma_r = str.size();

  ma_r = min(ma_r, K);

  for (int r = 1; r <= ma_r; r++) {
    for (int i = 0; i + r <= str.size(); i++) {
      auto s = str.substr(i, r);
      str_set.insert(s);
    }
  }

  auto itr = str_set.begin();

  REP(i, (K - 1)) itr++;

  cout << *itr << endl;

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int k;
string s, t;
vector<string> v;
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    for (int j = i; j < s.size(); j++) {
      t = s.substr(i, j - i + 1);
      v.push_back(t);
    }
  sort(v.begin(), v.end());
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    if (i == 0 || v[i] != v[i - 1])
      cnt++;
    if (cnt == k) {
      cout << v[i];
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int k;
string s, t;
vector<string> v;
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    for (int j = i; j < i + 5; j++) {
      if (j > s.size() - 1)
        continue;
      t = s.substr(i, j - i + 1);
      v.push_back(t);
    }
  sort(v.begin(), v.end());
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    if (i == 0 || v[i] != v[i - 1])
      cnt++;
    if (cnt == k) {
      cout << v[i];
      return 0;
    }
  }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> st;
  rep(i, n) {
    string t;
    repl(j, i, n) {
      t += s[j];
      st.insert(t);
    }
  }
  int i = 1;
  for (auto p : st) {
    if (i == k) {
      cout << p << endl;
      return 0;
    } else
      i++;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> st;
  rep(i, n) {
    string t;
    repl(j, i, min(n, i + 100)) {
      t += s[j];
      st.insert(t);
    }
  }
  int i = 1;
  for (auto p : st) {
    if (i == k) {
      cout << p << endl;
      return 0;
    } else
      i++;
  }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll BIG = 1e15;

long long ruijou(int n, int k) {
  if (k == 0)
    return 1;
  int x = k / 2;
  long long t = ruijou(n, x);

  if (k % 2 == 1)
    return n * t * t;
  else
    return t * t;
}

int main() {
  set<string> data;
  string S;
  cin >> S;

  int K;
  cin >> K;

  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= S.size() - i; j++) {
      data.insert(S.substr(i, j));
    }
  }

  auto itr = data.begin();
  if (K >= 2) {
    for (int i = 0; i < K - 1; i++)
      itr++;
  }

  cout << *itr << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll BIG = 1e15;

long long ruijou(int n, int k) {
  if (k == 0)
    return 1;
  int x = k / 2;
  long long t = ruijou(n, x);

  if (k % 2 == 1)
    return n * t * t;
  else
    return t * t;
}

int main() {
  set<string> data;
  string S;
  cin >> S;

  int K;
  cin >> K;

  for (int i = 0; i < S.size(); i++) {
    int p = S.size() - i;
    for (int j = 1; j <= min(p, K); j++) {
      data.insert(S.substr(i, j));
    }
  }

  auto itr = data.begin();
  if (K >= 2) {
    for (int i = 0; i < K - 1; i++)
      itr++;
  }

  cout << *itr << endl;
}