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

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

using namespace std;

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

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

string s;
int k;
set<string> st;
void solve() {
  cin >> s;
  cin >> k;
  int n = s.size();

  for (int i = 0; i < n; i++) {
    for (int j = 1; j + i <= n; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto ans = st.begin();
  for (int i = 1; i < k; i++) {
    ans++;
  }
  cout << *ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

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

using namespace std;

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

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

string s;
int k;
set<string> st;
void solve() {
  cin >> s;
  cin >> k;
  int n = s.size();

  for (int i = 0; i < n; i++) {
    for (int j = 1; j + i <= n && j <= k; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto ans = st.begin();
  for (int i = 1; i < k; i++) {
    ans++;
  }
  cout << *ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Problem p03353 (C++)

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

#define rep(i, a) for (int i = 0; i < a; i++)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define triplerep(i, j, k, a)                                                  \
  for (int i = 0; i < a; i++)                                                  \
    for (int j = 0; j < a; j++)                                                \
      if (i != j)                                                              \
        for (int k = 0; k < a; k++)                                            \
          if (i != k && j != k)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a, b) scanf("%d%d", &a, &b)
#define scnd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scnd4(a, b, c, d) scanf("%d%d%d%d", &a, &b, &c, &d)

#define prtd1(a) printf("%d\n", a)
#define prtd2(a, b) printf("%d %d\n", a, b)
#define prtd3(a, b, c) printf("%d %d %d\n", a, b, c)
#define prtd4(a, b, c, d) printf("%d %d %d %d\n", a, b, c, d)

#define mem(a, n) memset(a, n, sizeof(a))

typedef long long ll;

int K;
string s;

void dfs(string st) {

  for (char c = 'a'; c <= 'z'; c++) {
    if (s.find(st + c) != string::npos) {
      if (--K == 0) {
        cout << st + c << endl;
        return;
      }
      if (K == 0)
        return;
      dfs(st + c);
    }
  }
}

int main(void) {

  cin >> s >> K;

  dfs("");
}


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

#define rep(i, a) for (int i = 0; i < a; i++)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define triplerep(i, j, k, a)                                                  \
  for (int i = 0; i < a; i++)                                                  \
    for (int j = 0; j < a; j++)                                                \
      if (i != j)                                                              \
        for (int k = 0; k < a; k++)                                            \
          if (i != k && j != k)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a, b) scanf("%d%d", &a, &b)
#define scnd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scnd4(a, b, c, d) scanf("%d%d%d%d", &a, &b, &c, &d)

#define prtd1(a) printf("%d\n", a)
#define prtd2(a, b) printf("%d %d\n", a, b)
#define prtd3(a, b, c) printf("%d %d %d\n", a, b, c)
#define prtd4(a, b, c, d) printf("%d %d %d %d\n", a, b, c, d)

#define mem(a, n) memset(a, n, sizeof(a))

typedef long long ll;

int K;
string s;

void dfs(string st) {

  for (char c = 'a'; c <= 'z'; c++) {
    if (s.find(st + c) != string::npos) {
      if (--K == 0) {
        cout << st + c << endl;
        return;
      }
      if (K <= 0)
        return;
      dfs(st + c);
    }
  }
}

int main(void) {

  cin >> s >> K;

  dfs("");
}
Problem p03353 (C++)

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

using namespace std;

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> p;
  for (int i = 0; i < s.size(); i++) {
    string t = "";
    for (int j = 0; j < s.size() - i; j++) {
      t += s[i + j];
      p.insert(t);
    }
  }
  rep(i, k - 1) { p.erase(p.begin()); }
  string ans = *p.begin();
  cout << ans << endl;
}

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

using namespace std;

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> p;
  for (int i = 0; i < s.size(); i++) {
    string t = "";
    for (int j = 0; j < s.size() - i && j < 6; j++) {
      t += s[i + j];
      p.insert(t);
    }
  }
  rep(i, k - 1) { p.erase(p.begin()); }
  string ans = *p.begin();
  cout << ans << endl;
}
Problem p03353 (C++)

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

using namespace std;

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

  vector<string> x;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j - 1 < s.size()) {
        x.push_back(s.substr(i, j));
      }
    }
  }
  sort(x.begin(), x.end());
  int tmp = 0;
  if (k == 1) {
    cout << x[0] << endl;
  } else {
    for (int i = 0; i < x.size(); i++) {
      if (x[i] != x[i + 1]) {
        tmp++;
      }

      if (tmp == k) {
        cout << x[i] << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

using namespace std;

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

  vector<string> x;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j - 1 < s.size()) {
        x.push_back(s.substr(i, j));
      }
    }
  }
  sort(x.begin(), x.end());
  int tmp = 0;
  if (k == 1) {
    cout << x[0] << endl;
  } else {
    for (int i = 0; i < x.size(); i++) {
      if (i == x.size() - 1) {
        cout << x[i] << endl;
        return 0;
      }

      if (x[i] != x[i + 1]) {
        tmp++;
      }

      if (tmp == k) {
        cout << x[i] << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      string tmp = s.substr(i, j);
      // cout<<tmp<<endl;
      mp[tmp]++;
    }
  }
  int cnt = 0;
  for (auto v : mp) {
    cnt++;
    if (cnt == n) {
      cout << v.first << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= min((int)s.size() - i, 5); j++) {
      string tmp = s.substr(i, j);
      // cout<<tmp<<endl;
      mp[tmp]++;
    }
  }
  int cnt = 0;
  for (auto v : mp) {
    cnt++;
    if (cnt == n) {
      cout << v.first << endl;
    }
  }
}
Problem p03353 (C++)

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

#define rep(i, n) for (signed i = 0; i < n; ++i)
#define int long long
#define str string
#define debg(a) cout << #a << ":" << a << endl;
#define vint vector<signed>
#define all(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;

signed main() {
  str s;
  cin >> s;
  int n;
  cin >> n;
  vector<str> sv;
  int sl = s.length();
  rep(i, sl) {
    for (int j = 1; j < sl - i + 1; ++j) {
      sv.pb(s.substr(i, j));
    }
  }
  sort(all(sv));
  // for(auto i:sv)cout<<i<<" ";cout<<endl;
  n--;
  for (int i = 0; i < n; ++i) {
    if (sv[i] == sv[i + 1])
      n++;
    if (i == sv.size() - 1)
      break;
  }
  cout << sv[n];
  return 0;
}

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

#define rep(i, n) for (signed i = 0; i < n; ++i)
#define int long long
#define str string
#define debg(a) cout << #a << ":" << a << endl;
#define vint vector<signed>
#define all(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;

signed main() {
  str s;
  cin >> s;
  int n;
  cin >> n;
  vector<str> sv;
  int sl = s.length();
  rep(i, sl) {
    for (int j = 1; j < sl - i + 1; ++j) {
      sv.pb(s.substr(i, j));
      if (j > 5)
        break;
    }
  }
  sort(all(sv));
  // for(auto i:sv)cout<<i<<" ";cout<<endl;
  n--;
  for (int i = 0; i < n; ++i) {
    if (sv[i] == sv[i + 1])
      n++;
    if (i == sv.size() - 1)
      break;
  }
  cout << sv[n];
  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 repr(i, n) for (int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  int n = s.size();
  rep(i, n) {
    string tmp = "";
    for (int j = i; j < n; j++) {
      tmp += s[j];
      st.insert(tmp);
    }
  }
  int cnt = 1;
  for (auto it = st.begin(); it != st.end(); it++) {
    if (cnt == k) {
      cout << *it << endl;
      return 0;
    }
    cnt++;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  int n = s.size();
  rep(i, n) {
    string tmp = "";
    for (int j = i; j < min(i + 5, n); j++) {
      tmp += s[j];
      st.insert(tmp);
    }
  }
  int cnt = 1;
  for (auto it = st.begin(); it != st.end(); it++) {
    if (cnt == k) {
      cout << *it << endl;
      return 0;
    }
    cnt++;
  }

  return 0;
}
Problem p03353 (C++)

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

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

  set<string> st;
  for (int i = 0; i < n; i++) {
    for (int j = 1; i + j <= n; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto iter = st.begin();
  for (int i = 1; i < k; i++)
    iter++;
  cout << *iter << endl;
  return 0;
}

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

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

  set<string> st;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 5 && i + j <= n; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto iter = st.begin();
  for (int i = 1; i < k; i++)
    iter++;
  cout << *iter << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

int main() {
  std::ios::sync_with_stdio(false);
  int count = 0, k;
  string s;
  cin >> s >> k;
  set<string> setstr;
  for (int i = 0; i < 26; ++i) {
    char c = 'a' + i;
    string tempstr = "";
    for (size_t j = 0; j < s.length(); ++j) {
      if (s[j] == c) {
        tempstr = "";
        for (size_t k = j; k < s.length(); ++k) {
          tempstr += s[k];
          setstr.insert(tempstr);
        }
      }
    }
    if (setstr.size() >= k)
      break;
  }

  set<string>::iterator it = setstr.begin();
  for (int i = 1; i < k; ++i) {
    ++it;
  }
  cout << *it << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

int main() {
  std::ios::sync_with_stdio(false);
  int count = 0, k;
  string s;
  cin >> s >> k;
  set<string> setstr;
  for (int i = 0; i < 26; ++i) {
    char c = 'a' + i;
    string tempstr = "";
    for (size_t j = 0; j < s.length(); ++j) {
      if (s[j] == c) {
        tempstr = "";
        for (size_t p = 0; p < k && (p + j) < s.length(); ++p) {
          tempstr += s[p + j];
          setstr.insert(tempstr);
        }
      }
    }
    if (setstr.size() >= k)
      break;
  }

  set<string>::iterator it = setstr.begin();
  for (int i = 1; i < k; ++i) {
    ++it;
  }
  cout << *it << endl;
}
Problem p03353 (C++)

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

typedef long long ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main() {
  string S;
  int K;
  cin >> S >> K;
  string T = S;
  set<string> st;
  bool frag = 0;
  int b = 0;
  for (int i = 0; i < 26; i++) {
    char a = 'a' + i;

    for (int j = 1; j <= S.size(); j++) {
      for (int k = 0; k < S.size(); k++) {
        if (S[k] == a && k + j - 1 < S.size()) {
          // cout << S.substr(k,j) << endl;
          st.insert(S.substr(k, j));
          if (st.size() > K) {
            frag = 1;
          }
          b++;
          // cout << st.size() << endl;
        }
      }
      if (b > 1000000) {
        break;
      }
      /*if(frag){
        break;
      }*/
    }
    if (frag) {
      break;
    }
  }
  ll N = st.size();
  // cout << N << endl;
  int cnt = 0;
  for (auto x : st) {
    cnt++;
    if (cnt == K) {
      cout << x << endl;
    }
  }
}


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

typedef long long ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main() {
  string S;
  int K;
  cin >> S >> K;
  string T = S;
  set<string> st;
  bool frag = 0;
  int b = 0;
  for (int i = 0; i < 26; i++) {
    char a = 'a' + i;

    for (int j = 1; j <= S.size(); j++) {
      for (int k = 0; k < S.size(); k++) {
        if (S[k] == a && k + j - 1 < S.size()) {
          // cout << S.substr(k,j) << endl;
          st.insert(S.substr(k, j));
          if (st.size() > K) {
            frag = 1;
          }
          b++;
          // cout << st.size() << endl;
        }
      }
      if (b > 100000) {
        break;
      }
      /*if(frag){
        break;
      }*/
    }
    if (frag) {
      break;
    }
  }
  ll N = st.size();
  // cout << N << endl;
  int cnt = 0;
  for (auto x : st) {
    cnt++;
    if (cnt == K) {
      cout << x << endl;
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
// #define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;

int main(void) {
  string s;
  ll k;
  cin >> s >> k;
  set<string> pitsu;
  rep(i, s.size()) {
    string t = "";
    ll cnt = 0;
    for (ll j = i; j < s.size() && cnt < 1000; j++) {
      t += s[j];
      pitsu.insert(t);
      cnt++;
    }
  }
  ll i = 0;
  for (string tmp : pitsu) {
    if (i == k - 1) {
      cout << tmp << endl;
      return 0;
    }
    i++;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
// #define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;

int main(void) {
  string s;
  ll k;
  cin >> s >> k;
  set<string> pitsu;
  rep(i, s.size()) {
    string t = "";
    ll cnt = 0;
    for (ll j = i; j < s.size() && cnt < 500; j++) {
      t += s[j];
      pitsu.insert(t);
      cnt++;
    }
  }
  ll i = 0;
  for (string tmp : pitsu) {
    if (i == k - 1) {
      cout << tmp << endl;
      return 0;
    }
    i++;
  }
  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;
  vector<string> v;
  int k;
  int n, m = 0;

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

  for (int i = 0; i < n; i++) {
    for (int j = 1; i + j <= n; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

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


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

int main() {
  string s;
  vector<string> v;
  int k;
  int n, m = 0;

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

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

  cout << v[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<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x, y) x = min(x, y)

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = (int)s.size();
  set<string> st;
  for (int i = 0; i < n; i++) {
    string x = "";
    x += s[i];
    st.insert(x);
    for (int j = i + 1; j < n; j++) {
      x += s[j];
      st.insert(x);
    }
  }
  auto it = st.begin();
  it = next(it, k - 1);
  cout << *it << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x, y) x = min(x, y)

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

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

using namespace std;

typedef long long int64;
typedef vector<int, int> vec;
#define read(a) scanf("%d", &a)
#define printarr(a, n)                                                         \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";

const int rmax = 1e5 + 10;
const int inf = INT_MAX;
set<string> myset;

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

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i; j++) {
      string temp = s.substr(i, j);
      myset.insert(temp);
    }
  }

  set<string>::iterator it;

  int x = 1;

  it = myset.begin();

  while (x < k) {
    it++;
    x++;
  }

  cout << *it << endl;

  return 0;
}


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

using namespace std;

typedef long long int64;
typedef vector<int, int> vec;
#define read(a) scanf("%d", &a)
#define printarr(a, n)                                                         \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";

const int rmax = 1e5 + 10;
const int inf = INT_MAX;
set<string> myset;

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

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= s.length() - i and j <= 5; j++) {
      string temp = s.substr(i, j);
      myset.insert(temp);
    }
  }

  set<string>::iterator it;

  int x = 1;

  it = myset.begin();

  while (x < k) {
    it++;
    x++;
  }

  cout << *it << endl;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

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

  for (auto x : m) {
    if (k == 1) {
      cout << x.first << endl;
      break;
    }
    k--;
  }
}


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

using namespace std;

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

  map<string, bool> m;
  for (int i = 0; i < s.length(); i++) {

    for (int j = 1; j <= min(k, (int)s.length() - i); j++) {
      m[s.substr(i, j)] = true;
    }
  }

  for (auto x : m) {
    if (k == 1) {
      cout << x.first << endl;
      break;
    }
    k--;
  }
}
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, m, n) for (ll i = m; i < n; i++)

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

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

  set<string> S;
  rep(i, s.size()) {
    rep(j, s.size() - i) { S.insert(s.substr(i, j + 1)); }
  }

  int cnt = 0;
  for (auto &&i : S) {
    if (cnt == k - 1) {
      cout << i << endl;
      return 0;
    }
    cnt++;
  }
}

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, m, n) for (ll i = m; i < n; i++)

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

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

  set<string> S;
  rep(i, s.size()) {
    for (int j = 0;; j++) {
      if (s.size() - i == j || k == j)
        break;
      S.insert(s.substr(i, j + 1));
    }
  }

  int cnt = 0;
  for (auto &&i : S) {
    if (cnt == k - 1) {
      cout << i << endl;
      return 0;
    }
    cnt++;
  }
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();

template <class T> void dumpVector(const vector<T> &vec) {
#ifdef SOURCE_TEST
  for (ll i = 0; i < vec.size(); ++i) {
    cout << vec[i] << ",";
  }
  cout << endl;
#endif
}

template <class T> void distinct(vector<T> &vec) {
  // 配列から重複を削除する
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

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

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

  dumpVector(strings);
  sort(strings.begin(), strings.end());
  distinct(strings);

  PR(strings[N - 1]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();

template <class T> void dumpVector(const vector<T> &vec) {
#ifdef SOURCE_TEST
  for (ll i = 0; i < vec.size(); ++i) {
    cout << vec[i] << ",";
  }
  cout << endl;
#endif
}

template <class T> void distinct(vector<T> &vec) {
  // 配列から重複を削除する
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

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

  vector<string> strings;
  for (ll i = 0; i < s.size(); ++i) {
    for (ll j = 1; (i + j) <= s.size(); ++j) {
      if (j > 5)
        continue;
      strings.push_back(s.substr(i, j));
    }
  }

  dumpVector(strings);
  sort(strings.begin(), strings.end());
  distinct(strings);

  PR(strings[N - 1]);
  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  int n, k;
  cin >> s >> k;
  set<string> ss;
  n = s.length();
  for (int i = 0; s[i]; i++) {
    for (int j = i; s[j]; j++) {
      int len = j - i + 1;
      ss.insert(s.substr(i, len));
    }
  }
  set<string>::iterator it;
  int counter = 0;
  for (it = ss.begin(); it != ss.end(); it++) {
    counter++;
    if (counter == k) {
      cout << *it;
      return 0;
    }
  }
}

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

int main() {
  string s;
  int n, k;
  cin >> s >> k;
  set<string> ss;
  n = s.length();
  for (int i = 0; s[i]; i++) {
    for (int j = i; s[j]; j++) {
      int len = j - i + 1;
      if (len > k)
        break;
      ss.insert(s.substr(i, len));
    }
  }
  set<string>::iterator it;
  int counter = 0;
  for (it = ss.begin(); it != ss.end(); it++) {
    counter++;
    if (counter == k) {
      cout << *it;
      return 0;
    }
  }
}
Problem p03353 (C++)

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

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> ss;
  for (int i = 1; i <= min((int)s.size(), K); i++) {
    for (int j = 0; j + i <= (int)s.size(); j++) {
      ss.insert(s.substr(i, j));
    }
  }

  set<string>::iterator it = ss.begin();
  for (int i = 0; i < K - 1; i++) {
    it++;
  }

  cout << *it << endl;

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> ss;
  for (int i = 1; i <= min((int)s.size(), K); i++) {
    for (int j = 0; j + i <= (int)s.size(); j++) {
      ss.insert(s.substr(j, i));
    }
  }

  set<string>::iterator it = ss.begin();
  for (int i = 0; i < K - 1; i++) {
    it++;
  }

  cout << *it << endl;

  return 0;
}
Problem p03353 (C++)

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

int main() {

  string s;
  int k;

  cin >> s >> k;

  set<string> a;

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

  auto it = a.begin();

  rep(i, k - 1) it++;

  cout << *it << endl;

  return 0;
}

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

int main() {

  string s;
  int k;

  cin >> s >> k;

  set<string> a;

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

  auto it = a.begin();

  rep(i, k - 1) it++;

  cout << *it << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

#define ad(x) int i = 100;
typedef long long ll;
// enum {
//   AST_INT,
//   AST_SYM,
//   AST_STR,
//   AST_FUNCALL,
// };

// double winProb(int Rp, int Rq) {
//     return 1/(1+pow(10, (Rq-Rp)/400.));
// }

// int R[1<<10];
// double dp[12][1<<10];
int k;
string s;

vector<string> a;

// int w[30010];
// int e[30010];

int main() {
  cin >> s >> k;
  // REP(i,)
  // cout << s.length() << endl;

  REP(i, 0, s.length() - 1) {
    REP(j, 1, k + 1) { a.push_back(s.substr(i, j)); }
  }

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

  // for(auto c: a) {
  //     cout << c << endl;
  // }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

#define ad(x) int i = 100;
typedef long long ll;
// enum {
//   AST_INT,
//   AST_SYM,
//   AST_STR,
//   AST_FUNCALL,
// };

// double winProb(int Rp, int Rq) {
//     return 1/(1+pow(10, (Rq-Rp)/400.));
// }

// int R[1<<10];
// double dp[12][1<<10];
int k;
string s;

vector<string> a;

// int w[30010];
// int e[30010];

int main() {
  cin >> s >> k;
  // REP(i,)
  // cout << s.length() << endl;
  // if (s.length() == 1) {
  //     cout << s << endl;
  //     return 0;
  // }
  REP(i, 0, s.length()) {
    REP(j, 1, k + 1) { a.push_back(s.substr(i, j)); }
  }

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

  // for(auto c: a) {
  //     cout << c << endl;
  // }

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

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1000000000)
#define MOD (1000000007)

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<string> v;
  string sub;
  rep(i, n) {
    rep(j, n - i) {
      sub = s.substr(i, j + 1);
      v.push_back(sub);
    }
  }
  sort(all(v));
  map<string, bool> m;
  int cnt = 0;
  rep(i, v.size()) {
    if (!m[v[i]]) {
      cnt++;
      m[v[i]] = 1;
      if (cnt == k) {
        cout << v[i] << endl;
        return 0;
      }
    }
  }
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1000000000)
#define MOD (1000000007)

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<string> v;
  string sub;
  rep(i, n) {
    rep(j, min(n - i, 5)) {
      sub = s.substr(i, j + 1);
      v.push_back(sub);
    }
  }
  sort(all(v));
  map<string, bool> m;
  int cnt = 0;
  rep(i, v.size()) {
    if (!m[v[i]]) {
      cnt++;
      m[v[i]] = 1;
      if (cnt == k) {
        cout << v[i] << endl;
        return 0;
      }
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(), a.end()
#define vec vector
typedef long long ll;
typedef pair<int, int> p;
// const ll big=998244353;
const ll big = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll max(ll x, ll y) {
  if (x > y)
    return x;
  else
    return y;
}
ll min(ll x, ll y) {
  if (x < y)
    return x;
  else
    return y;
}
ll expm(ll x, ll y) {
  if (y == 0)
    return 1; // 0^0=1
  if (x == 1 || x == 0)
    return x;
  if (y % 2 == 1)
    return (expm(x, y - 1) * x) % big;
  ll t = expm(x, y / 2);
  return (t * t) % big;
}
ll exp(ll x, ll y) {
  if (y == 0)
    return 1; // 0^0=1
  if (x == 1 || y == 0)
    return x;
  if (y % 2 == 1)
    return exp(x, y - 1) * x;
  ll t = exp(x, y / 2);
  return t * t;
}
ll inv(ll x) { return expm(x, big - 2); }

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/

  string s;
  cin >> s;
  int k;
  cin >> k;
  int cnt = 0;
  vec<string> ans;
  rep(i, s.size()) rep2(j, i, min(s.size(), i + k - 1))
      ans.push_back(s.substr(i, j - i + 1));
  sort(all(ans));

  rep(i, k) {
    if (i != 0 && ans[i] == ans[i - 1])
      k++;
    if (i == k - 1)
      cout << ans[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(), a.end()
#define vec vector
typedef long long ll;
typedef pair<int, int> p;
// const ll big=998244353;
const ll big = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll max(ll x, ll y) {
  if (x > y)
    return x;
  else
    return y;
}
ll min(ll x, ll y) {
  if (x < y)
    return x;
  else
    return y;
}
ll expm(ll x, ll y) {
  if (y == 0)
    return 1; // 0^0=1
  if (x == 1 || x == 0)
    return x;
  if (y % 2 == 1)
    return (expm(x, y - 1) * x) % big;
  ll t = expm(x, y / 2);
  return (t * t) % big;
}
ll exp(ll x, ll y) {
  if (y == 0)
    return 1; // 0^0=1
  if (x == 1 || y == 0)
    return x;
  if (y % 2 == 1)
    return exp(x, y - 1) * x;
  ll t = exp(x, y / 2);
  return t * t;
}
ll inv(ll x) { return expm(x, big - 2); }

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/

  string s;
  cin >> s;
  int k;
  cin >> k;
  int cnt = 0;
  vec<string> ans;
  rep(i, s.size()) rep2(j, i, min(s.size(), i + k))
      ans.push_back(s.substr(i, j - i + 1));
  sort(all(ans));

  rep(i, k) {
    if (i != 0 && ans[i] == ans[i - 1])
      k++;
    if (i == k - 1)
      cout << ans[i] << endl;
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
// char c;

#define Endl endl

/*--------------------template--------------------*/

int main() {
  cin >> s;
  int K;
  cin >> K;
  ll size = s.size();

  set<string> ans;
  vector<string> prevs;
  REP(i, size) {
    string c = string{s[i]};
    vector<string> curs;
    curs.push_back(c);
    for (string prev : prevs) {
      curs.push_back(prev + c);
    }
    for (string cur : curs) {
      ans.insert(cur);
    }
    prevs = curs;
  }
  auto iter = ans.begin();
  REP(i, K - 1) iter++;
  cout << *iter << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
// char c;

#define Endl endl

/*--------------------template--------------------*/

int main() {
  cin >> s;
  int K;
  cin >> K;
  ll size = s.size();

  set<string> ans;
  vector<string> prevs;
  REP(i, size) {
    string c = string{s[i]};
    vector<string> curs;
    curs.push_back(c);
    for (string prev : prevs) {
      if ((int)prev.size() < K)
        curs.push_back(prev + c);
    }
    for (string cur : curs) {
      ans.insert(cur);
    }
    prevs = curs;
  }
  auto iter = ans.begin();
  REP(i, K - 1) iter++;
  cout << *iter << endl;
  return 0;
}
Problem p03353 (C++)

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

using namespace std;
typedef long long int lli;
typedef pair<int, int> ii;

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

  set<string> ss;
  for (int i = 0; s[i] != '\0'; i++) {
    for (int j = 0; s[i + j] != '\0'; j++) {
      string ps = s.substr(i, j + 1);
      ss.insert(ps);
      if (ss.size() > K)
        ss.erase(--ss.end());
    }
  }

  cout << *(--ss.end()) << endl;
}


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

using namespace std;
typedef long long int lli;
typedef pair<int, int> ii;

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

  set<string> ss;
  for (int i = 0; s[i] != '\0'; i++) {
    for (int j = 0; s[i + j] != '\0' && j <= K; j++) {
      string ps = s.substr(i, j + 1);
      ss.insert(ps);
      if (ss.size() > K)
        ss.erase(--ss.end());
    }
  }

  cout << *(--ss.end()) << endl;
}
Problem p03353 (C++)

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

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

// ABC97-C
int main() {
  string s;
  cin >> s;
  ll K;
  cin >> K;

  ll len = s.length();
  set<string> st;

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

  vector<string> A;
  for (auto item : st) {
    A.push_back(item);
  }

  std::sort(A.begin(), A.end());

  cout << A[K - 1];
}


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

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

// ABC97-C
int main() {
  string s;
  cin >> s;
  ll K;
  cin >> K;

  ll len = s.length();
  set<string> st;

  for (ll i = 0; i < len; i++) {
    for (ll j = 1; j <= min(K, len - i); j++) {
      st.insert(s.substr(i, j));
    }
  }

  vector<string> A;
  for (auto item : st) {
    A.push_back(item);
  }

  std::sort(A.begin(), A.end());

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();

  int K;
  cin >> K;

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

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

  put(sv[K - 1]);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();

  int K;
  cin >> K;

  vector<string> sv;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n && j < i + 8; j++) {
      sv.push_back(s.substr(i, j - i));
    }
  }

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

  put(sv[K - 1]);

  return 0;
}
Problem p03353 (C++)

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

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

  string s;
  int K;
  cin >> s >> K;
  set<string> st;
  for (int i = 0; i <= s.size(); i++) {
    // string tmp = "";
    for (int j = 0; j <= s.size() - i; j++) {
      // cout << s.substr(i, j) << endl;
      // cout << i << endl;
      st.insert(s.substr(i, j));
    }
  }
  // cout << s.substr(0, 3) << endl;
  vector<string> tmp;
  for (auto x : st) {
    tmp.push_back(x);
  }
  // int solve(mn[][])
  cout << tmp[K] << endl;
}

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

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

  string s;
  int K;
  cin >> s >> K;
  set<string> st;
  for (int i = 0; i <= s.size(); i++) {
    // string tmp = "";
    for (int j = 0; j <= 5; j++) {
      // cout << s.substr(i, j) << endl;
      // cout << i << endl;
      st.insert(s.substr(i, j));
    }
  }
  // cout << s.substr(0, 3) << endl;
  vector<string> tmp;
  for (auto x : st) {
    tmp.push_back(x);
  }
  // int solve(mn[][])
  cout << tmp[K] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main() {
  string s;
  ll K;
  set<string> st;
  cin >> s >> K;
  ll N = s.length();
  REP(i, N) {
    for (int j = 1; i + j <= N; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto itr = st.begin();
  REP(i, K - 1) { itr++; }
  PRINT(*itr);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main() {
  string s;
  ll K;
  set<string> st;
  cin >> s >> K;
  ll N = s.length();
  REP(i, N) {
    FOR(j, 1, K + 1) {
      if (i + j > N)
        continue;
      st.insert(s.substr(i, j));
    }
  }
  auto itr = st.begin();
  REP(i, K - 1) { itr++; }
  PRINT(*itr);
  return 0;
}
Problem p03353 (C++)

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

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RFOR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define LL long long
#define INF INT_MAX / 3

const double EPS = 1e-14;
const double PI = acos(-1.0);

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

  int k;
  cin >> k;

  vector<string> v;

  FOR(i, 0, s.size()) {
    FOR(j, 1, s.size() - i + 1) { v.push_back(s.substr(i, j)); }
  }

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

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


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

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RFOR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define LL long long
#define INF INT_MAX / 3

const double EPS = 1e-14;
const double PI = acos(-1.0);

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

  int k;
  cin >> k;

  vector<string> v;

  FOR(i, 0, s.size()) {
    FOR(j, 1, 10) { v.push_back(s.substr(i, j)); }
  }

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

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

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

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

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

  vector<string> strs;
  for (string str : str_set)
    strs.push_back(str);
  sort(strs.begin(), strs.end());

  //  for (string str: strs) {
  //    cout << str << endl;
  //  }
  cout << strs[K - 1] << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

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

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

  vector<string> strs;
  for (string str : str_set)
    strs.push_back(str);
  sort(strs.begin(), strs.end());

  //  for (string str: strs) {
  //    cout << str << endl;
  //  }
  cout << strs[K - 1] << endl;

  return 0;
}