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

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

int main() {
  string s;
  int K;

  cin >> s;
  cin >> K;

  set<string> substrs;
  for (string::size_type i = 0; i < s.size(); ++i) {
    for (string::size_type l = 1; i + l <= s.size(); ++l) {
      substrs.emplace(s.substr(i, l));
    }
  }

  cout << *(next(begin(substrs), K - 1)) << endl;
}


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

int main() {
  string s;
  int K;

  cin >> s;
  cin >> K;

  set<string> substrs;
  for (string::size_type i = 0; i < s.size(); ++i) {
    for (string::size_type l = 1; l <= K; ++l) {
      substrs.emplace(s.substr(i, l));
    }
  }

  cout << *(next(begin(substrs), K - 1)) << endl;
}
Problem p03353 (C++)

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> vec;
  for (int i = 1; i <= s.size(); i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      vec.push_back(s.substr(j, i));
    }
  }
  sort(vec.begin(), vec.end());
  int l = 0;
  while (l < vec.size() - 1) {
    if (vec[l] == vec[l + 1]) {
      vec.erase(vec.begin() + l);
      continue;
    }
    l++;
  }
  cout << vec[k - 1] << endl;
  return 0;
}

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> vec;
  int size = s.size();
  for (int i = 1; i <= min(k, size); i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      vec.push_back(s.substr(j, i));
    }
  }
  sort(vec.begin(), vec.end());
  int l = 0;
  while (l < vec.size() - 1) {
    if (vec[l] == vec[l + 1]) {
      vec.erase(vec.begin() + l);
      continue;
    }
    l++;
  }
  cout << vec[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max() / 4;
const ll MOD = 1e9 + 7;
const int n_max = 1e5 + 10;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  vector<vector<ll>> table(26);
  set<string> ret;
  ll n = s.size();
  rep(i, s.size()) {
    ll t = s[i] - 'a';
    table[t].emplace_back(i);
  }
  ll cnt = 0, ind = 0;
  while (cnt < k) {
    for (auto i : table[ind]) {
      rep(j, n - i) ret.insert(s.substr(i, j + 1));
    }
    cnt = ret.size();
    ind++;
  }
  // string r;
  auto itr = ret.begin();
  rep(i, k - 1) itr++;
  cout << *itr << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max() / 4;
const ll MOD = 1e9 + 7;
const int n_max = 1e5 + 10;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  vector<vector<ll>> table(26);
  set<string> ret;
  ll n = s.size();
  rep(i, s.size()) {
    ll t = s[i] - 'a';
    table[t].emplace_back(i);
  }
  ll cnt = 0, ind = 0;
  while (cnt < k) {
    for (auto i : table[ind]) {
      rep(j, k) ret.insert(s.substr(i, j + 1));
    }
    cnt = ret.size();
    ind++;
  }
  // string r;
  auto itr = ret.begin();
  rep(i, k - 1) itr++;
  cout << *itr << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// ミョ(-ω- ?)
int main() {
  map<string, int> m;
  string s;
  ll k;
  cin >> s >> k;
  const ll n = s.length();
  for (ll i = 0; i < n; i++) {
    for (ll j = 1; j <= n; j++) {
      ll len = j;
      if (i + j > n)
        len = s.length() - 1;
      m[s.substr(i, len)]++;
    }
  }
  ll cnt = 1;
  for (auto a : m) {
    if (cnt == k) {
      cout << a.first << "\n";
      return 0;
    } else
      cnt++;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// ミョ(-ω- ?)
int main() {
  map<string, int> m;
  string s;
  ll k;
  cin >> s >> k;
  const ll n = s.length();
  for (ll i = 0; i < n; i++) {
    for (ll j = 1; j <= n; j++) {
      ll len = j;
      if (i + j > n)
        len = s.length() - 1;
      if (len > k)
        continue;
      m[s.substr(i, len)]++;
    }
  }
  ll cnt = 1;
  for (auto a : m) {
    if (cnt == k) {
      cout << a.first << "\n";
      return 0;
    } else
      cnt++;
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  int len = s.size();
  vector<string> sub;
  for (int i = 0; i < len; i++) {
    for (int j = 1; j <= len - i; j++) {
      sub.push_back(s.substr(i, j));
    }
  }
  set<string> subset(sub.begin(), sub.end());
  vector<string> sortedSub(subset.begin(), subset.end());
  cout << sortedSub[k - 1] << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  int len = s.size();
  vector<string> sub;
  for (int i = 0; i < len; i++) {
    for (int j = 1; j <= len - i; j++) {
      string subs = s.substr(i, j);
      if (subs.size() <= k) {
        sub.push_back(subs);
      }
    }
  }
  set<string> subset(sub.begin(), sub.end());
  vector<string> sortedSub(subset.begin(), subset.end());
  cout << sortedSub[k - 1] << endl;
}
Problem p03353 (C++)

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

using namespace std;
int main() {
  vector<string> v;

  string s;
  int K;

  cin >> s >> K;

  for (int i = 0; i < s.size(); i++) {
    string cur;
    for (int j = 0; j < s.size() && j < i + K; j++) {
      cur = s.substr(i, j + 1);
      v.push_back(cur);
    }
  }

  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

  cout << v[K - 1];

  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
int main() {
  vector<string> v;

  string s;
  int K;

  cin >> s >> K;

  for (int i = 0; i < s.size(); i++) {
    string cur;
    for (int j = 0; j < K; j++) {
      cur = s.substr(i, j + 1);
      v.push_back(cur);
    }
  }

  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

  cout << v[K - 1];

  return 0;
}
Problem p03353 (C++)

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

long long gcd(long long aaa, long long bbb) {
  if (bbb == 0) {
    return aaa;
  }
  return gcd(bbb, aaa % bbb);
}

int main() {

  string s, tmp[25000000], tmpp;
  ll K, count = 0, countt = 0;
  map<string, ll> m;
  cin >> s >> K;
  ll tmppp = s.size();
  tmppp = max(tmppp, K);
  for (int i = tmppp; i >= 1; i--) {
    for (int j = 0; j <= s.size() - i; j++) {
      tmpp = s.substr(j, i);
      m[tmpp]++;
      if (m[tmpp] == 1) {
        tmp[count] = s.substr(j, i);
        count++;
      }
    }
  }
  sort(tmp, tmp + count);
  cout << tmp[K - 1] << endl;

  return 0;
}


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

long long gcd(long long aaa, long long bbb) {
  if (bbb == 0) {
    return aaa;
  }
  return gcd(bbb, aaa % bbb);
}

int main() {

  string s, tmp[25000000], tmpp;
  ll K, count = 0, countt = 0;
  map<string, ll> m;
  cin >> s >> K;
  ll tmppp = s.size();
  tmppp = min(tmppp, K);
  for (int i = 1; i <= tmppp; i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      tmpp = s.substr(j, i);
      m[tmpp]++;
      if (m[tmpp] == 1) {
        tmp[count] = s.substr(j, i);
        count++;
      }
    }
  }
  sort(tmp, tmp + count);
  cout << tmp[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

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

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

  int n = s.length();
  set<string> small;
  for (int i = 0; i < n; i++) {
    for (int p = 1; p <= n - i; p++) {
      small.insert(s.substr(i, p));
    }
  }

  auto it = small.begin();
  for (int i = 1; i < k; i++)
    it++;
  cout << (*it) << endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

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

  int n = s.length();
  set<string> small;
  for (int i = 0; i < n; i++) {
    for (int p = 1; p <= min(k, n - i); p++) {
      small.insert(s.substr(i, p));
    }
  }

  auto it = small.begin();
  for (int i = 1; i < k; i++)
    it++;
  cout << (*it) << endl;
}
Problem p03353 (C++)

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

#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define rep2(i, j, n) for (int i = (j); i <= (n); i++)
#define all(i) i.begin(), i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  rep(i, 0, s.size()) {
    string a;
    a = s[i];
    st.insert(a);
    rep(j, i + 1, s.size()) {
      a += s[j];
      st.insert(a);
    }
  }
  auto ite = st.begin();
  rep(i, 1, k) { ite++; }
  cout << *ite << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define rep2(i, j, n) for (int i = (j); i <= (n); i++)
#define all(i) i.begin(), i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  rep(i, 0, s.size()) {
    string a;
    a = s[i];
    st.insert(a);
    rep(j, 1, 6) {
      if (i + j >= s.size()) {
        break;
      }
      a += s[i + j];
      st.insert(a);
    }
  }
  auto ite = st.begin();
  rep(i, 1, k) { ite++; }
  cout << *ite << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
/* ****TCIITB**** */

#include <bits/stdc++.h>
#define io                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll int long long
#define pb push_back
#define endl '\n'
#define piil pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair

using namespace std;

ll expo(ll base, ll exponent, ll mod) { // return base^exponent modulo modulus
  ll ans = 1;
  while (exponent != 0) {
    if ((exponent & 1) == 1) {
      ans = ans * base;
    }
    base = base * base;

    exponent >>= 1;
  }
  return ans;
}
int main() {
  ll t;
  t = 1;
  while (t--) {
    string x;
    cin >> x;
    ll k;
    cin >> k;
    std::vector<string> a;
    std::map<string, ll> aa;
    rep(i, 0, x.length()) {
      string z = "";
      rep(j, i, x.length()) {
        z += x[j];
        if (aa.find(z) != aa.end()) {
          continue;
        } else {
          aa[z] = 1;
          a.push_back(z);
        }
      }
    }

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


Fixed submission:
/* ****TCIITB**** */

#include <bits/stdc++.h>
#define io                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll int long long
#define pb push_back
#define endl '\n'
#define piil pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair

using namespace std;

ll expo(ll base, ll exponent, ll mod) { // return base^exponent modulo modulus
  ll ans = 1;
  while (exponent != 0) {
    if ((exponent & 1) == 1) {
      ans = ans * base;
    }
    base = base * base;

    exponent >>= 1;
  }
  return ans;
}
int main() {
  ll t;
  t = 1;
  while (t--) {
    string x;
    cin >> x;
    ll k;
    cin >> k;
    std::vector<string> a;
    std::map<string, ll> aa;
    rep(i, 0, x.length()) {
      string z = "";
      for (ll j = i; j < x.length() && j <= i + k + 1; j++) {
        z += x[j];
        if (aa.find(z) != aa.end()) {
          continue;
        } else {
          aa[z] = 1;
          a.push_back(z);
        }
      }
    }

    sort(a.begin(), a.end());
    cout << a[k - 1];
  }
}
Problem p03353 (C++)

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

#define INF 1e18
#define REP(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = " << x << endl

const double PI =
    3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  map<string, int> m;
  for (int i = 1; i < S.length() + 1; i++) {
    for (int j = 0; j < S.length() - i + 1; j++) {
      string sub = S.substr(j, i);
      m[sub] = 1;
    }
  }
  int cnt = 0;
  for (auto item : m) {
    cnt++;
    if (cnt == K) {
      print(item.first);
      break;
    }
  }
}

signed main() { solve(); }


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

#define INF 1e18
#define REP(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = " << x << endl

const double PI =
    3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  map<string, int> m;
  for (int i = 1; i < S.length() + 1; i++) {
    if (S.length() > 50 && i > 10) {
      break;
    }
    for (int j = 0; j < S.length() - i + 1; j++) {
      string sub = S.substr(j, i);
      m[sub] = 1;
    }
  }
  int cnt = 0;
  for (auto item : m) {
    cnt++;
    if (cnt == K) {
      print(item.first);
      break;
    }
  }
}

signed main() { solve(); }
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  string s;
  cin >> s;
  ll K;
  cin >> K;
  map<string, ll> subs;
  for (ll i = 0; i < s.size(); i++) {
    for (ll l = 1; l <= s.size() - i; l++) {
      // cerr << s.substr(i, l) << endl;
      subs[s.substr(i, l)]++;
    }
  }
  string kth;
  ll count = 0;
  for (auto itr : subs) {
    count++;
    if (count == K)
      kth = itr.first;
  }
  cout << kth << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  string s;
  cin >> s;
  ll K;
  cin >> K;
  map<string, ll> subs;
  for (ll i = 0; i < s.size(); i++) {
    // for(ll l=1; l<=s.size()-i;l++)
    for (ll l = 1; l <= K; l++) {
      // cerr << s.substr(i, l) << endl;
      subs[s.substr(i, l)]++;
    }
  }
  string kth;
  ll count = 0;
  for (auto itr : subs) {
    count++;
    if (count == K)
      kth = itr.first;
  }
  cout << kth << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#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, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  set<string> strs;
  for (int i = 0; i < N; i++) {
    string s = "";
    for (int j = i; j < N; j++) {
      s += S[j];
      strs.insert(s);
    }
  }
  auto it = strs.begin();
  rep(i, K - 1) it++;
  cout << *it << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#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, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  set<string> strs;
  for (int i = 0; i < N; i++) {
    string s = "";
    for (int j = i; j < N; j++) {
      s += S[j];
      strs.insert(s);
      if (s.size() == 5)
        break;
    }
  }
  auto it = strs.begin();
  rep(i, K - 1) it++;
  cout << *it << endl;
  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  string s;
  int k, n;
  map<string, int> mp;

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

  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n; j++) {
      mp[s.substr(i, j)] = 1;
    }
  }

  int kk = 0;
  string ans;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans = it->first;
    kk++;
    if (kk == k)
      break;
  }

  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  string s;
  int k, n;
  map<string, int> mp;

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

  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= 5; j++) {
      mp[s.substr(i, j)] = 1;
    }
  }

  int kk = 0;
  string ans;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans = it->first;
    kk++;
    if (kk == k)
      break;
  }

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

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

int main() {

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

  std::string s;
  std::cin >> s;

  int k;
  std::cin >> k;

  std::vector<std::string> v;

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

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

  std::cout << v[k - 1];

  return 0;
}

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

int main() {

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

  std::string s;
  std::cin >> s;

  int k;
  std::cin >> k;

  std::vector<std::string> v;

  for (int i = 0; i < s.size(); ++i) {
    for (int len = 1; len <= s.size() - i; ++len) {
      std::string news = s.substr(i, len);
      if (news.size() <= k)
        v.push_back(news);
    }
  }

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

  std::cout << v[k - 1];

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

set<string> S;
string s;
int k;
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      S.insert(s.substr(i, j - i + 1));
    }
  }
  int cnt = 1;
  for (auto &x : S) {
    if (cnt == k) {
      cout << x << endl;
      break;
    }
    cnt++;
  }
}

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

using namespace std;

set<string> S;
string s;
int k;
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      S.insert(s.substr(i, j));
    }
  }
  int cnt = 1;
  for (auto &x : S) {
    if (cnt == k) {
      cout << x << endl;
      break;
    }
    cnt++;
  }
}
Problem p03353 (C++)

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

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

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

  int i = 1;
  for (auto sub : subs) {
    if (i == k) {
      cout << sub << endl;
      break;
    }
    i++;
  }

  return 0;
}


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

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

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

  int i = 1;
  for (auto sub : subs) {
    if (i == k) {
      cout << sub << endl;
      break;
    }
    i++;
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;

int main() {
  int count = 0;
  string s;
  int k;
  cin >> s >> k;
  string t;
  t += s;
  string x[100000];
  int c = 0;
  sort(t.begin(), t.end());
  rep(i, s.size()) {
    rep(k, 5) {

      if (s[i] == t[k]) {
        rep(j, 5) {
          if (i + j <= s.size() - 1)
            x[c] += s[i + j];
        }
        c++;
      }
    }
  }
  sort(x, x + c);
  int d = 0;
  string p[100000];
  rep(i, c) {
    rep(j, x[i].size()) {
      p[d] += x[i].substr(0, j + 1);
      d++;
    }
  }
  sort(p, p + d);
  rep(i, d) {
    if (p[i + 1] != p[i])
      count++;
    if (count == k) {
      cout << p[i] << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;

int main() {
  int count = 0;
  string s;
  int k;
  cin >> s >> k;
  string t;
  t += s;
  string x[100000];
  int c = 0;
  sort(t.begin(), t.end());
  rep(i, s.size()) {
    rep(k, 5) {

      if (s[i] == t[k]) {
        rep(j, 5 - k) {
          if (i + j <= s.size() - 1)
            x[c] += s[i + j];
        }
        c++;
      }
    }
  }
  sort(x, x + c);
  int d = 0;
  string p[100000];
  rep(i, c) {
    rep(j, x[i].size()) {
      p[d] += x[i].substr(0, j + 1);
      d++;
    }
  }
  sort(p, p + d);
  rep(i, d) {
    if (p[i + 1] != p[i])
      count++;
    if (count == k) {
      cout << p[i] << endl;
      break;
    }
  }
  return 0;
}
Problem p03353 (C++)

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

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

  cout << *begin(ans) << endl;

  return 0;
}


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

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

  cout << *begin(ans) << endl;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

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

  vec.erase(unique(vec.begin(), vec.end()), vec.end());

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

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

using namespace std;

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

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

  vec.erase(unique(vec.begin(), vec.end()), vec.end());

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

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

using namespace std;

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  // int count = 0;
  for (int i = 1; i <= int(s.size()); i++) {
    for (int j = 0; j < int(s.size()); j++) {
      v.push_back(s.substr(j, i));
    }
  }
  set<string> tmp(v.begin(), v.end());
  vector<string> v2(tmp.begin(), tmp.end());
  sort(v2.begin(), v2.end());
  // for(string a : v2) cout << a << endl;
  cout << v2[k - 1] << endl;
  return 0;
}


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

using namespace std;

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  // int count = 0;
  for (int i = 1; i <= 5; i++) {
    for (int j = 0; j < int(s.size()); j++) {
      v.push_back(s.substr(j, i));
    }
  }
  set<string> tmp(v.begin(), v.end());
  vector<string> v2(tmp.begin(), tmp.end());
  sort(v2.begin(), v2.end());
  // for(string a : v2) cout << a << endl;
  cout << v2[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 <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, a) repi(i, 0, a)
#define all(u) u.begin(), u.end()
#define pl pair<ll, ll>
#define fi first
#define se second
#define inf 1000000007

string s;
ll K;
vector<string> S;
set<string> st;

int main() {
  cin >> s;
  cin >> K;
  rep(i, s.size()) {
    ll len = 1;
    while (i + len - 1 < s.size() || len <= K) {
      string sub = s.substr(i, len);
      st.insert(sub);
      len++;
    }
  }
  for (auto i = st.begin(); i != st.end(); i++) {
    S.push_back(*i);
  }
  sort(S.begin(), S.end());
  cout << S[K - 1] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, a) repi(i, 0, a)
#define all(u) u.begin(), u.end()
#define pl pair<ll, ll>
#define fi first
#define se second
#define inf 1000000007

string s;
ll K;
vector<string> S;
set<string> st;

int main() {
  cin >> s;
  cin >> K;
  rep(i, s.size()) {
    ll len = 1;
    while (i + len - 1 < s.size() && len <= K) {
      string sub = s.substr(i, len);
      st.insert(sub);
      len++;
    }
  }
  for (auto i = st.begin(); i != st.end(); i++) {
    S.push_back(*i);
  }
  sort(S.begin(), S.end());
  cout << S[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  cin >> s;
  int m;
  cin >> m;
  vector<char> T;
  vector<string> U;
  int n = s.size();
  map<char, int> mp;
  map<string, int> mp2;
  rep(i, n) mp[s[i]]++;
  int ans = 0;
  for (auto p : mp) {
    int q = p.second;
    if (q > 0) {
      T.push_back(p.first);
      ans++;
    }
  }
  // rep(i,ans) cout << T[i] << endl ;
  ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n + 1; j++) {
      // cout << s.substr(0,3) << endl;
      mp2[s.substr(i, j)]++;
    }
  }
  for (auto p : mp2) {
    int q = p.second;
    if (q > 0) {
      U.push_back(p.first);
      ans++;
    }
  }
  cout << U[m - 1] << endl;
}

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

int main() {
  string s;
  cin >> s;
  int m;
  cin >> m;
  vector<char> T;
  vector<string> U;
  int n = s.size();
  map<char, int> mp;
  map<string, int> mp2;
  rep(i, n) mp[s[i]]++;
  int ans = 0;
  for (auto p : mp) {
    int q = p.second;
    if (q > 0) {
      T.push_back(p.first);
      ans++;
    }
  }
  // rep(i,ans) cout << T[i] << endl ;
  ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 6; j++) {
      // cout << s.substr(0,3) << endl;
      mp2[s.substr(i, j)]++;
    }
  }
  for (auto p : mp2) {
    int q = p.second;
    if (q > 0) {
      U.push_back(p.first);
      ans++;
    }
  }
  cout << U[m - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long l;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
const int INF = 1000000001;
const double PI = 3.141592653589;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  rep(i, s.size()) {
    for (int j = i; j < s.size(); j++) {
      string c = s.substr(i, (j + 1) - i);
      se.insert(c);
    }
  }

  // vector<string> vs;
  int C = 0;
  for (auto itr = se.begin(); itr != se.end(); itr++) {
    C++;
    if (C == k)
      cout << *itr << endl;
  }

  // sort(vs.begin(),vs.end());
  // cout<<vs[k-1]<<endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long l;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
const int INF = 1000000001;
const double PI = 3.141592653589;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  rep(i, s.size()) {
    for (int j = i; j < s.size(); j++) {
      if ((j + 1) - i > 5)
        continue;
      string c = s.substr(i, (j + 1) - i);
      se.insert(c);
    }
  }

  // vector<string> vs;
  int C = 0;
  for (auto itr = se.begin(); itr != se.end(); itr++) {
    C++;
    if (C == k)
      cout << *itr << endl;
  }

  // sort(vs.begin(),vs.end());
  // cout<<vs[k-1]<<endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define COUT(x) cout << (x) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using M = map<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

string S;
int K, N;
set<string> ans;

void dfs(string s, int i) {
  if (i >= N) {
    ans.insert(s);
    return;
  }
  dfs(s + S[i], i + 1);
  if (!s.empty())
    ans.insert(s);
}

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

  REP(i, N) {
    string s;
    dfs(s, i);
  }

  auto it = ans.begin();
  REP(i, K - 1) it++;
  COUT(*it);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define COUT(x) cout << (x) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using M = map<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

string S;
int K, N;
set<string> ans;

void dfs(string s, int i) {
  if (s.size() > K || i >= N) {
    ans.insert(s);
    return;
  }
  dfs(s + S[i], i + 1);
  if (!s.empty())
    ans.insert(s);
}

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

  REP(i, N) {
    string s;
    dfs(s, i);
  }

  auto it = ans.begin();
  REP(i, K - 1) it++;
  COUT(*it);
  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;
  set<string> v;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      v.insert(s.substr(i, j));
    }
  }
  int c = 1;
  for (auto i = v.begin(); i != v.end(); i++) {
    if (c == k) {
      cout << *i << endl;
      return 0;
    }
    c++;
  }
  return 0;
}


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

using namespace std;

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

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= min(k, int(s.size())); j++) {
      v.insert(s.substr(i, j));
    }
  }
  int c = 1;
  for (auto i = v.begin(); i != v.end(); i++) {
    if (c == k) {
      cout << *i << endl;
      return 0;
    }
    c++;
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
set<string> s1;
set<string>::iterator it;
string s_kth, minstr, tmp;
char sz[5000];
void broken(string str_c) {
  int i, j, k;
  k = str_c.length();
  for (i = 1; i <= k; i++) {
    for (j = 0; j < k - i + 1; j++) {
      tmp = str_c.substr(j, i);
      s1.insert(tmp);
    }
  }
  return;
}
int main() {
  int i, l, k;
  scanf("%s", sz);
  s_kth = sz;
  l = s_kth.length();
  scanf("%d", &k);
  minstr = s_kth;
  if (k > l) {
    broken(s_kth);
  } else {
    for (i = 0; i < l - k; i++) {
      tmp = s_kth.substr(i, k);
      if (tmp < minstr) {
        broken(tmp);
        minstr = tmp;
      }
    }
    tmp = s_kth.substr(l - k, k);
    broken(tmp);
  }
  it = s1.begin();
  for (i = 0; i < k - 1; i++) {
    it++;
  }
  printf("%s", (*it).c_str());
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
set<string> s1;
set<string>::iterator it;
string s_kth, minstr, tmp;
char sz[5001];
void broken(string str_c) {
  int i, j, k;
  k = str_c.length();
  for (i = 1; i <= k; i++) {
    for (j = 0; j < k - i + 1; j++) {
      tmp = str_c.substr(j, i);
      s1.insert(tmp);
    }
  }
  return;
}
int main() {
  int i, l, k;
  scanf("%s", sz);
  s_kth = sz;
  l = s_kth.length();
  scanf("%d", &k);
  minstr = s_kth;
  if (k > l) {
    broken(s_kth);
  } else {
    for (i = 0; i < l - k; i++) {
      tmp = s_kth.substr(i, k);
      if (tmp < minstr) {
        broken(tmp);
        minstr = tmp;
      }
    }
    tmp = s_kth.substr(l - k, k);
    broken(tmp);
  }
  it = s1.begin();
  for (i = 0; i < k - 1; i++) {
    it++;
  }
  printf("%s", (*it).c_str());
  return 0;
}
Problem p03353 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  priority_queue<string, vector<string>, greater<string>> pq;
  set<string> set;
  for (int l = 0; l < s.size(); l++) {
    for (int r = l; r < s.size(); r++) {
      string str = s.substr(l, r - l + 1);
      if (set.find(str) == set.end()) {
        set.insert(str);
        pq.push(str);
      }
    }
  }
  for (int i = 0; i < k - 1; i++) {
    pq.pop();
  }
  cout << pq.top() << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  priority_queue<string, vector<string>, greater<string>> pq;
  set<string> set;
  for (int l = 0; l < s.size(); l++) {
    for (int r = l; r < s.size() && r - l + 1 <= 5; r++) {
      string str = s.substr(l, r - l + 1);
      if (set.find(str) == set.end()) {
        set.insert(str);
        pq.push(str);
      }
    }
  }
  for (int i = 0; i < k - 1; i++) {
    pq.pop();
  }
  cout << pq.top() << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC097C - K-th Substring
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N = s.size();
  set<string> setS;
  REP(i, N) {
    for (int j = 1; j <= N - i; j++) {
      setS.insert(s.substr(i, j));
    }
  }
  vector<string> vecS(setS.begin(), setS.end());
  sort(vecS.begin(), vecS.end());
  cout << vecS[K - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC097C - K-th Substring
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N = s.size();
  set<string> setS;
  REP(i, N) {
    for (int j = 1; j <= min(N - i, K); j++) {
      setS.insert(s.substr(i, j));
    }
  }
  vector<string> vecS(setS.begin(), setS.end());
  sort(vecS.begin(), vecS.end());
  cout << vecS[K - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  set<string> res;
  REP(i, N) {
    REP(j, N - i) { res.insert(S.substr(i, j + 1)); }
  }
  int cnt = 0;
  for (auto i : res) {
    if (cnt == K - 1) {
      cout << i << endl;
      return 0;
    }
    cnt++;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  set<string> res;
  REP(i, N) {
    REP(j, min(K, N - i)) { res.insert(S.substr(i, j + 1)); }
  }
  int cnt = 0;
  for (auto i : res) {
    if (cnt == K - 1) {
      cout << i << endl;
      return 0;
    }
    cnt++;
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9 : 1e18)
#define EPS 0.0000000001
using namespace std;
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 <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vectors<decltype(inner)>(x, inner);
}
template <class T> void show_with_brank(T a) {
  int cnt = 0;
  for (auto itr : a) {
    if (cnt++ != 0)
      cout << " ";
    cout << itr;
  }
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
#define int ll
signed main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<string> res;
  map<string, int> mem;
  for (int i = 0; i < s.size(); i++) {
    string temp;
    for (int l = 0; l + i < s.size(); l++) {
      temp += s[i + l];
      if (mem[temp] == 0) {
        res.push_back(temp);
        mem[temp]++;
      }
    }
  }
  sort(all(res));
  cout << res[--n] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9 : 1e18)
#define EPS 0.0000000001
using namespace std;
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 <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vectors<decltype(inner)>(x, inner);
}
template <class T> void show_with_brank(T a) {
  int cnt = 0;
  for (auto itr : a) {
    if (cnt++ != 0)
      cout << " ";
    cout << itr;
  }
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
#define int ll
signed main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<string> res;
  map<string, int> mem;
  for (int i = 0; i < s.size(); i++) {
    string temp;
    for (int l = 0; l + i < s.size(); l++) {
      temp += s[i + l];
      if (temp.size() > 100)
        continue;
      if (mem[temp] == 0) {
        res.push_back(temp);
        mem[temp]++;
      }
    }
  }
  sort(all(res));
  cout << res[--n] << endl;
}