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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI = 3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL

vector<string> vec(2500 * 5001);

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

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

  // auto compare = [](string& x, string& y) { return x > y; };
  // priority_queue<string, vector<string>, decltype(compare)> pque{compare};
  int total = 0;
  for (int k = 1; k <= s.size(); ++k) {
    rep(pos, s.size() - k + 1) {
      // pque.push(s.substr(pos, k));
      vec[total++] = s.substr(pos, k);
    }
  }

  sort(vec.begin(), vec.begin() + total);
  vec.erase(unique(vec.begin(), vec.begin() + total), vec.begin() + total);
  cout << vec[K - 1] << "\n";

  // string ans = "";
  // int count = 0;
  // while (!pque.empty())
  // {
  //     if (ans != pque.top())
  //     {
  //         ans = pque.top();
  //         ++count;
  //     }
  //     if (count == K) break;
  //     pque.pop();
  // }

  // cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI = 3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL

vector<string> vec(2500 * 5001);

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

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

  // auto compare = [](string& x, string& y) { return x > y; };
  // priority_queue<string, vector<string>, decltype(compare)> pque{compare};
  int total = 0;
  for (int k = 1; k <= K; ++k) {
    rep(pos, s.size() - k + 1) {
      // pque.push(s.substr(pos, k));
      vec[total++] = s.substr(pos, k);
    }
  }

  sort(vec.begin(), vec.begin() + total);
  vec.erase(unique(vec.begin(), vec.begin() + total), vec.begin() + total);
  cout << vec[K - 1] << "\n";

  // string ans = "";
  // int count = 0;
  // while (!pque.empty())
  // {
  //     if (ans != pque.top())
  //     {
  //         ans = pque.top();
  //         ++count;
  //     }
  //     if (count == K) break;
  //     pque.pop();
  // }

  // cout << ans << "\n";
  return 0;
}
Problem p03353 (C++)

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

typedef long long ll;

int main() {
  set<string> st;
  string s;
  cin >> s;
  int K;
  cin >> K;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; i + j <= s.length(); j++) {
      st.insert(s.substr(i, j));
    }
  }
  int cnt = 1;
  string ans = "";
  for (auto itr = st.begin(); itr != st.end(); itr++) {
    // cout << *itr << endl;
    if (cnt == K) {
      ans = *itr;
      break;
    }
    cnt++;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

int main() {
  set<string> st;
  string s;
  cin >> s;
  int K;
  cin >> K;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= K; j++) {
      st.insert(s.substr(i, j));
    }
  }
  int cnt = 1;
  string ans = "";
  for (auto itr = st.begin(); itr != st.end(); itr++) {
    // cout << *itr << endl;
    if (cnt == K) {
      ans = *itr;
      break;
    }
    cnt++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  string str;
  int K;
  cin >> str;
  cin >> K;
  set<string> st;
  for (int i = 0; i < str.size(); i++) {
    for (int j = i + 1; j <= str.size(); j++) {
      int cnt = 0;
      bool if_break = false;
      if (st.size() < K) {
        st.insert(str.substr(i, j - i));
      } else {
        for (auto itr = st.begin(); itr != st.end(); itr++) {
          if (cnt <= K) {
            if (*itr > str.substr(i, j - i)) {
              st.insert(str.substr(i, j - i));
              break;
            }
          } else {
            if_break = true;
            break;
          }
          cnt++;
        }
      }
      if (if_break)
        break;
    }
  }

  int idx = 1;
  for (auto itr = st.begin(); itr != st.end(); itr++) {
    if (idx == K) {
      cout << *itr << endl;
      break;
    }
    idx++;
  }

  return 0;
}

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

using namespace std;

int main() {
  string str;
  int K;
  cin >> str;
  cin >> K;
  set<string> st;
  for (int i = 0; i < str.size(); i++) {
    for (int j = i + 1; j <= min((int)str.size(), i + K); j++) {
      int cnt = 0;
      bool if_break = false;
      if (st.size() < K) {
        st.insert(str.substr(i, j - i));
      } else {
        for (auto itr = st.begin(); itr != st.end(); itr++) {
          if (cnt <= K) {
            if (*itr > str.substr(i, j - i)) {
              st.insert(str.substr(i, j - i));
              break;
            }
          } else {
            if_break = true;
            break;
          }
          cnt++;
        }
      }
      if (if_break)
        break;
    }
  }

  int idx = 1;
  for (auto itr = st.begin(); itr != st.end(); itr++) {
    if (idx == K) {
      cout << *itr << endl;
      break;
    }
    idx++;
  }

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

// typedef pair<int,int> P;

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

  string s;
  char str[501];
  int K;
  scanf("%s", str);
  scanf("%d", &K);

  s = str;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= K; j++) {
      string sub = s.substr(i, j);
      auto itr = mp.find(sub);
      if (itr == mp.end()) {
        mp[sub] = i * s.length() + j;
        // printf("%s\n", sub.c_str());
      }
    }
  }

  auto iter = mp.begin();
  iter = next(iter, K - 1);
  printf("%s\n", iter->first.c_str());

  return 0;
}


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

using namespace std;

// typedef pair<int,int> P;

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

  string s;
  char str[5001];
  int K;
  scanf("%s", str);
  scanf("%d", &K);

  s = str;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= K; j++) {
      string sub = s.substr(i, j);
      auto itr = mp.find(sub);
      if (itr == mp.end()) {
        mp[sub] = i * s.length() + j;
        // printf("%s\n", sub.c_str());
      }
    }
  }

  auto iter = mp.begin();
  iter = next(iter, K - 1);
  printf("%s\n", iter->first.c_str());

  return 0;
}
Problem p03353 (C++)

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

string s;
int k;
string ans[6];

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

  for (int i = 0; i <= k; i++) {
    ans[i] = "~";
  }

  int l = s.length();
  for (int i = 0; i < l; i++) {
    for (int j = 1; j <= l - i; j++) {
      string tmp = s.substr(i, j);
      int I;
      for (I = 0; I < k; I++) {
        if (ans[I] == tmp)
          break;
      }
      if (I == k) {
        ans[k] = tmp;
        sort(ans, ans + k + 1);
      }
    }
  }

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

  return 0;
}

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

string s;
int k;
string ans[6];

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

  for (int i = 0; i <= k; i++) {
    ans[i] = "~";
  }

  int l = s.length();
  for (int i = 0; i < l; i++) {
    for (int j = 1; j <= l - i; j++) {
      string tmp = s.substr(i, j);
      if (ans[k - 1] <= tmp)
        break;
      int I;
      for (I = 0; I < k; I++) {
        if (ans[I] == tmp)
          break;
      }
      if (I == k) {
        ans[k] = tmp;
        sort(ans, ans + k + 1);
      }
    }
  }

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

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>

using namespace std;
// using ll = long long;
using ll = int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve() {
  string s;
  int k;
  cin >> s >> k;

  set<string> x;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i; j++) {
      x.insert(s.substr(i, j));
    }
  }
  int c = 0;
  for (auto itr = x.begin(); itr != x.end(); itr++) {
    if (c == k - 1) {
      cout << *itr << endl;
      return;
    }
    c++;
  }
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>

using namespace std;
// using ll = long long;
using ll = int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve() {
  string s;
  int k;
  cin >> s >> k;

  set<string> x;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= k; j++) {
      x.insert(s.substr(i, j));
    }
  }
  int c = 0;
  for (auto itr = x.begin(); itr != x.end(); itr++) {
    if (c == k - 1) {
      cout << *itr << endl;
      return;
    }
    c++;
  }
}

int main() {
  solve();
  return 0;
}
Problem p03353 (C++)

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

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

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

int main() {
  vector<string> substrs;
  int k;
  string s;
  cin >> s >> k;
  for (int length = 1; length <= k; length++) {
    for (int i = 0; i < s.length() - length + 1; i++) {
      substrs.push_back(s.substr(i, length));
    }
  }
  sort(substrs.begin(), substrs.end());
  unique(substrs.begin(), substrs.end());
  cout << substrs[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 vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  for (int i = 0; i < s.length(); ++i) {
    for (int j = i; j < s.length(); ++j) {
      st.insert(s.substr(i, j - i + 1));
    }
  }
  vector<string> ans(st.begin(), st.end());
  sort(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
  return 0;
}

static int speedUp = []() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  return 0;
}();


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  for (int i = 0; i < s.length(); ++i) {
    for (int j = 1; j <= k; ++j) {
      st.insert(s.substr(i, j));
    }
  }
  vector<string> ans(st.begin(), st.end());
  sort(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
  return 0;
}

static int speedUp = []() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  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;

  vector<string> v;
  set<string> st;
  for (int i = 1; i <= s.size(); i++) {
    for (int j = 0; i + j <= s.size(); j++) {
      string sub = s.substr(j, i);
      if (st.count(sub) == 0) {
        st.insert(sub);
        v.push_back(sub);
      }
    }
  }

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

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

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

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

  vector<string> v;
  set<string> st;
  for (int i = 1; i <= K; i++) {
    for (int j = 0; i + j <= s.size(); j++) {
      string sub = s.substr(j, i);
      if (st.count(sub) == 0) {
        st.insert(sub);
        v.push_back(sub);
      }
    }
  }

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

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

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

int main() {
  vector<string> v;
  string s;
  int k;
  cin >> s >> k;
  // cout << s.size() << endl;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; i + j <= s.size(); j++) {
      v.push_back(s.substr(i, j));
      // 	cout << s.substr(i, j) << endl;
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  // cout << "sorted" << endl;
  for (auto itr = v.begin(); itr != v.end(); itr++) {
    //	cout << (*itr) << endl;
  }

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

  return 0;
}

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

int main() {
  vector<string> v;
  string s;
  int k;
  cin >> s >> k;
  // cout << s.size() << endl;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      if ((i + j) <= s.size())
        v.push_back(s.substr(i, j));
      // 	cout << s.substr(i, j) << endl;
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  // cout << "sorted" << endl;
  for (auto itr = v.begin(); itr != v.end(); itr++) {
    //	cout << (*itr) << endl;
  }

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

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {

  string s;
  cin >> s;

  int k;
  cin >> k;

  int len = s.size();

  vector<string> v;

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

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

  cout << v[k - 1] << '\n';
  return 0;
}

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

using namespace std;

int main() {

  string s;
  cin >> s;

  int k;
  cin >> k;

  int len = s.size();

  vector<string> v;

  for (int i = 0; i < len; i++) {
    for (int j = i; j < len && (j - i + 1) <= k; j++) {
      string a = s.substr(i, j - i + 1);
      v.push_back(a);
    }
  }

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

  cout << v[k - 1] << '\n';
  return 0;
}
Problem p03353 (C++)

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

typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
#define rep(i, N) for (ll i = 0; i < (N); i++)

string s;
string ss[10];
string S[15005];
map<string, ll> mp;
ll K;
ll n;

int main() {

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

  cin >> s >> K;

  ll n = 0;
  ll sz = s.size();
  rep(i, sz) {
    ss[0] = s.substr(i, 1);
    ss[1] = s.substr(i, 2);
    ss[2] = s.substr(i, 3);
    ss[3] = s.substr(i, 4);
    ss[4] = s.substr(i, 5);

    rep(k, 5) {
      if (i + k >= sz)
        continue;
      if (mp[ss[k]] == 0) {
        S[n] = ss[k];
        n++;
        mp[ss[k]]++;
      }
    }
  }

  sort(S, S + n);

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


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

typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
#define rep(i, N) for (ll i = 0; i < (N); i++)

string s;
string ss[10];
string S[25005];
map<string, ll> mp;
ll K;
ll n;

int main() {

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

  cin >> s >> K;

  ll n = 0;
  ll sz = s.size();
  rep(i, sz) {
    ss[0] = s.substr(i, 1);
    ss[1] = s.substr(i, 2);
    ss[2] = s.substr(i, 3);
    ss[3] = s.substr(i, 4);
    ss[4] = s.substr(i, 5);

    rep(k, 5) {
      if (i + k >= sz)
        continue;
      if (mp[ss[k]] == 0) {
        S[n] = ss[k];
        n++;
        mp[ss[k]]++;
      }
    }
  }

  sort(S, S + n);

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

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

using namespace std;

int main() {
  string s, s_temp;
  int k;
  cin >> s >> k;
  set<string> se;
  for (int i = 0; i < s.length(); i++) {
    s_temp = "";
    for (int j = i; j < s.length(); j++) {
      s_temp += s[j];
      // cout << s_temp << endl;
      se.insert(s_temp);
    }
  }
  int i = 0;
  for (auto f : se) {
    i++;
    if (i == k)
      cout << f << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  string s, s_temp;
  int k;
  cin >> s >> k;
  set<string> se;
  for (int i = 0; i < s.length(); i++) {
    s_temp = "";
    for (int j = i; j < s.length(); j++) {
      s_temp += s[j];
      // cout << s_temp << endl;
      if (s_temp.length() <= 5)
        se.insert(s_temp);
    }
  }
  int i = 0;
  for (auto f : se) {
    i++;
    if (i == k)
      cout << f << endl;
  }
  return 0;
}
Problem p03353 (C++)

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

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

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

  int c = 0;
  for (auto p : mp) {
    c++;
    if (c == k) {
      cout << p.first << endl;
      return 0;
    }
  }

  return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

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

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

  int c = 0;
  for (auto p : mp) {
    c++;
    if (c == k) {
      cout << p.first << endl;
      return 0;
    }
  }

  return 0;
}
Problem p03353 (C++)

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

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

  int n = s.size();
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n - i; j++) {
      string c = s.substr(i, j);
      if (c == "")
        continue;
      m[c]++;
    }
  }

  int i = 0;
  for (auto p : m) {
    i++;
    if (i == k) {
      cout << p.first << endl;
      return 0;
    }
  }

  return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

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

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

  int i = 0;
  for (auto p : m) {
    i++;
    if (i == k) {
      cout << p.first << endl;
      return 0;
    }
  }

  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;

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

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

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

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

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

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

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

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

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

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

vector<string> v;
string str;
map<string, int> mp;

int main() {
  int k;
  string temp;

  cin >> str;
  cin >> k;

  for (int i = 0; i < str.size(); i++) {
    temp = "";

    for (int j = 0; i + j < str.size(); j++) {
      temp += str[i + j];
      if (mp.count(temp) == 0) {
        mp[temp] = 1;
        v.push_back(temp);
      }
    }
  }

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

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

  return 0;
}


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

vector<string> v;
string str;
map<string, int> mp;

int main() {
  int k;
  string temp;

  cin >> str;
  cin >> k;

  for (int i = 0; i < str.size(); i++) {
    temp = "";

    for (int j = 0; i + j < str.size() && j < k; j++) {
      temp += str[i + j];
      if (mp.count(temp) == 0) {
        mp[temp] = 1;
        v.push_back(temp);
      }
    }
  }

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

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

  return 0;
}
Problem p03353 (C++)

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

int main(int argc, char *argv[]) {
  std::string s;
  int k;
  std::cin >> s >> k;
  //	std::vector<std::string> ss;
  std::set<std::string> ss;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i; j++) {
      //			ss.push_back(s.substr(i, j));
      ss.insert(s.substr(i, j));
    }
  }
  //	std::sort(ss.begin(), ss.end());
  //	std::unique(ss.begin(), ss.end());
  //	std::cout << ss[k-1];
  int cnt = 1;
  for (auto it : ss) {
    if (cnt == k) {
      std::cout << it;
    }
    cnt++;
  }
}

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

int main(int argc, char *argv[]) {
  std::string s;
  int k;
  std::cin >> s >> k;
  //	std::vector<std::string> ss;
  std::set<std::string> ss;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= std::min((int)s.length() - i, 5); j++) {
      //			ss.push_back(s.substr(i, j));
      ss.insert(s.substr(i, j));
    }
  }
  //	std::sort(ss.begin(), ss.end());
  //	std::unique(ss.begin(), ss.end());
  //	std::cout << ss[k-1];
  int cnt = 1;
  for (auto it : ss) {
    if (cnt == k) {
      std::cout << it;
    }
    cnt++;
  }
}
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> st;

  for (int i = 1; i <= s.size(); i++) {
    for (int j = 0; j < s.size() - i + 1; j++) {
      st.insert(s.substr(j, i));
    }
  }
  int count = 0;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    count++;
    if (count == k)
      std::cout << *itr << "\n";
  }
  return 0;
}

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

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

  set<string> st;

  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < s.size() - i + 1; j++) {
      st.insert(s.substr(j, i));
    }
  }
  int count = 0;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    count++;
    if (count == k)
      std::cout << *itr << "\n";
  }
  return 0;
}
Problem p03353 (C++)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

  vector<string> v;

  for (int i = 1; i <= k; ++i) { // 何文字か。最大でもk文字以下になる
    for (int j = 0; j <= s.size() - i; ++j) { // 何文字目からか
      string st = "";
      for (int l = 0; l < i; ++l) {
        if (j + l > s.size() - 1) {
          break;
        } else {
          st += s[j + l];
        }
      }

      auto itr = find(v.begin(), v.end(), st);
      if (itr == v.end()) {
        v.push_back(st);
      }
    }
  }

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

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

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

  vector<string> v;

  int n = s.size();

  for (int i = 1; i <= min(k, n); ++i) { // 何文字か。最大でもk文字以下になる
    for (int j = 0; j <= s.size() - i; ++j) { // 何文字目からか
      string st = "";
      for (int l = 0; l < i; ++l) {
        if (j + l > s.size() - 1) {
          break;
        } else {
          st += s[j + l];
        }
      }

      auto itr = find(v.begin(), v.end(), st);
      if (itr == v.end()) {
        v.push_back(st);
      }
    }
  }

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

  cout << v[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 < (n); ++i)
#define REP(i, n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

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

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

int main() {
  string s;
  int k, n;
  cin >> s >> k;
  n = s.size();
  map<string, int> mp;
  for (int i = n; i > 0; --i) {
    if (n - i >= 6)
      break;
    rep(j, i) { mp[s.substr(j, (n - i + 1))]++; }
  }
  int cnt = 0;
  string ans;
  for (auto &v : mp) {
    ans = v.first;
    cnt++;
    if (cnt == k)
      break;
  }
  cout << ans << 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;
  cin >> s >> k;

  vector<string> vec;
  set<string> st;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; i + j <= s.size(); j++) {
      st.insert(s.substr(i, j));
    }
  }
  for (auto x : st) {
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());

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

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

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

  vector<string> vec;
  set<string> st;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j > s.size())
        break;
      st.insert(s.substr(i, j));
    }
  }
  for (auto x : st) {
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());

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

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

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

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

  set<string>::iterator it = subs.begin();
  while (k-- > 1)
    it++;
  cout << *it << endl;
  return 0;
}

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

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

  for (int i = 1; i <= min(k, (int)s.size()); i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      subs.insert(s.substr(j, i));
    }
  }

  set<string>::iterator it = subs.begin();
  while (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;
  cin >> s;
  int k;
  cin >> k;
  int l = s.size();

  int i = l;
  int b = 1;
  set<string> cnddt;
  while (i--) {
    for (int j = 0; j < l - i + 1; j++)
      cnddt.insert(s.substr(j, i + 1));
  }
  vector<string> ss(cnddt.begin(), cnddt.end());
  cout << ss[k] << endl;
  return 0;
}

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

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

  int i = l > k ? k : l;
  int b = 1;
  set<string> cnddt;
  while (i--) {
    for (int j = 0; j < l - i + 1; j++)
      cnddt.insert(s.substr(j, i + 1));
  }
  vector<string> ss(cnddt.begin(), cnddt.end());
  cout << ss[k] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
// ll a[N],sum[N];

vector<string> t;
set<string> st;

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

  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      t.pb(s.substr(i, j - i + 1));
    }
  }
  sort(t.begin(), t.end());
  int cnt = 0;
  for (auto ss : t) {
    st.insert(ss);
  }
  for (auto ss : st) {
    ++cnt;
    if (cnt == k) {
      cout << ss << endl;
      break;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
// ll a[N],sum[N];

vector<string> t;
set<string> st;

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

  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int len = 1; len <= 5; len++) {
      if (i + len <= n)
        t.pb(s.substr(i, len));
    }
  }
  sort(t.begin(), t.end());
  int cnt = 0;
  for (auto ss : t) {
    st.insert(ss);
  }
  for (auto ss : st) {
    ++cnt;
    if (cnt == k) {
      cout << ss << endl;
      break;
    }
  }

  return 0;
}
Problem p03353 (C++)

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

const int N = 2e5 + 100;
const int mod = 1e9 + 7;
typedef long long ll;

typedef pair<int, int> pa;

set<string> s;

vector<string> ve;
unordered_map<string, int> mp;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string ss;
  cin >> ss;
  int len = ss.size();
  for (int i = 0; i < len; i++) {
    string kk = "";
    for (int j = i; j < len; j++) {
      kk.push_back(ss[j]);
      if (!mp[kk]) {
        mp[kk] = 1;
        ve.push_back(kk);
      }
    }
  }
  sort(ve.begin(), ve.end(), less<string>());
  int k;
  cin >> k;
  cout << ve[k - 1] << endl;
  return 0;
}


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

const int N = 2e5 + 100;
const int mod = 1e9 + 7;
typedef long long ll;

typedef pair<int, int> pa;

set<string> s;

vector<string> ve;
unordered_map<string, int> mp;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string ss;
  cin >> ss;
  int len = ss.size();
  for (int i = 0; i < len; i++) {
    string kk = "";
    for (int j = i; j < min(len, i + 10); j++) {
      kk.push_back(ss[j]);
      if (!mp[kk]) {
        mp[kk] = 1;
        ve.push_back(kk);
      }
    }
  }
  sort(ve.begin(), ve.end(), less<string>());
  int k;
  cin >> k;
  cout << ve[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> st;
  for (int i = 0; i < s.length(); i++) {
    for (int j = i; j < s.length(); j++) {
      st.insert(s.substr(i, min((int)s.length() - j, K)));
    }
  }
  int idx = 1;
  for (auto s : st) {
    if (idx == K) {
      cout << s << endl;
      return 0;
    }
    idx++;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> st;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= K; j++) {
      st.insert(s.substr(i, min(j, (int)s.length() - i)));
    }
  }
  int idx = 1;
  for (auto s : st) {
    if (idx == K) {
      cout << s << endl;
      return 0;
    }
    idx++;
  }
  return 0;
}
Problem p03353 (C++)

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

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {

  // cin.tie(0); ios_base::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;

  int n = sz(s);
  set<string> st;

  rep2(len, 1, n + 1) { rep(i, n - len + 1) st.insert(s.substr(i, len)); }
  // for(auto x :st) cout << x <<" "; puts("");
  auto it = st.begin();
  rep(i, k - 1) it++;
  cout << *it << "\n";
  return 0;
}


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

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {

  // cin.tie(0); ios_base::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;

  int n = sz(s);
  set<string> st;

  rep2(len, 1, min(6, n + 1)) {
    rep(i, n - len + 1) st.insert(s.substr(i, len));
  }
  // for(auto x :st) cout << x <<" "; puts("");
  auto it = st.begin();
  rep(i, k - 1) it++;
  cout << *it << "\n";
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {

  string s;
  int k;

  cin >> s >> k;

  vector<string> subs;

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

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

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

  cout << subs[k - 1] NL;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {

  string s;
  int k;

  cin >> s >> k;

  vector<string> subs;

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

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

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

  cout << subs[k - 1] NL;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;
typedef long long ll;
using Pll = pair<ll, ll>;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

// cout << fixed << setprecision(10);

int main() {
  string s;
  ll K;
  cin >> s >> K;
  vector<vector<ll>> ch(26, vector<ll>());
  for (int i = 0; i < (ll)s.size(); i++) {
    ch[s[i] - 'a'].push_back(i);
  }
  vector<string> strs;
  set<string> st;
  for (int i = 0; i < 26; i++) {
    string tmp = "";
    if (strs.size() > K)
      break;
    for (ll e : ch[i]) {
      for (int l = e; l < s.size(); l++) {
        tmp = s.substr(e, l - e + 1);
        if (st.count(tmp) == 0) {
          st.insert(tmp);
          strs.push_back(tmp);
        }
      }
    }
  }
  sort(strs.begin(), strs.end());
  cout << strs[K - 1] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
using Pll = pair<ll, ll>;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

// cout << fixed << setprecision(10);

int main() {
  string s;
  ll K;
  cin >> s >> K;
  vector<vector<ll>> ch(26, vector<ll>());
  for (int i = 0; i < (ll)s.size(); i++) {
    ch[s[i] - 'a'].push_back(i);
  }
  vector<string> strs;
  set<string> st;
  for (int i = 0; i < 26; i++) {
    string tmp = "";
    if (strs.size() > K)
      break;
    for (ll e : ch[i]) {
      for (int l = e; l < e + K; l++) {
        tmp = s.substr(e, l - e + 1);
        if (st.count(tmp) == 0) {
          st.insert(tmp);
          strs.push_back(tmp);
        }
      }
    }
  }
  sort(strs.begin(), strs.end());
  cout << strs[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, cnt = 0;
  string s, alph = "abcdefghijklmnopqrstuvwxyz", t[10];
  cin >> s >> n;
  map<string, int> mp;
  for (int i = 0; i < alph.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == alph[i]) {
        for (int k = 1; k <= n; k++) {
          if (mp[s.substr(j, k)] == 0) {
            mp[s.substr(j, k)]++;
            t[cnt] = s.substr(j, k);
            cnt++;
          }
        }
      }
    }
    if (cnt >= n) {
      sort(t, t + cnt);
      cout << t[n - 1] << endl;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, cnt = 0;
  string s, alph = "abcdefghijklmnopqrstuvwxyz", t[1000];
  cin >> s >> n;
  map<string, int> mp;
  for (int i = 0; i < alph.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == alph[i]) {
        for (int k = 1; k <= n; k++) {
          if (mp[s.substr(j, k)] == 0) {
            mp[s.substr(j, k)]++;
            t[cnt] = s.substr(j, k);
            cnt++;
          }
        }
      }
    }
    if (cnt >= n) {
      sort(t, t + cnt);
      cout << t[n - 1] << endl;
      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> set;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      set.insert(s.substr(i, j - i + 1));
    }
  }
  auto it = set.begin();
  for (int i = 0; i < k - 1; i++, it++)
    ;
  cout << *it << endl;
}


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

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

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

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

  map<string, bool> mp;
  vector<string> subs;
  for (int i = 0; i < int(s.size()); i++) {
    string temp = "";
    for (int j = 0; i + j < int(s.size()); j++) {
      temp += s[i + j];
      if (mp[temp] == false) {
        subs.push_back(temp);
        mp[temp] = true;
      }
    }
  }

  sort(subs.begin(), subs.end());
  // subs.erase(unique(subs.begin(), subs.end()), subs.end());

  // rep(i, subs.size()) cout << subs[i] << endl;

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

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

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

  map<string, bool> mp;
  vector<string> subs;
  for (int i = 0; i < int(s.size()); i++) {
    string temp = "";
    for (int j = 0; j < 5 && i + j < s.size(); j++) {
      temp += s[i + j];
      if (mp[temp] == false) {
        subs.push_back(temp);
        mp[temp] = true;
      }
    }
  }

  sort(subs.begin(), subs.end());
  // subs.erase(unique(subs.begin(), subs.end()), subs.end());

  // rep(i, subs.size()) cout << subs[i] << endl;

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

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  priority_queue<string, vector<string>, greater<string>> q;
  for (int i = 0; i < s.length(); ++i) {
    for (int j = i; j < s.length(); ++j) {
      const basic_string<char, char_traits<char>, allocator<char>> &v =
          s.substr(i, j - i + 1);
      q.push(v);
    }
  }

  string prev = q.top();
  q.pop();
  int i = 1;
  while (i < k) {
    string ss = q.top();
    q.pop();
    if (ss != prev) {
      i++;
      prev = ss;
    }
  }
  cout << prev << endl;

  return 0;
}


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

int main() {
  string s;
  int k;
  cin >> s >> k;
  priority_queue<string, vector<string>, greater<string>> q;
  for (int i = 0; i < s.length(); ++i) {
    for (int j = i; j < s.length(); ++j) {
      const basic_string<char, char_traits<char>, allocator<char>> &v =
          s.substr(i, j - i + 1);
      q.push(v);
      if (j - i + 1 == k)
        break;
    }
  }

  string prev = q.top();
  q.pop();
  int i = 1;
  while (i < k) {
    string ss = q.top();
    q.pop();
    if (ss != prev) {
      i++;
      prev = ss;
    }
  }
  cout << prev << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
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;

int main() {
  string S;
  int K;
  cin >> S;
  cin >> K;
  vector<string> T;
  int N = S.size();
  rep(i, N) {
    for (int j = 1; j <= N - i; j++) {
      T.push_back(S.substr(i, j));
    }
  }
  sort(T.begin(), T.end());
  ll M = T.size();
  int cnt = 1;
  string ans;
  for (ll i = 0; i < M; i++) {
    if (cnt == K) {
      ans = T[i];
      break;
    }
    if (T[i] != T[i + 1])
      cnt++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
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;

int main() {
  string S;
  int K;
  cin >> S;
  cin >> K;
  vector<string> T;
  int N = S.size();
  rep(i, N) {
    for (int j = 1; j <= 5; j++) {
      T.push_back(S.substr(i, j));
    }
  }
  sort(T.begin(), T.end());
  ll M = T.size();
  int cnt = 1;
  string ans;
  for (ll i = 0; i < M; i++) {
    if (cnt == K) {
      ans = T[i];
      break;
    }
    if (T[i] != T[i + 1])
      cnt++;
  }
  cout << ans << endl;
}
Problem p03353 (C++)

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

using namespace std;

set<string> X;

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

  for (int len = 1; len <= s.size(); ++len) {
    for (int start = 0; start + len <= s.size(); ++start) {
      string substr = s.substr(start, len);
      X.insert(substr);

      if (X.size() > 5) {
        X.erase(--X.end());
      }
    }
  }

  int k = 1;
  for (auto &x : X) {
    if (k++ == K) {
      cout << x << endl;
      break;
    }
  }
  return 0;
}

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

using namespace std;

set<string> X;

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

  for (int len = 1; len <= 5; ++len) {
    for (int start = 0; start + len <= s.size(); ++start) {
      string substr = s.substr(start, len);
      X.insert(substr);

      if (X.size() > 5) {
        X.erase(--X.end());
      }
    }
  }

  int k = 1;
  for (auto &x : X) {
    if (k++ == K) {
      cout << x << endl;
      break;
    }
  }
  return 0;
}