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

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

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

#define N 100005
unordered_map<ll, ll> m;
set<string> s;
int main() {
  ios string a, b;
  ll k, i, j, n, cnt = 0;
  cin >> a >> k;
  n = a.size();
  for (i = 0; i < n; i++) {
    string aa;
    ll num = 0;
    for (j = i; j < n; j++) {
      aa += a[j];
      num = (num * 37 + a[j] - 'a' + 1) % hell;
      if (m[num] == 0 && aa.size() < 10) {
        s.insert(aa);
        if (s.size() > 5) {
          auto ii = s.rbegin();
          s.erase(*ii);
        }
        m[num] = 1;
      }
    }
  }
  for (auto i : s) {
    cnt++;
    if (cnt == k) {
      cout << i;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
/* Dsingh_24 */

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

#define N 100005
unordered_map<ll, ll> m;
set<string> s;
int main() {
  ios string a, b;
  ll k, i, j, n, cnt = 0;
  cin >> a >> k;
  n = a.size();
  for (i = 0; i < n; i++) {
    string aa;
    ll num = 0;
    for (j = i; j < min(n, i + 10); j++) {
      aa += a[j];
      num = (num * 37 + a[j] - 'a' + 1) % hell;
      if (m[num] == 0 && aa.size() < 10) {
        s.insert(aa);
        if (s.size() > 5) {
          auto ii = s.rbegin();
          s.erase(*ii);
        }
        m[num] = 1;
      }
    }
  }
  for (auto i : s) {
    cnt++;
    if (cnt == k) {
      cout << i;
      return 0;
    }
  }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define pb push_back
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using vst = vector<string>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// abba
// 43376
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<vst> cnt(5050, vst(5050, ""));
  int len = 1;
  map<string, int> moji;
  while (n - len >= 0 || len > 6) {
    rep(i, 0, n + 1 - len) {
      string v = "";
      v = cnt[i][len - 1] + s[i + len - 1];
      cnt[i][len] = v;
      // cout<<v<<endl;
      moji[v]++;
    }
    len++;
  }
  int u = 0;
  for (auto v : moji) {
    u++;
    if (u == k) {
      cout << v.first << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define pb push_back
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using vst = vector<string>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// abba
// 43376
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<vst> cnt(5050, vst(5050, ""));
  int len = 1;
  map<string, int> moji;
  while (n - len >= 0 && len <= 6) {
    rep(i, 0, n + 1 - len) {
      string v = "";
      v = cnt[i][len - 1] + s[i + len - 1];
      cnt[i][len] = v;
      // cout<<v<<endl;
      moji[v]++;
    }
    len++;
  }
  int u = 0;
  for (auto v : moji) {
    u++;
    if (u == k) {
      cout << v.first << endl;
      return 0;
    }
  }
}
Problem p03355 (C++)

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

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using V = vector<ll>;
using P = pair<ll, ll>;

int main() {
  vector<string> l;
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll n = s.size();
  for (int i = 1; i <= n; ++i) { // 長さ固定
    for (int j = 0; j <= n - i; ++j) {
      l.push_back(s.substr(j, i));
    }
  }
  sort(all(l));
  l.erase(unique(all(l)), l.end());
  // for(auto v:l){
  //   cout <<v<<endl;
  //}
  cout << l[k - 1] << endl;
  return 0;
}

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

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using V = vector<ll>;
using P = pair<ll, ll>;

int main() {
  vector<string> l;
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll n = s.size();
  for (int i = 1; i <= k; ++i) { // 長さ固定
    for (int j = 0; j <= n - i; ++j) {
      l.push_back(s.substr(j, i));
    }
  }
  sort(all(l));
  l.erase(unique(all(l)), l.end());
  // for(auto v:l){
  //   cout <<v<<endl;
  //}
  cout << l[k - 1] << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

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

  vector<string> v;
  rep(i, s.size()) {
    REP(j, 1, k) {
      if (j > s.size())
        continue;
      v.push_back(s.substr(i, j));
    }
  }
  sort(ALL(v));
  int now = 1;
  vector<string> res;
  int cnt = 0;
  rep(i, v.size()) {
    // cout << v[i] << endl;
    if (v[now] == v[i] && i != 0)
      continue;
    cnt++;
    now = i;
    // cout << cnt << " " << v[now] << endl;
    if (cnt == k)
      break;
  }
  cout << v[now] << endl;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

int main() {
  string s;
  int k;
  cin >> s >> k;
  if (s == "z") {
    cout << "z" << endl;
    return 0;
  }
  vector<string> v;
  rep(i, s.size()) {
    REP(j, 1, k) {
      if (j > s.size())
        continue;
      v.push_back(s.substr(i, j));
    }
  }
  sort(ALL(v));
  int now = 1;
  vector<string> res;
  int cnt = 0;
  rep(i, v.size()) {
    // cout << v[i] << endl;
    if (v[now] == v[i] && i != 0)
      continue;
    cnt++;
    now = i;
    // cout << cnt << " " << v[now] << endl;
    if (cnt == k)
      break;
  }
  cout << v[now] << endl;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
    アリナ・グレイはかわいい
*/

#include <bits/stdc++.h>
using namespace std;
#define itn int
#define endl "\n"

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


Fixed submission:
/*
    アリナ・グレイはかわいい
*/

#include <bits/stdc++.h>
using namespace std;
#define itn int
#define endl "\n"

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  map<string, int> P;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < i + k; j++) {
      string t = s.substr(i, (j - i + 1));
      P[t]++;
    }
  }
  int count = 0;
  for (auto p : P) {
    if (count == k - 1)
      cout << p.first << endl;
    count++;
  }
}
Problem p03355 (C++)

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

using namespace std;

int main() {
  string s, sub;
  int k;
  vector<string> v;
  unordered_map<string, int> m;

  cin >> s >> k;

  int size = s.size();
  for (int i = 0; i < size; ++i) {
    for (int j = i + 1; j <= size; ++j) {
      sub = s.substr(i, j - i);
      if (m[sub] == 0) {
        m[sub] = 1;
        v.push_back(sub);
      }
    }
  }

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

  printf("%s\n", v[k - 1].c_str());

  return 0;
}


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

using namespace std;

int main() {
  string s, sub;
  int k;
  vector<string> v;
  unordered_map<string, int> m;

  cin >> s >> k;

  int size = s.size();
  for (int i = 0; i < size; ++i) {
    for (int j = 1; j <= k && (i + j) <= size; ++j) {
      sub = s.substr(i, j);
      if (m[sub] == 0) {
        m[sub] = 1;
        v.push_back(sub);
      }
    }
  }

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

  printf("%s\n", v[k - 1].c_str());

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7, INF = 1e9;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> m;
  for (int i = 0; i < s.size(); i++) {
    string t = "";
    t += s[i];
    m.insert(t);
    for (int j = i + 1; j < s.size(); j++) {
      t += s[j];
      m.insert(t);
    }
  }
  int i = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (i == k - 1) {
      cout << *itr << endl;
      break;
    }
    i++;
  }
  system("pause");
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7, INF = 1e9;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> m;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k; j++) {
      string t = s.substr(i, j);
      m.insert(t);
    }
  }
  int i = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (i == k - 1) {
      cout << *itr << endl;
      break;
    }
    i++;
  }
  system("pause");
}
Problem p03355 (C++)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
ll MOD = 1000000007;

int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  map<string, int> mp;
  REP(i, s.size()) {
    REP(j, i + 1) { mp[s.substr(j, i - j + 1)]++; }
  }

  int i = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    i++;
    if (i == k)
      cout << itr->first << endl;
  }

  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
ll MOD = 1000000007;

int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  map<string, int> mp;
  REP(i, s.size()) {
    for (int j = max(i - 5, 0); j < i + 1; j++) {
      mp[s.substr(j, i - j + 1)]++;
    }
  }

  int i = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    i++;
    if (i == k)
      cout << itr->first << endl;
  }

  return 0;
}
Problem p03355 (C++)

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

string S;
int K;

int main() {
  cin >> S >> K;
  vector<string> vec;
  for (int i = 0; i < S.size(); i++) {
    for (int j = i; j < min((int)S.size(), i + 6); j++)
      vec.push_back(S.substr(i, j - i + 1));
  }
  sort(vec.begin(), vec.end());
  cout << vec[K] << endl;
  return 0;
}

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

string S;
int K;

int main() {
  cin >> S >> K;
  vector<string> vec;
  for (int i = 0; i < S.size(); i++) {
    for (int j = i; j < min((int)S.size(), i + 6); j++)
      vec.push_back(S.substr(i, j - i + 1));
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec[K - 1] << endl;
  return 0;
}
Problem p03355 (C++)

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

using namespace std;

int main(void) {
  char s[5050];
  scanf("%s", s);
  int len = strlen(s);
  int k;
  scanf("%d", &k);
  vector<string> v;
  for (int i = 0; i < len; i++) {
    string q;
    for (int j = i; j < len; j++) {
      q += (s[j]);
      v.push_back(q);
    }
  }
  sort(v.begin(), v.end());
  auto end = unique(v.begin(), v.end());
  v.erase(end, v.end());
  printf("%s", v[k - 1].c_str());
  return 0;
}


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

using namespace std;

int main(void) {
  char s[5050];
  scanf("%s", s);
  int len = strlen(s);
  int k;
  scanf("%d", &k);
  vector<string> v;
  for (int i = 0; i < len; i++) {
    string q;
    for (int j = i, a = 0; j < len && a < 5; j++, a++) {
      q += (s[j]);
      v.push_back(q);
    }
  }
  sort(v.begin(), v.end());
  auto end = unique(v.begin(), v.end());
  v.erase(end, v.end());
  printf("%s", v[k - 1].c_str());
  return 0;
}
Problem p03355 (C++)

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
  string str;
  cin >> str;
  int k;
  cin >> k;
  set<string> dp;

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

  set<string>::iterator it = dp.begin();
  for (int i = 0; i < k - 1; i++)
    it++;

  cout << *it << endl;

  return 0;
}


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
  string str;
  cin >> str;
  int k;
  cin >> k;
  set<string> dp;

  for (int i = 0; i < str.size(); i++) {
    for (int j = i; j < i + 5 && j < str.size(); j++) {
      dp.insert(str.substr(i, j - i + 1));
    }
  }

  set<string>::iterator it = dp.begin();
  for (int i = 0; i < k - 1; i++)
    it++;

  cout << *it << endl;

  return 0;
}
Problem p03355 (C++)

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

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

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

  int n = s.size();

  set<string> S;
  for (int i = 0; i < n; ++i) {
    string cur = "";
    for (int j = i; j < n; ++j) {
      cur += s[j];
      S.insert(cur);
    }
  }

  for (auto &i : S) {
    --k;
    if (k == 0) {
      cout << i << endl;
    }
  }
}

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

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

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

  int n = s.size();

  set<string> S;
  for (int i = 0; i < n; ++i) {
    string cur = "";
    for (int j = i; j < min(i + 5, n); ++j) {
      cur += s[j];
      S.insert(cur);
    }
  }

  for (auto &i : S) {
    --k;
    if (k == 0) {
      cout << i << endl;
    }
  }
}
Problem p03355 (C++)

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

using namespace std;

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

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

  return 0;
}


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

using namespace std;

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

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

  return 0;
}
Problem p03355 (C++)

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

int main() {
  string S;
  int K, count = 1;
  map<string, int> mp;
  cin >> S >> K;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= S.size() - i; j++) {
      string x = S.substr(i, j);
      mp[x]++;
    }
  }
  map<string, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    if (count == K) {
      cout << it->first;
      break;
    }
    count++;
  }
}

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

int main() {
  string S;
  int K, count = 1;
  map<string, int> mp;
  cin >> S >> K;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= S.size() - i && j <= K; j++) {
      string x = S.substr(i, j);
      mp[x]++;
    }
  }
  map<string, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    if (count == K) {
      cout << it->first;
      break;
    }
    count++;
  }
}
Problem p03355 (C++)

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

#define INF 9223372036854775807
#define int long long
#define pi 3.14159265

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> ans(0);
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      if (j + i + 1 > s.size())
        continue;
      ans.push_back(s.substr(i, j + 1));
    }
  }
  sort(ans.begin(), ans.end());
  unique(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
}


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

#define INF 9223372036854775807
#define int long long
#define pi 3.14159265

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> ans(0);
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < k; j++) {
      if (j + i + 1 > s.size())
        continue;
      ans.push_back(s.substr(i, j + 1));
    }
  }
  sort(ans.begin(), ans.end());
  unique(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
}
Problem p03355 (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 n = s.length();

  map<string, int> m;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      string l;
      l = s.substr(i, j - i + 1);

      auto itr = m.find(l);
      if (itr == m.end()) {
        m[l] = 1;
      }
    }
  }

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

  cout << itr->first << endl;
}

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

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

  int k;
  cin >> k;

  int n = s.length();

  map<string, int> m;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (i + k <= j) {
        break;
      }
      string l;
      l = s.substr(i, j - i + 1);

      auto itr = m.find(l);
      if (itr == m.end()) {
        m[l] = 1;
      }
    }
  }

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

  cout << itr->first << endl;
}
Problem p03355 (C++)

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

string s;
int k;
map<char, vector<int>> m;
int main() {
  while (cin >> s >> k) {
    m.clear();
    set<string> v;
    int len = s.length();
    for (int i = 0; i < len; ++i) {
      m[s[i]].push_back(i);
      // printf("i = %d\n", i);
    }
    for (auto it : m) {
      // cout << it.first << " -> ";
      for (auto i : it.second) {
        // cout << i << ' ';
        for (int j = 1, cnt = 0; cnt < k && i + j <= len; ++j) {
          v.insert(s.substr(i, j));
        }
      }
      if (v.size() >= k) {
        break;
      }
    }
    int i = 0;
    for (auto it : v) {
      ++i;
      if (i == k) {
        cout << it << ' ';
        break;
      }
    }
    cout << endl;
    // break;
    // for (int i = 0; i < len; ++i) {
    //   for (int j = 1; i+j <= len; ++j) {
    //     v.push_back(s.substr(i, j));
    //   }
    // }
    // cout << "s=" << s << endl;
    // for (auto it : v) {
    //   cout << it << ' ';
    // } cout << endl;
    // sort(v.begin(), v.end());
    // auto it = unique(v.begin(), v.end());
    // v.resize(distance(v.begin(),it));
    // cout << v[k-1] << endl;
    // for (auto it : v) {
    //   cout << it << ' ';
    // } cout << endl;
  }
}


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

string s;
int k;
map<char, vector<int>> m;
int main() {
  while (cin >> s >> k) {
    m.clear();
    set<string> v;
    int len = s.length();
    for (int i = 0; i < len; ++i) {
      m[s[i]].push_back(i);
      // printf("i = %d\n", i);
    }
    for (auto it : m) {
      // cout << it.first << " -> ";
      for (auto i : it.second) {
        // cout << i << ' ';
        for (int j = 1, cnt = 0; cnt < k && i + j <= len; ++cnt, ++j) {
          v.insert(s.substr(i, j));
        }
      }
      if (v.size() >= k) {
        break;
      }
    }
    int i = 0;
    for (auto it : v) {
      ++i;
      if (i == k) {
        cout << it << ' ';
        break;
      }
    }
    cout << endl;
    // break;
    // for (int i = 0; i < len; ++i) {
    //   for (int j = 1; i+j <= len; ++j) {
    //     v.push_back(s.substr(i, j));
    //   }
    // }
    // cout << "s=" << s << endl;
    // for (auto it : v) {
    //   cout << it << ' ';
    // } cout << endl;
    // sort(v.begin(), v.end());
    // auto it = unique(v.begin(), v.end());
    // v.resize(distance(v.begin(),it));
    // cout << v[k-1] << endl;
    // for (auto it : v) {
    //   cout << it << ' ';
    // } cout << endl;
  }
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 5050
int K, n;
struct A {
  char s[10];
  bool operator<(const A &x) const { return strcmp(s, x.s) < 0; }
  bool operator==(const A &x) const { return strcmp(s, x.s) == 0; }
} a[N];
char s[N];
int main() {
  int cnt = 0;
  scanf("%s%d", s, &K);
  int i, j, k;
  n = strlen(s);
  for (i = 0; i < n; i++) {
    for (j = 1; j <= 5 && i + j - 1 < n; j++) {
      ++cnt;
      for (k = i; k <= i + j - 1; k++)
        a[cnt].s[k - i] = s[k];
    }
  }
  sort(a + 1, a + cnt + 1);
  cnt = unique(a + 1, a + cnt + 1) - a - 1;
  printf("%s\n", a[K].s);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 5050
int K, n;
struct A {
  char s[10];
  bool operator<(const A &x) const { return strcmp(s, x.s) < 0; }
  bool operator==(const A &x) const { return strcmp(s, x.s) == 0; }
} a[N << 3];
char s[N];
int main() {
  int cnt = 0;
  scanf("%s%d", s, &K);
  int i, j, k;
  n = strlen(s);
  for (i = 0; i < n; i++) {
    for (j = 1; j <= 5 && i + j - 1 < n; j++) {
      ++cnt;
      for (k = i; k <= i + j - 1; k++)
        a[cnt].s[k - i] = s[k];
    }
  }
  sort(a + 1, a + cnt + 1);
  cnt = unique(a + 1, a + cnt + 1) - a - 1;
  printf("%s\n", a[K].s);
}
Problem p03355 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  string s;
  int k;
  cin >> s >> k;
  ll n = s.size();
  set<string> vs;
  rep(i, 0, n) {
    rep(j, 1, k + 1) {
      string sij = s.substr(i, j);
      vs.insert(sij);
    }
  }
  auto ite = vs.begin();
  rep(i, 0, k) { ite++; }
  cout << *ite << endl;
}

Fixed submission:
#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  string s;
  int k;
  cin >> s >> k;
  ll n = s.size();
  set<string> vs;
  rep(i, 0, n) {
    rep(j, 1, k + 1) {
      string sij = s.substr(i, j);
      vs.insert(sij);
    }
  }
  auto ite = vs.begin();
  rep(i, 0, k - 1) { ite++; }
  cout << *ite << endl;
}
Problem p03355 (C++)

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

using namespace std;

#ifndef errOut
#define errOut(s)
#endif

std::string calc(const std::string &s, int k) {
  std::multimap<char, int> startIdxes;
  std::set<std::string> ss;
  for (int idx = 0; idx < s.length(); ++idx) {
    char const ch = s[idx];
    startIdxes.insert(std::make_pair(ch, idx));
  }
  for (char ch = 'a'; ch <= 'z'; ++ch) {
    auto chItr = startIdxes.find(ch);
    if (chItr == startIdxes.end()) {
      continue;
    }
    for (auto itr = chItr; itr != startIdxes.end() && itr->first == ch; ++itr) {
      int const startIdx = itr->second;
      for (int len = 1; startIdx + len <= s.size(); ++len) {
        ss.insert(s.substr(itr->second, len));
      }
    }
    if (ss.size() >= k) {
      break;
    }
  }
  auto itr = ss.begin();
  for (int idx = 1; idx < k; ++idx, ++itr) {
  }
  return *itr;
}

int main() {
  std::string s;
  int k;
  std::cin >> s;
  std::cin >> k;
  std::cout << calc(s, k) << std::endl;
  return 0;
}


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

using namespace std;

#ifndef errOut
#define errOut(s)
#endif

std::string calc(const std::string &s, int k) {
  std::multimap<char, int> startIdxes;
  std::set<std::string> ss;
  for (int idx = 0; idx < s.length(); ++idx) {
    char const ch = s[idx];
    startIdxes.insert(std::make_pair(ch, idx));
  }
  for (char ch = 'a'; ch <= 'z'; ++ch) {
    auto chItr = startIdxes.find(ch);
    if (chItr == startIdxes.end()) {
      continue;
    }
    for (auto itr = chItr; itr != startIdxes.end() && itr->first == ch; ++itr) {
      int const startIdx = itr->second;
      for (int len = 1; startIdx + len <= s.size(); ++len) {
        std::string const substr = s.substr(itr->second, len);
        if (ss.find(substr) != ss.end()) {
          continue;
        }
        if (ss.size() >= k) {
          auto itr = ss.end();
          --itr;
          if (substr >= *itr) {
            break;
          } else {
            ss.erase(itr);
          }
        }
        ss.insert(substr);
      }
    }
    if (ss.size() >= k) {
      break;
    }
  }
  auto itr = ss.begin();
  for (int idx = 1; idx < k; ++idx, ++itr) {
  }
  return *itr;
}

int main() {
  std::string s;
  int k;
  std::cin >> s;
  std::cin >> k;
  std::cout << calc(s, k) << std::endl;
  return 0;
}
Problem p03355 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> a;
  rep(i, n) {
    for (int j = 1; j <= k; ++j) {
      if (i + j > n)
        continue;
      a.pb(s.substr(i, j));
    }
  }
  sort(a.begin(), a.end());
  a.pb("");
  int j = 1;
  rep(i, a.size()) {
    if (i == j) {
      cout << a.at(i) << endl;
      return 0;
    }
    if (a.at(i) != a.at(i + 1))
      j++;
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> a;
  rep(i, n) {
    for (int j = 1; j <= k; ++j) {
      if (i + j > n)
        continue;
      a.pb(s.substr(i, j));
    }
  }
  sort(a.begin(), a.end());
  a.pb("");
  int j = 1;
  rep(i, a.size()) {
    if (j == k) {
      cout << a.at(i) << endl;
      return 0;
    }
    if (a.at(i) != a.at(i + 1))
      j++;
  }
}
Problem p03355 (C++)

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

int main() {
  set<string> st;
  string s;
  cin >> s;
  int K;
  cin >> K;

  for (int i = 0; i < s.size(); i++) {
    string temp = "";
    for (int j = i; j < s.size(); j++) {
      temp += s[j];
      st.insert(temp);
    }
  }
  for (int i = 0; i < K - 1; i++) {
    st.erase(st.begin());
  }
  auto itr = st.begin();
  cout << *itr << endl;
  return 0;
}

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

int main() {
  set<string> st;
  string s;
  cin >> s;
  int K;
  cin >> K;

  for (int i = 0; i < s.size(); i++) {
    string temp = "";
    for (int j = i; j < i + K; j++) {
      if (j >= s.size())
        break;
      temp += s[j];
      st.insert(temp);
    }
  }
  for (int i = 0; i < K - 1; i++) {
    st.erase(st.begin());
  }
  auto itr = st.begin();
  cout << *itr << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define divup(a, b) (((a) + ((b)-1u)) / (b)) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
bool cmp(string a, string b) {
  ll sa = a.size();
  ll sb = b.size();
  bool fa = true;
  rep(i, min(sa, sb)) {
    if (a[i] != b[i])
      return a[i] < b[i];
  }
  return sa < sb;
}
signed main() {
  string s;
  ll k;
  cin >> s >> k;
  vector<string> s1;
  ll ss = s.size();
  rep(i, ss) {
    for (ll j = 0; (i + j < ss || j < 5); j++) {
      s1.push_back(s.substr(i, j + 1));
    }
  }
  sort(s1.begin(), s1.end(), cmp);
  unique(s1.begin(), s1.end());
  cout << s1[k - 1] << endl;
}


Fixed submission:
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define divup(a, b) (((a) + ((b)-1u)) / (b)) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
bool cmp(string a, string b) {
  ll sa = a.size();
  ll sb = b.size();
  bool fa = true;
  rep(i, min(sa, sb)) {
    if (a[i] != b[i])
      return a[i] < b[i];
  }
  return sa < sb;
}
signed main() {
  string s;
  ll k;
  cin >> s >> k;
  vector<string> s1;
  ll ss = s.size();
  rep(i, ss) {
    for (ll j = 0; (i + j < ss && j < 5); j++) {
      s1.push_back(s.substr(i, j + 1));
    }
  }
  sort(s1.begin(), s1.end(), cmp);
  unique(s1.begin(), s1.end());
  cout << s1[k - 1] << endl;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>

using namespace std;

char s[5005];
int len, K, sum;
bool buc[30];

struct Trie {
  int c[30], pre;
  char ch;
} tr[5005];
int cnt;
void insert(int pos) {
  int now = 0;
  for (int i = pos; i <= len; i++) {
    if (tr[now].c[s[i] - 'a'])
      now = tr[now].c[s[i] - 'a'];
    else {
      tr[now].c[s[i] - 'a'] = ++cnt;
      tr[cnt].pre = now;
      tr[cnt].ch = s[i];
      now = cnt;
    }
  }
}

char ans[5005];
void print(int x) {
  while (x) {
    ans[++ans[0]] = tr[x].ch;
    x = tr[x].pre;
  }
  for (int i = ans[0]; i; i--)
    putchar(ans[i]);
}

bool findAns;
void dfs(int x) {
  if (findAns)
    return;
  if (sum == K) {
    findAns = 1;
    print(x);
    return;
  }
  for (int i = 'a'; i <= 'z'; i++)
    if (tr[x].c[i - 'a'])
      sum++, dfs(tr[x].c[i - 'a']);
}

int main() {
  scanf("%s", s + 1);
  scanf("%d", &K);
  len = strlen(s + 1);
  for (int i = 1; i <= len; i++)
    buc[s[i] - 'a'] = 1;
  for (int c = 0; c < 26; c++)
    if (buc[c]) {
      cnt = 0;
      memset(tr, 0, sizeof tr);
      for (int i = 1; i <= len; i++)
        if (s[i] == c + 'a')
          insert(i);
      dfs(0);
      if (findAns)
        break;
    }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>

using namespace std;

char s[5005];
int len, K, sum;
bool buc[30];

struct Trie {
  int c[30], pre;
  char ch;
} tr[3000005];
int cnt;
void insert(int pos) {
  int now = 0;
  for (int i = pos; i <= len; i++) {
    if (tr[now].c[s[i] - 'a'])
      now = tr[now].c[s[i] - 'a'];
    else {
      tr[now].c[s[i] - 'a'] = ++cnt;
      tr[cnt].pre = now;
      tr[cnt].ch = s[i];
      now = cnt;
    }
  }
}

char ans[5005];
void print(int x) {
  while (x) {
    ans[++ans[0]] = tr[x].ch;
    x = tr[x].pre;
  }
  for (int i = ans[0]; i; i--)
    putchar(ans[i]);
}

bool findAns;
void dfs(int x) {
  if (findAns)
    return;
  if (sum == K) {
    findAns = 1;
    print(x);
    return;
  }
  for (int i = 'a'; i <= 'z'; i++)
    if (tr[x].c[i - 'a'])
      sum++, dfs(tr[x].c[i - 'a']);
}

int main() {
  scanf("%s", s + 1);
  scanf("%d", &K);
  len = strlen(s + 1);
  for (int i = 1; i <= len; i++)
    buc[s[i] - 'a'] = 1;
  for (int c = 0; c < 26; c++)
    if (buc[c]) {
      cnt = 0;
      memset(tr, 0, sizeof tr);
      for (int i = 1; i <= len; i++)
        if (s[i] == c + 'a')
          insert(i);
      dfs(0);
      if (findAns)
        break;
    }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const double EPS = 1e-10;
const ll mod = 1000000007;
// const ll mod=998244353;
int main(void) {
  set<string> SET;
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  for (int i = 0; i < n; i++) {
    string t;
    for (int j = i; j < n; j++) {
      t += s[j];
      SET.insert(t);
    }
  }
  auto itr = SET.begin();
  for (int i = 0; i < k - 1; i++)
    itr++;
  cout << *itr << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const double EPS = 1e-10;
const ll mod = 1000000007;
// const ll mod=998244353;
int main(void) {
  set<string> SET;
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  for (int i = 0; i < n; i++) {
    string t;
    for (int j = i; j < n && j - i <= k; j++) {
      t += s[j];
      SET.insert(t);
    }
  }
  auto itr = SET.begin();
  for (int i = 0; i < k - 1; i++)
    itr++;
  cout << *itr << endl;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 810114514
#define YES(s) s ? cout << "YES" << endl : cout << "NO" << endl
#define Yes(s) s ? cout << "Yes" << endl : cout << "No" << endl
#define Taka(s) s ? cout << "Takahashi" << endl : cout << "Aoki" << endl
#define int long long

signed main() {
  string s;
  string G[6000];
  int Gle = 0;
  int num = 0;
  int K;
  cin >> s >> K;
  REP(i, 26) {
    Gle = 0;
    REP(j, s.size()) {
      if (s[j] == (char)('a' + i)) {
        for (int k = j; k < s.size() && k - j < 5; k++) {
          G[Gle] = s.substr(j, k - j + 1);
          // cout <<j <<"sub  "<< G[Gle] << endl;
          Gle++;
        }
      }
    }
    sort(G, G + Gle);
    // cout << "GLEM " ;REP(k,Gle){cout << G[k] << "   ";}cout << endl;
    REP(j, Gle) {
      if (j == 0 || (j != 0 && G[j] != G[j - 1])) {
        num++;
        // cout << num << "  " << G[j] << endl;
      }
      if (num == K) {
        cout << G[j] << endl;
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 810114514
#define YES(s) s ? cout << "YES" << endl : cout << "NO" << endl
#define Yes(s) s ? cout << "Yes" << endl : cout << "No" << endl
#define Taka(s) s ? cout << "Takahashi" << endl : cout << "Aoki" << endl
#define int long long

signed main() {
  string s;
  string G[100000];
  int Gle = 0;
  int num = 0;
  int K;
  cin >> s >> K;
  REP(i, 26) {
    Gle = 0;
    REP(j, s.size()) {
      if (s[j] == (char)('a' + i)) {
        for (int k = j; k < s.size() && k - j < 5; k++) {
          G[Gle] = s.substr(j, k - j + 1);
          // cout <<j <<"sub  "<< G[Gle] << endl;
          Gle++;
        }
      }
    }
    sort(G, G + Gle);
    // cout << "GLEM " ;REP(k,Gle){cout << G[k] << "   ";}cout << endl;
    REP(j, Gle) {
      if (j == 0 || (j != 0 && G[j] != G[j - 1])) {
        num++;
        // cout << num << "  " << G[j] << endl;
      }
      if (num == K) {
        cout << G[j] << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
// ProblemC

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// ProblemC

class Solve {
private:
  void solve() {
    string s;
    int k;
    cin >> s >> k;

    auto t = s;
    std::partial_sort(t.begin(), t.begin() + min(5, (int)s.length()), t.end());
    t.resize(5, ' ');
    unordered_set<char> okc(t.begin(), t.end());

    set<string> ss;
    for (size_t i = 0; i < s.length(); i++) {
      if (okc.find(s[i]) != okc.end()) {
        for (size_t j = 1; i + j <= s.length(); j++) {
          ss.insert(s.substr(i, j));
        }
      }
    }
    auto it = ss.begin();
    for (int i = 1; i < k; i++)
      ++it;
    cout << *it << endl;
  }

public:
  Solve() { solve(); }
};

int main(int argc, char *argv[]) {
  unique_ptr<Solve> solve = make_unique<Solve>();
  return 0;
}


Fixed submission:
// ProblemC

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// ProblemC

class Solve {
private:
  void solve() {
    string s;
    int k;
    cin >> s >> k;

    auto t = s;
    std::partial_sort(t.begin(), t.begin() + min(5, (int)s.length()), t.end());
    t.resize(5, ' ');
    unordered_set<char> okc(t.begin(), t.end());

    set<string> ss;
    for (size_t i = 0; i < s.length(); i++) {
      if (okc.find(s[i]) != okc.end()) {
        for (size_t j = 1; i + j <= s.length() && j <= 5; j++) {
          ss.insert(s.substr(i, j));
        }
      }
    }
    auto it = ss.begin();
    for (int i = 1; i < k; i++)
      ++it;
    cout << *it << endl;
  }

public:
  Solve() { solve(); }
};

int main(int argc, char *argv[]) {
  unique_ptr<Solve> solve = make_unique<Solve>();
  return 0;
}
Problem p03355 (C++)

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

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

  vector<string> vec;
  int len = s.length();
  for (int i = 0; i < len; ++i) {
    int sublen = len - i;
    string sub = "";
    for (int j = 0; j < sublen; ++j) {
      sub += s[i + j];
      vec.push_back(sub);
    }
  }

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

  k--;
  cout << vec[k] << "\n";

  return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

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

  vector<string> vec;
  int len = s.length();
  for (int l = 0; l < len; ++l) {
    for (int r = l + 1; r <= len && r - l <= 5; ++r) {
      vec.push_back(s.substr(l, r - l));
    }
  }

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

  k--;
  cout << vec[k] << "\n";

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

string s;
int N, K;
string t[5 * 5000];

int main(int argc, char *argv[]) {
  cin >> s;
  cin >> K;
  N = s.length();

  int k = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j <= i + K; j++) {
      t[k] = s.substr(i, j - i);
      k++;
    }
  }
  sort(t, t + k);
  int i;
  for (i = 0; i < k; i++) {
    if (t[i] != t[i + 1])
      K--;
    if (K == 0)
      break;
  }
  cout << t[i] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

string s;
int N, K;
string t[5 * 5000];

int main(int argc, char *argv[]) {
  cin >> s;
  cin >> K;
  N = s.length();

  int k = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      if (i + j - 1 >= N)
        continue;
      t[k] = s.substr(i, j);
      k++;
    }
  }
  sort(t, t + k);
  int i;
  for (i = 0; i < k; i++) {
    if (t[i] != t[i + 1])
      K--;
    if (K == 0)
      break;
  }
  cout << t[i] << endl;

  return 0;
}