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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  string s;
  int K;

  void ans() {
    cin >> s >> K;
    int N = s.size();
    set<string> st;
    for (int i = 0; i < N; i++) {
      for (int j = 1; j <= N - i; j++) {
        st.insert(s.substr(i, j));
      }
    }
    set<string>::iterator itr = st.begin();
    REP(i, K - 1) itr++;
    cout << *itr << "\n";
  }
};

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

  question q;
  q.ans();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  string s;
  int K;

  void ans() {
    cin >> s >> K;
    int N = s.size();
    set<string> st;
    for (int i = 0; i < N; i++) {
      for (int j = 1; j <= min(N - i, K); j++) {
        st.insert(s.substr(i, j));
      }
    }
    set<string>::iterator itr = st.begin();
    REP(i, K - 1) itr++;
    cout << *itr << "\n";
  }
};

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

  question q;
  q.ans();

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main() {
  string s;
  int K;
  cin >> s >> K;
  string t(s);
  set<string> st;
  sort(t.begin(), t.end());

  set<char> cst;
  for (int i = 0; i < t.size(); ++i)
    cst.insert(t[i]);

  for (auto itr = cst.cbegin(); itr != cst.cend(); ++itr) {
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == *itr) {
        for (int j = 0; j <= s.size() - i; ++j) {
          st.insert(s.substr(i, j));
        }
      }
    }
    if (st.size() > K)
      break;
  }
  st.erase("");

  int cnt = 1;
  for (auto itr = st.cbegin(); itr != st.cend(); ++itr) {
    if (cnt == K) {
      cout << *itr << endl;
      break;
    }
    cnt++;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main() {
  string s;
  int K;
  cin >> s >> K;
  string t(s);
  set<string> st;
  sort(t.begin(), t.end());

  set<char> cst;
  for (int i = 0; i < t.size(); ++i)
    cst.insert(t[i]);

  for (auto itr = cst.cbegin(); itr != cst.cend(); ++itr) {
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == *itr) {
        for (int j = 0; j <= s.size() - i && j <= K; ++j) {
          st.insert(s.substr(i, j));
        }
      }
    }
    if (st.size() > K)
      break;
  }
  st.erase("");

  int cnt = 1;
  for (auto itr = st.cbegin(); itr != st.cend(); ++itr) {
    if (cnt == K) {
      cout << *itr << endl;
      break;
    }
    cnt++;
  }

  return 0;
}
Problem p03353 (C++)

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

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28;   // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

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

  int len = s.length();
  vector<string> tmp;
  for (int i = 0; i < len; i++) {
    for (int j = i; j < len; j++) {
      tmp.push_back(s.substr(i, len - j));
    }
  }
  sort(tmp.begin(), tmp.end());
  unique(tmp.begin(), tmp.end());

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


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28;   // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

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

  int len = s.length();
  vector<string> tmp;
  for (int i = 0; i < len; i++) {
    int a = min(k, len - i);
    for (int j = 1; j <= a; j++) {
      tmp.push_back(s.substr(i, j));
    }
  }
  sort(tmp.begin(), tmp.end());
  unique(tmp.begin(), tmp.end());

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

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

using namespace std;

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

  vector<string> list;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j < 5; j++) {
      string q = s.substr(i, j);
      int c = count(list.begin(), list.end(), q);
      if (c == 0) {
        list.push_back(q);
      }
    }
  }
  sort(list.begin(), list.end());
  list.erase(unique(list.begin(), list.end()), list.end());
  cout << list[k - 1] << endl;
}

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

using namespace std;

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

  vector<string> list;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j < 6; j++) {
      string q = s.substr(i, j);
      int c = count(list.begin(), list.end(), q);
      if (c == 0) {
        list.push_back(q);
      }
    }
  }
  sort(list.begin(), list.end());
  list.erase(unique(list.begin(), list.end()), list.end());
  cout << list[k - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> se;
  string s;
  int k;
  cin >> s >> k;
  int m = s.size();
  for (int i = 0; i < m; i++) {
    for (int j = 1; j + i <= m; j++) {
      se.insert(s.substr(i, j));
    }
  }
  auto itr = se.begin();
  for (int i = 0; i < k - 1; i++)
    ++itr;
  cout << *itr << endl;
}

Fixed submission:
#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> se;
  string s;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j + i <= min(i + 5, (int)s.size()); j++) {
      se.insert(s.substr(i, j));
    }
  }
  auto itr = se.begin();
  for (int i = 0; i < k - 1; i++)
    ++itr;
  cout << *itr << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string s, res;
int K;

vector<int> start_with[26];
int main(int argc, char **argv) {
  cin >> s >> K;
  for (int i = 0; i < s.size(); ++i)
    start_with[s[i] - 'a'].push_back(i);

  set<string> substr;
  for (int i = 0; i < 26; ++i) {
    substr.clear();

    for (int j = 0; j < start_with[i].size(); ++j) {
      int pos = start_with[i][j];
      for (int len = 1; len <= s.size() - pos; ++len) {
        substr.insert(s.substr(pos, len));
      }
    }

    if (substr.size() < K)
      K -= substr.size();
    else {
      set<string>::iterator it = substr.begin();
      it = next(it, K - 1);
      res = *it;
      break;
    }
  }

  cout << res << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string s, res;
int K;

vector<int> start_with[26];
int main(int argc, char **argv) {
  cin >> s >> K;
  for (int i = 0; i < s.size(); ++i)
    start_with[s[i] - 'a'].push_back(i);

  set<string> substr;
  for (int i = 0; i < 26; ++i) {
    substr.clear();

    for (int j = 0; j < start_with[i].size(); ++j) {
      int pos = start_with[i][j];
      for (int len = 1; len <= min(100, (int)(s.size() - pos)); ++len) {
        substr.insert(s.substr(pos, len));
      }
    }

    if (substr.size() < K)
      K -= substr.size();
    else {
      set<string>::iterator it = substr.begin();
      it = next(it, K - 1);
      res = *it;
      break;
    }
  }

  cout << res << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed << setprecision(n)
#define mm(o, k) memset(o, k, sizeof o)
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn = 200005;

int main() {
  IO;
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  set<string> st;
  for (int i = 0; i < n; ++i) {
    string tmp;
    for (int j = i; j < n; ++j) {
      tmp.push_back(s[j]);
      st.insert(tmp);
    }
  }
  for (auto i : st) {
    --k;
    if (!k)
      re cout << i, 0;
  }
  re 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed << setprecision(n)
#define mm(o, k) memset(o, k, sizeof o)
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn = 200005;

int main() {
  IO;
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  set<string> st;
  for (int i = 0; i < n; ++i) {
    string tmp;
    int cnt = 0;
    for (int j = i; j < n && cnt < 5; ++j, ++cnt) {
      tmp.push_back(s[j]);
      st.insert(tmp);
    }
  }
  for (auto i : st) {
    --k;
    if (!k)
      re cout << i, 0;
  }
  re 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {

  string s;
  int K;
  cin >> s >> K;

  vector<string> S;

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

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

  cout << S.at(K - 1) << endl;
  return 0;
}


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

using namespace std;

int main() {

  string s;
  int K;
  cin >> s >> K;

  vector<string> S;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      S.push_back(s.substr(i, j));
    }
  }

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

  cout << S.at(K - 1) << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  string s;
  int K;
  set<string> st;
  cin >> s;
  cin >> K;
  string str;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size(); j++) {
      str = s.substr(i, j);
      st.insert(str);
    }
  }

  /*for(auto itr = st.begin(); itr != st.end(); ++itr) {
      std::cout << *itr << endl;      // イテレータの指す先のデータを表示
  }*/

  auto itr = st.begin();

  for (int i = 1; i < K; i++) {
    itr++;
  }

  cout << *itr << endl;

  // cout << s.size() << endl;
  /*std::string str("012345");
  std::string sub = str.substr(2, 3);     //  [2] の位置から3文字切り出す
  std::cout << sub << "\n";   234*/
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  string s;
  int K;
  set<string> st;
  cin >> s;
  cin >> K;
  string str;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= K; j++) {
      str = s.substr(i, j);
      st.insert(str);
    }
  }

  /*for(auto itr = st.begin(); itr != st.end(); ++itr) {
      std::cout << *itr << endl;      // イテレータの指す先のデータを表示
  }*/

  auto itr = st.begin();

  for (int i = 1; i < K; i++) {
    itr++;
  }

  cout << *itr << endl;

  // cout << s.size() << endl;
  /*std::string str("012345");
  std::string sub = str.substr(2, 3);     //  [2] の位置から3文字切り出す
  std::cout << sub << "\n";   234*/
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  string s;
  set<string> sets;
  int K;
  cin >> s >> K;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5 && i + j < s.size(); j++)
      sets.insert(s.substr(i, j));
  }
  vector<string> vecs = vector<string>(sets.begin(), sets.end());
  cout << vecs[K - 1] << endl;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  string s;
  set<string> sets;
  int K;
  cin >> s >> K;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5 && i + j <= s.size(); j++)
      sets.insert(s.substr(i, j));
  }
  vector<string> vecs = vector<string>(sets.begin(), sets.end());
  cout << vecs[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;
  set<string> v;
  for (int i = 1; i <= s.length(); i++) {
    for (int j = 0; j + i - 1 < s.length(); j++)
      v.insert(s.substr(j, i));
  }
  vector<string> vv;
  for (auto i : v)
    vv.push_back(i);
  cout << vv[k - 1];

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> v;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j + i - 1 < s.length(); j++)
      v.insert(s.substr(j, i));
  }
  vector<string> vv;
  for (auto i : v)
    vv.push_back(i);
  cout << vv[k - 1];

  return 0;
}
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;
  int n = s.size();

  set<string> ss;

  for (int i = 0; i < s.size(); i++) {
    int siz = 1;
    while (i + siz < n || siz <= k) {
      ss.insert(s.substr(i, siz));
      siz++;
    }
  }

  auto itr = ss.begin();
  for (int i = 0; i < k - 1; i++)
    itr++;
  cout << *itr << endl;
}

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

int main() {

  string s;
  int k;
  cin >> s >> k;
  int n = s.size();

  set<string> ss;

  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      string tmp = s.substr(i, j);
      ss.insert(tmp);
    }
  }

  auto itr = ss.begin();
  for (int i = 0; i < k - 1; i++)
    itr++;
  cout << *itr << endl;
}
Problem p03353 (C++)

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

#define pb push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

vector<int> ch[28];

int main(void) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);

  string s;
  int K;

  cin >> s;
  cin >> K;

  for (int i = 0; i < s.size(); i++) {
    ch[s[i] - 'a'].pb(i);
  }

  set<string> small;

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < ch[i].size(); j++) {
      for (int k = ch[i][j]; k < s.size(); k++) {
        string cand = s.substr(ch[i][j], k - ch[i][j] + 1);
        // cout << cand << endl;
        // cout << small.size() << endl;
        small.insert(cand);
      }
    }

    if (small.size() >= K) {
      int cnt = 0;
      for (auto it = small.begin(); it != small.end(); it++) {
        cnt++;

        if (cnt == K) {
          cout << *it << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


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

#define pb push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

vector<int> ch[28];

int main(void) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);

  string s;
  int K;

  cin >> s;
  cin >> K;

  for (int i = 0; i < s.size(); i++) {
    ch[s[i] - 'a'].pb(i);
  }

  set<string> small;

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < ch[i].size(); j++) {
      for (int k = ch[i][j]; k < min(ch[i][j] + 5, (int)s.size()); k++) {
        string cand = s.substr(ch[i][j], k - ch[i][j] + 1);
        // cout << cand << endl;
        // cout << small.size() << endl;
        small.insert(cand);
      }
    }

    if (small.size() >= K) {
      int cnt = 0;
      for (auto it = small.begin(); it != small.end(); it++) {
        cnt++;

        if (cnt == K) {
          cout << *it << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}
Problem p03353 (C++)

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

int main() {
  set<string> st;
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  for (int len = 1; len <= n; ++len) {
    for (int i = 0; i + len - 1 < n; i++) {
      st.emplace(s.substr(i, len));
      if (st.size() > k)
        st.erase(--st.end());
    }
  }
  cout << *(--st.end()) << endl;
}

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

int main() {
  set<string> st;
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  for (int len = 1; len <= k; ++len) {
    for (int i = 0; i + len - 1 < n; i++) {
      st.emplace(s.substr(i, len));
      if (st.size() > k)
        st.erase(--st.end());
    }
  }
  cout << *(--st.end()) << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
struct node {
  char s[6];
  friend bool operator<(node a, node b) {
    int i;
    for (i = 0; a.s[i] != '\0' && b.s[i] != '\0'; ++i)
      if (a.s[i] != b.s[i])
        return a.s[i] < b.s[i];
    return a.s[i] < b.s[i];
  }
} s1[300000];
int main(void) {
  char s[5003];
  int k, i, j;
  cin >> s;
  cin >> k;
  int cnt = 0;
  for (i = 0; s[i] != '\0'; ++i) {
    s1[cnt].s[0] = s[i];
    s1[cnt++].s[1] = '\0';
    int q = 1;
    for (j = i + 1; s[j] != '\0' && q <= 5; ++j) {
      strcpy(s1[cnt].s, s1[cnt - 1].s);
      s1[cnt].s[q] = s[j];
      s1[cnt++].s[++q] = '\0';
      // cout << "i=" << i<<"      "<<s1[cnt-1].s << endl;
    }
  }
  sort(s1, s1 + cnt);
  if (k == 1) {
    cout << s1[0].s << endl;
    return 0;
  }
  i = 1;
  int q = 1;
  while (k) {
    if (strcmp(s1[i].s, s1[i - 1].s) != 0) {
      q++;
      if (k == q) {
        cout << s1[i].s << endl;
        return 0;
      }
    }
    i++;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
struct node {
  char s[7];
  friend bool operator<(node a, node b) {
    int i;
    for (i = 0; a.s[i] != '\0' && b.s[i] != '\0'; ++i)
      if (a.s[i] != b.s[i])
        return a.s[i] < b.s[i];
    return a.s[i] < b.s[i];
  }
} s1[300000];
int main(void) {
  char s[5003];
  int k, i, j;
  cin >> s;
  cin >> k;
  int cnt = 0;
  for (i = 0; s[i] != '\0'; ++i) {
    s1[cnt].s[0] = s[i];
    s1[cnt++].s[1] = '\0';
    int q = 1;
    for (j = i + 1; s[j] != '\0' && q <= 5; ++j) {
      strcpy(s1[cnt].s, s1[cnt - 1].s);
      s1[cnt].s[q] = s[j];
      s1[cnt++].s[++q] = '\0';
      // cout << "i=" << i<<"      "<<s1[cnt-1].s << endl;
    }
  }
  sort(s1, s1 + cnt);
  if (k == 1) {
    cout << s1[0].s << endl;
    return 0;
  }
  i = 1;
  int q = 1;
  while (k) {
    if (strcmp(s1[i].s, s1[i - 1].s) != 0) {
      q++;
      if (k == q) {
        cout << s1[i].s << endl;
        return 0;
      }
    }
    i++;
  }
  return 0;
}
Problem p03353 (C++)

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

using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
// #pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2019/03/04  Problem: ABC 097 C / Link:
 * http://abc097.contest.atcoder.jp/tasks/abc097_c  ----- */

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

  string s;
  cin >> s;
  LL K;
  cin >> K;
  VS a;
  FOR(i, 0, SZ(s)) {
    string t = "";
    FOR(j, 0, SZ(s) + 1) {
      int k = i + j;
      if (k < SZ(s)) {
        t += s[k];
        a.push_back(t);
      }
    }
  }
  SORT(a);
  UNIQ(a);
  string ans = a[K - 1];

  cout << (ans) << "\n";

  return 0;
}


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

using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
// #pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2019/03/04  Problem: ABC 097 C / Link:
 * http://abc097.contest.atcoder.jp/tasks/abc097_c  ----- */

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

  string s;
  cin >> s;
  LL K;
  cin >> K;
  VS a;
  FOR(i, 0, SZ(s)) {
    string t = "";
    FOR(j, 0, K + 1) {
      int k = i + j;
      if (k < SZ(s)) {
        t += s[k];
        a.push_back(t);
      }
    }
  }
  SORT(a);
  UNIQ(a);
  string ans = a[K - 1];

  cout << (ans) << "\n";

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define coutdb fixed

#define MOD 1000000007

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int dx_8[] = {1, 1, 0, -1, -1, -1, 0, 1},
          dy_8[] = {0, -1, -1, -1, 0, 1, 1, 1};

typedef long long ll;

template <typename T> inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T> inline T LCM(T a, T b) {
  T c = GCD(a, b);
  a /= c;
  return a * b;
}
template <typename T> inline T nCr(T a, T b) {
  T i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= (a + 1 - i);
    r /= i;
  }
  return r;
}
template <typename T> inline T nHr(T a, T b) { return nCr(a + b - 1, b); }
template <typename T> inline T POW(T a, T b) {
  int i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= a;
  }
  return r;
}

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

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

  cin >> s >> k;

  REP(i, s.size()) {
    REP(j, s.size() - i + 1) {
      string t = s.substr(i, j);
      st.insert(t);
    }
  }

  auto itr = st.begin();
  while (k != 0) {
    itr++;
    k--;
  }
  cout << *itr << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define coutdb fixed

#define MOD 1000000007

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int dx_8[] = {1, 1, 0, -1, -1, -1, 0, 1},
          dy_8[] = {0, -1, -1, -1, 0, 1, 1, 1};

typedef long long ll;

template <typename T> inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T> inline T LCM(T a, T b) {
  T c = GCD(a, b);
  a /= c;
  return a * b;
}
template <typename T> inline T nCr(T a, T b) {
  T i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= (a + 1 - i);
    r /= i;
  }
  return r;
}
template <typename T> inline T nHr(T a, T b) { return nCr(a + b - 1, b); }
template <typename T> inline T POW(T a, T b) {
  int i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= a;
  }
  return r;
}

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

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

  cin >> s >> k;

  REP(i, s.size()) {
    REP(j, k + 1) {
      string t = s.substr(i, j);
      st.insert(t);
    }
  }

  auto itr = st.begin();
  while (k != 0) {
    itr++;
    k--;
  }
  cout << *itr << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):

// C - K-th Substring

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  int K;
  cin >> K;

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

  auto itr = substr_list.begin();
  for (int i = 1; i < K; i++) {
    itr++;
  }

  string ans = *itr;

  cout << ans << endl;

  return 0;
}

Fixed submission:

// C - K-th Substring

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  int K;
  cin >> K;

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

  auto itr = substr_list.begin();
  for (int i = 1; i < K; i++) {
    itr++;
  }

  string ans = *itr;

  cout << ans << endl;

  return 0;
}
Problem p03353 (C++)

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

template <typename T> void printmatrix(vector<vector<T>> ar) {
  for (int i = 0; i < (int)ar.size(); i++) {
    for (int j = 0; j < (int)ar.size(); j++) {
      cout << ar[i][j];
    }
    cout << endl;
  }
}

template <typename T> void printvector(vector<T> vec) {
  for (int i = 0; i < (int)vec.size(); i++) {
    cout << vec[i] << endl;
  }
}

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;

  int k;
  cin >> k;

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

  // printvector(strs);

  sort(strs.begin(), strs.end());
  strs.erase(unique(strs.begin(), strs.end()), strs.end());
  // printvector(strs);

  cout << strs[k - 1] << endl;

  return 0;
}


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

template <typename T> void printmatrix(vector<vector<T>> ar) {
  for (int i = 0; i < (int)ar.size(); i++) {
    for (int j = 0; j < (int)ar.size(); j++) {
      cout << ar[i][j];
    }
    cout << endl;
  }
}

template <typename T> void printvector(vector<T> vec) {
  for (int i = 0; i < (int)vec.size(); i++) {
    cout << vec[i] << endl;
  }
}

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;

  int k;
  cin >> k;

  vector<string> strs;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      strs.push_back(s.substr(i, j));
    }
  }

  // printvector(strs);

  sort(strs.begin(), strs.end());
  strs.erase(unique(strs.begin(), strs.end()), strs.end());
  // printvector(strs);

  cout << strs[k - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

const int MOD = 1000000007;

// long long
using ll = long long;

// 出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

// begin() end()
#define all(x) (x).begin(), (x).end()

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

// 最大公約数
unsigned gcd(unsigned a, unsigned b) {
  if (a < b)
    return gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

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

  set<string> C;
  REP(i, S.size()) {
    string now = "";
    for (int j = 1; j <= K || j < S.size(); j++) {
      now = S.substr(i, j);
      C.insert(now);
    }
  }

  int cnt = 0;
  for (auto i : C) {
    cnt++;
    if (cnt == K)
      cout << i << endl;
  }
}

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

const int MOD = 1000000007;

// long long
using ll = long long;

// 出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

// begin() end()
#define all(x) (x).begin(), (x).end()

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

// 最大公約数
unsigned gcd(unsigned a, unsigned b) {
  if (a < b)
    return gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

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

  set<string> C;
  REP(i, S.size()) {
    string now = "";
    for (int j = 1; j <= K; j++) {
      now = S.substr(i, j);
      C.insert(now);
    }
  }

  int cnt = 0;
  for (auto i : C) {
    cnt++;
    if (cnt == K)
      cout << i << endl;
  }
}
Problem p03353 (C++)

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> tmp;

  for (int i = 1; i <= int(s.size()); i++) {
    for (int j = 0; j < int(s.size()); j++) {
      if (i + j > int(s.size()))
        break;
      tmp.insert(s.substr(j, i));
    }
  }
  int i = 1;
  for (auto x : tmp) {
    if (i == k)
      cout << x << endl;
    i++;
  }

  return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> tmp;

  for (int i = 1; i <= int(s.size()); i++) {
    for (int j = 0; j < int(s.size()) && i <= k; j++) {
      if (i + j > int(s.size()))
        break;
      tmp.insert(s.substr(j, i));
    }
  }
  int i = 1;
  for (auto x : tmp) {
    if (i == k)
      cout << x << endl;
    i++;
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <tuple>
#include <vector>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i, n) for (long long i = 0; i < n; i++)
#define rep2(i, a, n) for (long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

  rep(i, s.size()) {
    string t = s.substr(i, s.size() - i);
    rep(j, t.size() + 1) {
      string sub = t.substr(0, j);
      if (sub.size() > K) {
        break;
      }
      if (sub != "ac" && sub != "z" && sub != "") {
        auto s = find(ans.begin(), ans.end(), sub);
        if (s == ans.end()) {
          ans.push_back(sub);
        }
      }
    }
  }

  sort(ans.begin(), ans.end());
  // for(auto v : ans) { cout << v << endl; }
  cout << ans[K - 1] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <tuple>
#include <vector>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i, n) for (long long i = 0; i < n; i++)
#define rep2(i, a, n) for (long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

  rep(i, s.size()) {
    string t = s.substr(i, s.size() - i);
    rep(j, t.size() + 1) {
      string sub = t.substr(0, j);
      if (sub.size() > K) {
        break;
      }
      if (sub != "") {
        auto s = find(ans.begin(), ans.end(), sub);
        if (s == ans.end()) {
          ans.push_back(sub);
        }
      }
    }
  }

  sort(ans.begin(), ans.end());
  // for(auto v : ans) { cout << v << endl; }
  cout << ans[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  string s;
  int K;
  cin >> s;
  cin >> K;
  vector<string> vec;
  for (int i = 0; i < s.size(); i++) {
    // start
    for (int j = 1; j <= K; j++) {
      // length
      string tmp = s.substr(i, j);
      vec.push_back(tmp);
    }
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  // ゴミの手前から最後までを消す
  cout << vec[K - 1] << endl;

  // REP(i, K + 1) { cout << res[i] << endl; }
  cout << vec[K] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  string s;
  int K;
  cin >> s;
  cin >> K;
  vector<string> vec;
  for (int i = 0; i < s.size(); i++) {
    // start
    for (int j = 1; j <= K; j++) {
      // length
      string tmp = s.substr(i, j);
      vec.push_back(tmp);
    }
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  // ゴミの手前から最後までを消す
  cout << vec[K - 1] << endl;
}
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;

  vector<string> words;
  for (auto litr = begin(s); litr != end(s); litr++) {
    for (auto ritr = litr + 1; ritr != end(s) + 1; ritr++) {
      words.push_back(string(litr, ritr));
    }
  }

  sort(begin(words), end(words));
  unique(begin(words), end(words));
  words.shrink_to_fit();

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


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

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

  vector<string> words;
  for (auto litr = begin(s); litr != end(s); litr++) {
    for (auto ritr = litr + 1; ritr != min(litr + 5, end(s)) + 1; ritr++) {
      words.push_back(string(litr, ritr));
    }
  }

  sort(begin(words), end(words));
  unique(begin(words), end(words));
  words.shrink_to_fit();

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

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

typedef long long ll;
#define mfor(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) mfor(i, 0, n)
#define all(x) (x).begin(), (x).end()

bool comp(const vector<int> &x, const vector<int> &y) { return x[2] > y[2]; }

int main(void) {

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

  vector<string> ss;
  rep(i, s.length()) {
    mfor(j, 1, s.length() - i + 1) { ss.push_back(s.substr(i, j)); }
  }

  sort(all(ss));
  ss.erase(unique(all(ss)), ss.end());

  //    rep(i, ss.size()){
  //        cout << ss[i] << endl;
  //    }

  cout << ss[k - 1] << endl;

  return 0;
}

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

typedef long long ll;
#define mfor(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) mfor(i, 0, n)
#define all(x) (x).begin(), (x).end()

bool comp(const vector<int> &x, const vector<int> &y) { return x[2] > y[2]; }

int main(void) {

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

  vector<string> ss;
  rep(i, s.length()) {
    mfor(j, 1, 6) { ss.push_back(s.substr(i, j)); }
  }

  sort(all(ss));
  ss.erase(unique(all(ss)), ss.end());

  //    rep(i, ss.size()){
  //        cout << ss[i] << endl;
  //    }

  cout << ss[k - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

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

  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> t;
  for (int i = 0; i < s.size(); i++) {
    string tmp = "";
    for (int j = i; j < s.size(); j++) {
      tmp += s[j];
      t.insert(tmp);
    }
  }
  int cnt = 1;
  for (auto i = t.begin(); i != t.end(); i++) {
    if (cnt == k) {
      cout << *i << endl;
      return 0;
    }
    cnt++;
  }
  return 0;
}


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

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

  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> t;
  for (int i = 0; i < s.size(); i++) {
    string tmp = "";
    for (int j = i; j < s.size() && j < i + 5; j++) {
      tmp += s[j];
      t.insert(tmp);
    }
  }
  int cnt = 1;
  for (auto i = t.begin(); i != t.end(); i++) {
    if (cnt == k) {
      cout << *i << endl;
      return 0;
    }
    cnt++;
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define rREP(i, m, n) for (int(i) = (n)-1; (i) >= (m); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> st;
  rep(i, 0, (int)s.size()) {
    rep(j, 1, (int)s.size() + 1 - i) { st.insert(s.substr(i, j)); }
  }
  vector<string> str;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    str.push_back(*itr);
  }
  sort(all(str));
  cout << str[K - 1] << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define rREP(i, m, n) for (int(i) = (n)-1; (i) >= (m); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> st;
  rep(i, 0, (int)s.size()) {
    rep(j, 1, K + 1) { st.insert(s.substr(i, j)); }
  }
  vector<string> str;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    str.push_back(*itr);
  }
  sort(all(str));
  cout << str[K - 1] << "\n";

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divCeil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A)                                                            \
  {                                                                            \
    cout << (A) << endl;                                                       \
    exit(0);                                                                   \
  }

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

  set<string> S;
  for (ll i = 0; i < N; i++) {
    for (ll j = i; j < N; j++) {
      string t = T.substr(i, j - i + 1);
      S.emplace(t);
    }
  }

  auto itr = S.begin();
  for (ll i = 0; i < K - 1; i++) {
    itr++;
  }
  string ans = *itr;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divCeil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A)                                                            \
  {                                                                            \
    cout << (A) << endl;                                                       \
    exit(0);                                                                   \
  }

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

  set<string> S;
  for (ll i = 0; i < N; i++) {
    for (ll j = i; j < N; j++) {
      if (j - i + 1 > K)
        continue;
      string t = T.substr(i, j - i + 1);
      S.emplace(t);
    }
  }

  auto itr = S.begin();
  for (ll i = 0; i < K - 1; i++) {
    itr++;
  }
  string ans = *itr;
  cout << ans << endl;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, tmp;
  int k;
  cin >> s >> k;
  tmp = s;
  sort(tmp.begin(), tmp.end());
  int cnt = 0;
  map<string, int> mp;
  for (int k2 = 0; k2 < tmp.length(); k2++) {
    vector<string> store;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == tmp[k2]) {
        string a;
        for (int j = i; j < s.length(); j++) {
          a += s[j];
          if (!mp[a]) {
            mp[a]++;
            store.push_back(a);
          }
        }
      }
    }
    sort(store.begin(), store.end());
    if (store.size() >= k) {
      cout << store[k - 1] << endl;
      return 0;
    } else
      k -= store.size();
  }
  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, tmp;
  int k;
  cin >> s >> k;
  tmp = s;
  sort(tmp.begin(), tmp.end());
  int cnt = 0;
  map<string, int> mp;
  for (int k2 = 0; k2 < tmp.length(); k2++) {
    vector<string> store;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == tmp[k2]) {
        string a;
        for (int j = i; j < s.length() && j < i + 7; j++) {
          a += s[j];
          if (!mp[a]) {
            mp[a]++;
            store.push_back(a);
          }
        }
      }
    }
    sort(store.begin(), store.end());
    if (store.size() >= k) {
      cout << store[k - 1] << endl;
      return 0;
    } else
      k -= store.size();
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> substring;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k or i + j <= s.size(); j++) {
      substring.push_back(s.substr(i, j));
    }
  }
  sort(substring.begin(), substring.end());
  substring.erase(unique(substring.begin(), substring.end()), substring.end());
  cout << substring.at(k - 1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> substring;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k and i + j <= s.size(); j++) {
      substring.push_back(s.substr(i, j));
    }
  }
  sort(substring.begin(), substring.end());
  substring.erase(unique(substring.begin(), substring.end()), substring.end());
  cout << substring.at(k - 1) << endl;
}