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

Buggy submission (status: Time Limit Exceeded):
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-05 17:22:34
*/

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

#define all(x) (x).begin(), (x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

LL modpower(LL n, LL m, LL mod) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    LL p = modpower(n, m / 2, mod);
    return p * p % mod;
  } else {
    return n * modpower(n, m - 1, mod) % mod;
  }
}

LL modinv(LL n, LL mod) { return modpower(n, mod - 2, mod); }

LL modcombination(LL n, LL r, LL mod) {
  LL ret = 1;

  for (int i = 0; i < r; i++) {
    ret *= (n - i);
    ret %= mod;
    ret *= modinv(i + 1, mod);
    ret % mod;
  }

  return ret % mod;
}

int gcd(int k, int l) {
  if (l > 0)
    return gcd(l, k % l);
  else
    return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

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

  int m = 0;
  string ans;
  for (const auto &x : dict) {
    if (++m == k) {
      ans = x.first;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-05 17:22:34
*/

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

#define all(x) (x).begin(), (x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

LL modpower(LL n, LL m, LL mod) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    LL p = modpower(n, m / 2, mod);
    return p * p % mod;
  } else {
    return n * modpower(n, m - 1, mod) % mod;
  }
}

LL modinv(LL n, LL mod) { return modpower(n, mod - 2, mod); }

LL modcombination(LL n, LL r, LL mod) {
  LL ret = 1;

  for (int i = 0; i < r; i++) {
    ret *= (n - i);
    ret %= mod;
    ret *= modinv(i + 1, mod);
    ret % mod;
  }

  return ret % mod;
}

int gcd(int k, int l) {
  if (l > 0)
    return gcd(l, k % l);
  else
    return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

  int n = s.length();
  map<string, int> dict;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      dict[s.substr(i, j)]++;
    }
  }

  int m = 0;
  string ans;
  for (const auto &x : dict) {
    if (++m == k) {
      ans = x.first;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
  string S;
  int K;
  cin >> S >> K;
  int cnt = S.size();
  set<string> st;
  for (int i = 0; i < cnt; i++) {
    for (int j = 1; j < min(K + 1, cnt - i); j++) {
      st.insert(S.substr(i, j));
    }
  }
  auto itr = st.begin();
  for (int i = 0; i < K - 1; i++) {
    ++itr;
  }
  cout << *itr << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
  string S;
  int K;
  cin >> S >> K;
  int cnt = S.size();
  set<string> st;
  for (int i = 0; i < cnt; i++) {
    for (int j = 1; j <= min(K + 1, cnt - i); j++) {
      st.insert(S.substr(i, j));
    }
  }
  auto itr = st.begin();
  for (int i = 0; i < K - 1; i++) {
    ++itr;
  }
  cout << *itr << endl;
}
Problem p03353 (C++)

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

set<string> ms;
set<string>::iterator it;

int main() {
  string s, sub;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    for (int j = 1; j + i <= s.size(); j++) {
      sub = s.substr(i, j);
      ms.insert(sub);
    }

  int cnt = 0;
  for (it = ms.begin(); it != ms.end(); it++) {
    cnt++;
    if (cnt == k) {
      cout << *it << endl;
      return 0;
    }
  }
  return 0;
}

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

set<string> ms;
set<string>::iterator it;

int main() {
  string s, sub;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    for (int j = 1; j <= 5; j++) {
      sub = s.substr(i, j);
      ms.insert(sub);
    }

  int cnt = 0;
  for (it = ms.begin(); it != ms.end(); it++) {
    cnt++;
    if (cnt == k) {
      cout << *it << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

  set<string> st;
  vector<vector<string>> v(k);

  REP(i, min((int)s.size(), 5)) {

    if (i == 0) {
      char c = 'a';
      while (c <= 'z' && v[i].size() < 5) {
        string tmp(1, c);
        if (s.find(tmp) != string::npos) {
          v[i].push_back(tmp);
          st.insert(tmp);
        }
        c++;
      }
    } else {
      for (auto ss : v[i - 1]) {
        char c = 'a';
        while (c <= 'z' && v[i].size() < 5) {
          string tmp = ss + c;
          if (s.find(tmp) != string::npos) {
            v[i].push_back(tmp);
            st.insert(tmp);
          }
          c++;
        }
      }
    }
    // cerr << st.size() << endl;
  }

  auto it = st.begin();
  REP(i, k - 1) it++;
  OUT(*it);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

  set<string> st;
  vector<vector<string>> v(5);

  REP(i, min((int)s.size(), 5)) {

    if (i == 0) {
      char c = 'a';
      while (c <= 'z' && v[i].size() < 5) {
        string tmp(1, c);
        if (s.find(tmp) != string::npos) {
          v[i].push_back(tmp);
          st.insert(tmp);
        }
        c++;
      }
    } else {
      for (auto ss : v[i - 1]) {
        char c = 'a';
        while (c <= 'z' && v[i].size() < 5) {
          string tmp = ss + c;
          if (s.find(tmp) != string::npos) {
            v[i].push_back(tmp);
            st.insert(tmp);
          }
          c++;
        }
      }
    }
    // cerr << st.size() << endl;
  }

  auto it = st.begin();
  REP(i, k - 1) it++;
  OUT(*it);

  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  int K;
  vector<string> sub_s;
  cin >> s >> K;
  for (int i = 0; i < s.length(); i++) {
    for (int j = i; j < s.length(); j++) {
      sub_s.push_back(s.substr(i, j - i + 1));
      sort(sub_s.begin(), sub_s.end());
      unique(sub_s.begin(), sub_s.end());
      if (sub_s.size() >= 6)
        sub_s.pop_back();
    }
  }
  cout << sub_s[K - 1] << endl;
  return 0;
}


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

int main() {
  string s;
  int K;
  vector<string> sub_s;
  cin >> s >> K;
  for (int i = 0; i < s.length(); i++) {
    for (int j = i; j < i + 5; j++) {
      sub_s.push_back(s.substr(i, j - i + 1));
      sort(sub_s.begin(), sub_s.end());
      unique(sub_s.begin(), sub_s.end());
      if (sub_s.size() >= 6)
        sub_s.pop_back();
    }
  }
  cout << sub_s[K - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
typedef pair<int, int> P;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  vector<int> t;
  int n = sz(s);
  rep(i, n) {
    string tmp = "";
    tmp.push_back(s[i]);
    st.insert(tmp);
    REP(j, i + 1, n) {
      tmp.push_back(s[j]);
      st.insert(tmp);
    }
  }
  int cnt = 0;
  for (auto it = st.begin(); it != st.end(); it++) {
    cnt++;
    if (cnt < k)
      continue;
    cout << *it << endl;
    return 0;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
typedef pair<int, int> P;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  vector<int> t;
  int n = sz(s);
  rep(i, n) {
    string tmp = "";
    tmp.push_back(s[i]);
    st.insert(tmp);
    REP(j, i + 1, min(n, i + k)) {
      tmp.push_back(s[j]);
      st.insert(tmp);
    }
  }
  int cnt = 0;
  for (auto it = st.begin(); it != st.end(); it++) {
    cnt++;
    if (cnt < k)
      continue;
    cout << *it << endl;
    return 0;
  }
}
Problem p03353 (C++)

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

int main() {
  std::string s;
  std::cin >> s;
  int K;
  scanf("%d", &K);
  int n = s.length();
  std::vector<std::string> vec;
  for (int i = 0; i < n; i++) {
    std::string moji;
    // std::cout << "S[" << i << "]=" << s[i] << std::endl;
    // std::cout << "moji=" << moji << std::endl;
    for (int j = i; j < n; j++) {
      moji += s[j];
      // std::cout << "Sj[" << j << "]=" << s[j] << std::endl;
      vec.push_back(moji);
      // std::cout << "moji=" << moji << std::endl;
    }
  }
  std::sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  // printf("size=%lu\n", vec.size());
  std::cout << vec[K - 1] << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

int main() {
  std::string s;
  std::cin >> s;
  int K;
  scanf("%d", &K);
  int n = s.length();
  std::vector<std::string> vec;
  for (int i = 0; i < n; i++) {
    std::string moji;
    // std::cout << "S[" << i << "]=" << s[i] << std::endl;
    // std::cout << "moji=" << moji << std::endl;
    for (int j = i; j < std::min(i + 6, n); j++) {
      moji += s[j];
      // std::cout << "Sj[" << j << "]=" << s[j] << std::endl;
      vec.push_back(moji);
      // std::cout << "moji=" << moji << std::endl;
    }
  }
  std::sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  // printf("size=%lu\n", vec.size());
  std::cout << vec[K - 1] << std::endl;
  return 0;
}
Problem p03353 (C++)

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

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

  std::vector<std::string> v;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = 5; j <= n - i; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());

  std::cout << v[k - 1] << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

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

  std::vector<std::string> v;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 5; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());

  std::cout << v[k - 1] << std::endl;
  return 0;
}
Problem p03353 (C++)

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

template <typename T> void print(const T &v);

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

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T> void print(const T &v);

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

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}
Problem p03353 (C++)

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

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

  std::vector<std::string> v;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= n - i; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());

  std::cout << v[k - 1] << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

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

  std::vector<std::string> v;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= n - i; j++) {
      std::string t = s.substr(i, j);
      if (t.size() <= k) {
        v.push_back(t);
      }
    }
  }
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());

  std::cout << v[k - 1] << std::endl;
  return 0;
}
Problem p03353 (C++)

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

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

  cin >> s;
  cin >> K;

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

  set<string> s2(str.begin(), str.end());
  vector<string> vec(s2.begin(), s2.end());

  cout << vec.at(K - 1) << endl;
}


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

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

  cin >> s;
  cin >> K;

  for (int i = 0; s.size() > i && K > i; i++) {
    for (int j = 0; s.size() > j + i; j++) {
      str.push_back(s.substr(j, i + 1));
    }
  }

  set<string> s2(str.begin(), str.end());
  vector<string> vec(s2.begin(), s2.end());

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  set<string> sub;
  REP(i, s.size()) {
    for (ll j = 1; j <= (ll)s.size() - i; j++) {
      sub.insert(s.substr(i, j));
    }
  }

  int index = 1;
  string ans;
  for (auto x : sub) {
    if (index == k) {
      ans = x;
      break;
    }
    index++;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  set<string> sub;
  REP(i, s.size()) {
    for (ll j = 1; j <= k; j++) {
      sub.insert(s.substr(i, j));
    }
  }

  int index = 1;
  string ans;
  for (auto x : sub) {
    if (index == k) {
      ans = x;
      break;
    }
    index++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  unordered_set<string> st;
  vector<string> substring;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      string result = "";
      if (i - j + 1 <= k) {
        for (int l = i; l <= j; l++) {
          result += s[l];
        }
        if (result == "") {
          continue;
        } else {
          if (st.find(result) == st.end()) {
            substring.push_back(result);
            st.insert(result);
          }
        }
      }
    }
  }
  sort(substring.begin(), substring.end());
  cout << substring[k - 1];
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  unordered_set<string> st;
  vector<string> substring;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      string result = "";
      if (j - i + 1 <= k) {
        for (int l = i; l <= j; l++) {
          result += s[l];
        }
        if (result == "") {
          continue;
        } else {
          if (st.find(result) == st.end()) {
            substring.push_back(result);
            st.insert(result);
          }
        }
      }
    }
  }
  sort(substring.begin(), substring.end());
  cout << substring[k - 1];
}
Problem p03353 (C++)

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> se;
  int i, j;
  for (i = 0; i < s.size(); ++i) {
    for (j = 1; j <= s.size() - i; ++j) {
      se.insert(s.substr(i, j));
    }
  }
  vector<string> array;
  for (string x : se) {
    array.push_back(x);
  }
  sort(array.begin(), array.end());
  cout << array.at(k - 1) << endl;
  return 0;
}

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> se;
  int i, j;
  for (i = 0; i < s.size(); ++i) {
    for (j = 1; j <= k; ++j) {
      se.insert(s.substr(i, j));
    }
  }
  vector<string> array;
  for (string x : se) {
    array.push_back(x);
  }
  sort(array.begin(), array.end());
  cout << array.at(k - 1) << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

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

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> us;
  int n = s.size();
  rep(i, n) {
    reps(j, n - i + 1, 1) { us.insert(s.substr(i, j)); }
  }
  vector<string> dict(us.begin(), us.end());
  sort(dict.begin(), dict.end());
  cout << dict[k - 1] << endl;
  return 0;
}

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> us;
  int n = s.size();
  rep(i, n) {
    reps(j, n - i + 1, 1) {
      if (j > k)
        break;
      us.insert(s.substr(i, j));
    }
  }
  vector<string> dict(us.begin(), us.end());
  sort(dict.begin(), dict.end());
  cout << dict[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

  vector<string> subs(K);
  for (int i = 0; i < S.size(); i++) {
    for (int j = i; j < S.size(); j++) {
      string s = S.substr(i, j - i + 1);
      for (int k = 0; k < K; k++) {
        if (s == subs[k])
          break;
        if (s < subs[k] || subs[k].empty()) {
          subs.insert(subs.begin() + k, s);
          subs.pop_back();
          break;
        }
      }
    }
  }

  cout << subs.back() << endl;
}

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

using namespace std;

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

  vector<string> subs(K);
  for (int i = 0; i < S.size(); i++) {
    for (int j = i; j < S.size(); j++) {
      string s = S.substr(i, j - i + 1);
      if (!subs.back().empty() && s >= subs.back())
        break;

      for (int k = 0; k < K; k++) {
        if (s == subs[k])
          break;
        if (s < subs[k] || subs[k].empty()) {
          subs.insert(subs.begin() + k, s);
          subs.pop_back();
          break;
        }
      }
    }
  }

  cout << subs.back() << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <vector>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  REP(i, s.length()) {
    rep(j, i, s.length()) { st.insert(s.substr(i, j - i + 1)); }
  }
  int cnt = 1;
  for (auto i : st) {
    if (cnt == k) {
      cout << i << endl;
      break;
    }
    cnt++;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <vector>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  REP(i, s.length()) {
    rep(j, i, s.length()) {
      if (j - i + 1 > k)
        break;
      st.insert(s.substr(i, j - i + 1));
    }
  }
  int cnt = 1;
  for (auto i : st) {
    if (cnt == k) {
      cout << i << endl;
      break;
    }
    cnt++;
  }
}
Problem p03353 (C++)

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

using namespace std;

int main(int argc, const char *argv[]) {
  vector<string> arr;
  map<string, bool> m;
  string s;
  int k;
  cin >> s >> k;
  string tmp;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      tmp = s.substr(i, j);
      if (m[tmp] != true) {
        m[tmp] = true;
        arr.push_back(tmp);
      }
    }
  }
  sort(arr.begin(), arr.end());
  cout << arr[k - 1] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <type_traits>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  vector<string> arr;
  map<string, bool> m;
  string s;
  int k;
  cin >> s >> k;
  string tmp;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= min(k, (int)s.size() - i); j++) {
      tmp = s.substr(i, j);
      if (m[tmp] != true) {
        m[tmp] = true;
        arr.push_back(tmp);
      }
    }
  }
  sort(arr.begin(), arr.end());
  cout << arr[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

  int k;
  cin >> k;

  int size = s.size();
  vector<string> list;

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

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

  string previous = list[0];
  for (int i = 1, j = 1; i < k; j++) {
    if (list[j] != previous) {
      i++;
      previous = list[j];
    }
  }

  cout << previous << endl;
  return 0;
}


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

using namespace std;

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

  int k;
  cin >> k;

  int size = s.size();
  vector<string> list;

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

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

  string previous = list[0];
  for (int i = 1, j = 1; i < k; j++) {
    if (list[j] != previous) {
      i++;
      previous = list[j];
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
/*
        Author: ankrypt
*/

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

string S = "";
std::set<string> V;
ll K;

int main() {
  cin >> S;
  scanf("%lld", &K);
  for (int i = 1; i <= S.size(); i++) {
    for (int j = 0; j <= S.size() - i; j++) {
      V.insert(S.substr(j, i));
      // if(V.size() >= 5) {}
    }
  }
  // sort(V.begin(), V.end());
  set<string>::iterator itr;
  ll cnt = 0;
  for (itr = V.begin(); itr != V.end(); itr++) {
    cnt++;
    if (cnt == K) {
      cout << *itr << " ";
      break;
    }
  }
  // auto itr = V.begin() + K;
  // advance(itr, K - 1);
  // cout << *itr << " ";

  return 0;
}
/*
        Powered by Buggy Plugin
*/


Fixed submission:
/*
        Author: ankrypt
*/

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

string S = "";
std::set<string> V;
ll K;

int main() {
  cin >> S;
  scanf("%lld", &K);
  int sz = S.size();
  for (int i = 1; i <= min(5, sz); i++) {
    for (int j = 0; j <= S.size() - i; j++) {
      V.insert(S.substr(j, i));
      // if(V.size() >= 5) {}
    }
  }
  // sort(V.begin(), V.end());
  set<string>::iterator itr;
  ll cnt = 0;
  for (itr = V.begin(); itr != V.end(); itr++) {
    cnt++;
    if (cnt == K) {
      cout << *itr << " ";
      break;
    }
  }
  // auto itr = V.begin() + K;
  // advance(itr, K - 1);
  // cout << *itr << " ";

  return 0;
}
/*
        Powered by Buggy Plugin
*/
Problem p03353 (C++)

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> subs;
  int len = s.size();

  for (int i = 0; i < len; i++) {
    for (int j = 1; j < k; j++) {
      if (i + j < len) {
        subs.push_back(s.substr(i, j));
      }
    }
  }
  sort(subs.begin(), subs.end());
  unique(subs.begin(), subs.end());

  cout << subs.at(k - 1) << endl;
}

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> subs;
  int len = s.size();

  for (int i = 0; i < len; i++) {
    for (int j = 1; j <= k; j++) {
      if (i + j <= len) {
        subs.push_back(s.substr(i, j));
      }
    }
  }
  sort(subs.begin(), subs.end());
  unique(subs.begin(), subs.end());

  cout << subs.at(k - 1) << endl;
}
Problem p03353 (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 REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;

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

  vector<string> sub;
  map<string, bool> mp;
  REP2(i, 1, k) {
    REP(j, s.size()) {
      string temp = s.substr(j, i);
      if (mp[temp])
        continue;
      sub.emplace_back(temp);
      mp[temp] = 1;
    }
  }
  sort(ALL(sub));
  cout << sub[k - 1] << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;

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

  vector<string> sub;
  map<string, bool> mp;
  REP2(i, 1, min(k, int(s.size())) + 1) {
    REP(j, s.size()) {
      string temp = s.substr(j, i);
      if (mp[temp])
        continue;
      sub.emplace_back(temp);
      mp[temp] = 1;
    }
  }
  sort(ALL(sub));
  cout << sub[k - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

  vector<string> v;

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

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

  cout << v.at(K - 1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

  vector<string> v;

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

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

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

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

using namespace std;

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

  vector<string> subs;
  subs.reserve(1000000);
  int size = s.size();
  for (int i = 0; i < size; ++i) {
    for (int j = 1; i + j <= size; ++j) {
      string sub = s.substr(i, j);
      for (int k = 0; k < num; ++k) {
        int subsSize = subs.size();
        if (subsSize <= k) {
          subs.push_back(sub);
          break;
        }

        if (subs[k] == sub) {
          break;
        }

        if (subs[k] > sub) {
          subs.insert(subs.begin() + k, sub);
          break;
        }
      }
    }
  }

  cout << subs[num - 1] << endl;

  return 0;
}

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

using namespace std;

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

  vector<string> subs;
  subs.reserve(1000000);
  int size = s.size();
  for (int i = 0; i < size; ++i) {
    for (int j = 1; i + j <= size && j <= 5; ++j) {
      string sub = s.substr(i, j);
      for (int k = 0; k < num; ++k) {
        int subsSize = subs.size();
        if (subsSize <= k) {
          subs.push_back(sub);
          break;
        }

        if (subs[k] == sub) {
          break;
        }

        if (subs[k] > sub) {
          subs.insert(subs.begin() + k, sub);
          break;
        }
      }
    }
  }

  cout << subs[num - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())
int main() {
  string s;
  vector<string> ans;
  int K;
  cin >> s >> K;
  rep(i, len(s)) {
    FOR(j, i, len(s)) {
      auto it = s.begin();
      string x;
      it += i;
      while (len(x) != (j - i + 1)) {
        x += *it;
        it++;
      }
      auto itr = find(ans.begin(), ans.end(), x);
      if (itr == ans.end() && len(x) <= 5) {
        ans.push_back(x);
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[K - 1] << endl;
}

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())
int main() {
  string s;
  vector<string> ans;
  int K;
  cin >> s >> K;
  rep(i, len(s)) {
    FOR(j, i, min(len(s), i + 5)) {
      auto it = s.begin();
      string x;
      it += i;
      while (len(x) != (j - i + 1)) {
        x += *it;
        it++;
      }
      auto itr = find(ans.begin(), ans.end(), x);
      if (itr == ans.end() && len(x) <= 5) {
        ans.push_back(x);
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[K - 1] << endl;
}
Problem p03353 (C++)

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

using namespace std;

#define inf 1 << 30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int main() {
  string s;
  int n;
  map<string, int> m;
  pqueue<string> q;
  cin >> s >> n;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      string in = s.substr(i, j);
      if (m[in])
        continue;
      if (q.size() < n)
        q.push(in);
      else if (q.top() > in)
        q.push(in);

      if (q.size() > n)
        q.pop();
      m[in]++;
    }
  }

  cout << q.top() << endl;
  return 0;
}

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

using namespace std;

#define inf 1 << 30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int main() {
  string s;
  int n;
  map<string, int> m;
  pqueue<string> q;
  cin >> s >> n;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      string in = s.substr(i, j);
      if (m[in])
        continue;
      if (q.size() < n)
        q.push(in);
      else if (q.top() > in)
        q.push(in);
      else
        break;

      if (q.size() > n)
        q.pop();
      m[in]++;
    }
  }

  cout << q.top() << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int k;
string s;
set<string> str;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> k;
  int n = (int)s.size();
  erep(i, 1, n) {
    rep(j, 0, n) { str.insert(s.substr(j, i)); }
  }
  auto itr = str.begin();
  rep(i, 1, k)++ itr;
  cout << *itr << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int k;
string s;
set<string> str;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> k;
  int n = (int)s.size();
  erep(i, 1, k) {
    rep(j, 0, n) { str.insert(s.substr(j, i)); }
  }
  auto itr = str.begin();
  rep(i, 1, k)++ itr;
  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  int K;

  cin >> s >> K;

  set<string> str;

  int len = s.length();
  for (int i = 0; i < len; i++) {
    for (int w = 0; i + w < len; w++) {
      str.insert(s.substr(i, w + 1));
    }
  }

  int cnt = 0;
  for (auto itr = str.begin(); itr != str.end(); itr++) {
    if (cnt == K - 1) {
      cout << *itr << endl;
    }
    cnt += 1;
  }

  return 0;
}


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

int main() {
  string s;
  int K;

  cin >> s >> K;

  set<string> str;

  int len = s.length();
  for (int i = 0; i < len; i++) {
    for (int w = 0; i + w < len; w++) {
      string t = s.substr(i, w + 1);
      str.insert(t);
      if (t.length() > K) {
        break;
      }
    }
  }

  int cnt = 0;
  for (auto itr = str.begin(); itr != str.end(); itr++) {
    if (cnt == K - 1) {
      cout << *itr << endl;
    }
    cnt += 1;
  }

  return 0;
}
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;

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

  int n = s.length();
  set<string> sets;
  for (int l = 0; l < n; ++l) {
    for (int r = l + 1; r <= n; ++r) {
      sets.insert(s.substr(l, r - l));
    }
  }
  auto itr = sets.begin();
  rep(i, k - 1)++ itr;
  cout << *itr << endl;
  return 0;
}

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;

  int n = s.length();
  set<string> sets;
  for (int l = 0; l < n; ++l) {
    for (int r = l + 1; r <= min(n, l + k); ++r) {
      sets.insert(s.substr(l, r - l));
    }
  }
  auto itr = sets.begin();
  rep(i, k - 1)++ itr;
  cout << *itr << endl;
  return 0;
}
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 FOR(i, start, end) for (int i = start; i <= end; i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

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

  rep(i, K - 1) { S.erase(S.begin()); }

  cout << *S.begin() << endl;
}


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

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

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

  rep(i, K - 1) { S.erase(S.begin()); }

  cout << *S.begin() << endl;
}
Problem p03353 (C++)

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64, i64> P;

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

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

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

  for (auto i = st.begin();; i++, k--) {
    if (k == 1) {
      cout << *i << endl;
      break;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64, i64> P;

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

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

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

  for (auto i = st.begin();; i++, k--) {
    if (k == 1) {
      cout << *i << endl;
      break;
    }
  }

  return 0;
}