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

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> sub;
  for (char c = 'a'; c <= 'z'; c++) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == c) {
        string cc;
        cc = s[i];
        sub.insert(cc);
        for (int j = i + 1; j < s.size(); j++) {
          cc += s[j];
          sub.insert(cc);
        }
      }
    }
    if (sub.size() >= 5)
      break;
  }
  vector<string> v(sub.begin(), sub.end());
  cout << v[k - 1] << endl;
}


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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> sub;
  for (char c = 'a'; c <= 'z'; c++) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == c) {
        string cc;
        cc = s[i];
        sub.insert(cc);
        for (int j = i + 1; j < s.size(); j++) {
          if (j - i >= 5)
            break;
          cc += s[j];
          sub.insert(cc);
        }
      }
    }
    if (sub.size() >= 5)
      break;
  }
  vector<string> v(sub.begin(), sub.end());
  cout << v[k - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
using namespace std;

int main(void) {
  vector<string> A;
  int k;
  string x;
  string y;

  cin >> x;
  cin >> k;
  for (int i = 0; i < x.length(); i++) {
    for (int j = i; j < x.length(); j++) {
      y += x[j];
      A.push_back(y);
    }
    y.clear();
  }
  sort(A.begin(), A.end());
  A.resize(unique(A.begin(), A.end()) - A.begin());

  std::cout << A[k - 1] << std::endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
using namespace std;

int main(void) {
  vector<string> A;
  int k;
  string x;
  string y;

  cin >> x;
  cin >> k;
  for (int i = 0; i < x.length(); i++) {
    for (int j = i; j < x.length() && j < i + 5; j++) {
      y += x[j];
      A.push_back(y);
    }
    y.clear();
  }
  sort(A.begin(), A.end());
  A.resize(unique(A.begin(), A.end()) - A.begin());

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main() {
  string s;
  int K;
  cin >> s >> K;
  int leng = s.l_ength();
  vector<string> d;
  for (int range = 0; range < leng; ++range) {
    for (int l = 0; l + range < leng; ++l) {
      d.push_back(s.substr(l, range + 1));
    }
  }
  sort(d.begin(), d.end());
  auto itr = unique(d.begin(), d.end());
  d.erase(itr, d.end());
  cout << d[K - 1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main() {
  string s;
  int K;
  cin >> s >> K;
  int leng = s.l_ength();
  vector<string> d;
  for (int range = 0; range < K; ++range) {
    for (int l = 0; l + range < leng; ++l) {
      d.push_back(s.substr(l, range + 1));
    }
  }
  sort(d.begin(), d.end());
  auto itr = unique(d.begin(), d.end());
  d.erase(itr, d.end());
  cout << d[K - 1] << endl;
  return 0;
}
Problem p03353 (C++)

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

#define PB push_back
#define ALL(a) (a).begin(), (a).end()
#define DWN(a) (a).begin(), (a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = (int)1e9;

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

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

#define PB push_back
#define ALL(a) (a).begin(), (a).end()
#define DWN(a) (a).begin(), (a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = (int)1e9;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> v;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= (int)s.size() - i; j++) {
      string t = s.substr(j, i);
      v.insert(t);
    }
  }
  auto it = v.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 <iostream>
#include <set>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> v;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; i + j <= s.size(); ++j) {
      v.insert(s.substr(i, j));
    }
  }
  auto p = v.begin();
  for (int i = 0; i < k - 1; ++i)
    p++;
  cout << *p << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <set>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> v;
  for (int i = 1; i <= k; ++i) { // 個数 超長い文字列insertする意味ない
    for (int j = 0; i + j <= s.size(); ++j) { // j <= s.size() - i 要は最後まで
      v.insert(s.substr(j, i));
    }
  }
  auto p = v.begin();
  for (int i = 0; i < k - 1; ++i)
    p++;
  cout << *p << endl;
  return 0;
}
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++)

int main() {
  string s;
  int k;
  int l;
  vector<string> v;

  cin >> s >> k;
  l = s.length();

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

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v[k - 1] << 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++)

int main() {
  string s;
  int k;
  int l;
  vector<string> v;

  cin >> s >> k;
  l = s.length();

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

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

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

int main() {

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

  vector<string> c;
  for (int count = 1; count <= s.size(); count++) {
    for (int j = 0; j < s.size() - count + 1; j++) {
      c.push_back(s.substr(j, count));
    }
  }

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

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

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

int main() {

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

  vector<string> c;
  for (int count = 1; count <= k; count++) {
    for (int j = 0; j < s.size() - count + 1; j++) {
      c.push_back(s.substr(j, count));
    }
  }

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s;
  cin >> s;
  int k;
  cin >> k;
  int now = 0, sz = s.size();
  vector<string> vec;
  REP(i, 26) {
    char c = 'a' + i;
    set<pair<int, int>> st;
    REP(j, sz) if (s[j] == c) {
      if (j == sz - 1)
        st.insert({-1, j});
      else
        st.insert({s[j + 1] - 'a', j});
    }
    for (auto a : st)
      FOR(j, 1, sz - a.second + 1) vec.push_back(s.substr(a.second, j));
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)), vec.end());
    if (vec.size() >= k) {
      cout << vec[k - 1] << '\n';
      return 0;
    }
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s;
  cin >> s;
  int k;
  cin >> k;
  int now = 0, sz = s.size();
  vector<string> vec;
  REP(i, 26) {
    char c = 'a' + i;
    set<pair<int, int>> st;
    REP(j, sz) if (s[j] == c) {
      if (j == sz - 1)
        st.insert({-1, j});
      else
        st.insert({s[j + 1] - 'a', j});
    }
    for (auto a : st)
      FOR(j, 1, min(sz - a.second, k) + 1) vec.push_back(s.substr(a.second, j));
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)), vec.end());
    if (vec.size() >= k) {
      cout << vec[k - 1] << '\n';
      return 0;
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  string s;
  set<string> subs;
  int k;
  cin >> s >> k;
  int ssize = s.size();
  for (int i = 1; i <= ssize; i++) {
    for (int j = 0; j + i - 1 < ssize; j++) {
      subs.insert(s.substr(j, i));
    }
  }
  auto itr = subs.begin();
  for (int i = 1; i < k; i++) {
    itr++;
  }
  cout << *itr << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  string s;
  set<string> subs;
  int k;
  cin >> s >> k;
  int ssize = s.size();
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j + i - 1 < ssize; j++) {
      subs.insert(s.substr(j, i));
    }
  }
  auto itr = subs.begin();
  for (int i = 1; i < k; i++) {
    itr++;
  }
  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

  set<string> st;

  rep(i, n) {
    string t = "";
    for (int j = i; j < n; j++) {
      t += s[j];
      st.insert(t);
    }
  }

  int c = 0;
  for (auto &&e : st) {
    c++;
    if (c == k)
      cout << e << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

  set<string> st;

  rep(i, n) {
    string t = "";
    for (int j = i; j < n; j++) {
      if (t.size() > k)
        break;
      t += s[j];
      st.insert(t);
    }
  }

  int c = 0;
  for (auto &&e : st) {
    c++;
    if (c == k)
      cout << e << 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>;
using Pl = pair<ll, ll>;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPD(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define FILLl(n, first_dimension_size, value)                                  \
  fill((ll *)n, (ll *)(n + first_dimension_size), value)
#define FILL(n, first_dimension_size, value)                                   \
  fill((int *)n, (int *)(n + first_dimension_size), value)
#define INF (1 << 29)
#define MOD 1000000007
// int dx[4] = {1,0,0,-1};
// int dy[4] = {0,1,-1,0};

int main() {

  string s;
  int k;
  set<string> se;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      se.insert(s.substr(i, j - i + 1));
    }
  }
  auto itr = se.begin();
  for (int i = 0; i < k - 1; i++)
    itr++;
  cout << *itr << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPD(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define FILLl(n, first_dimension_size, value)                                  \
  fill((ll *)n, (ll *)(n + first_dimension_size), value)
#define FILL(n, first_dimension_size, value)                                   \
  fill((int *)n, (int *)(n + first_dimension_size), value)
#define INF (1 << 29)
#define MOD 1000000007
// int dx[4] = {1,0,0,-1};
// int dy[4] = {0,1,-1,0};

int main() {

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

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

int main() {
  int k, i, j;
  vector<string> v;
  set<string> st;
  string s;
  cin >> s >> k;
  for (i = 0; i < s.length(); i++) {
    for (j = 0; j < k && i + j < s.length(); j++) {
      v.push_back(s.substr(i, j + 1));
    }
  }
  sort(v.begin(), v.end());
  i = 0;
  while (st.size() < k) {
    st.insert(v[i]);
    i++;
  }
  cout << v[i] << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int k, i, j;
  vector<string> v;
  set<string> st;
  string s;
  cin >> s >> k;
  for (i = 0; i < s.length(); i++) {
    for (j = 0; j < k && i + j < s.length(); j++) {
      v.push_back(s.substr(i, j + 1));
    }
  }
  sort(v.begin(), v.end());
  i = 0;
  while (st.size() < k) {
    st.insert(v[i]);
    i++;
  }
  cout << v[i - 1] << "\n";
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
// g++ -std=c++11 -o2 -Wall ABC097C.cpp -o ./out/ABC097C.out
// ./out/ABC097C.out

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> ss;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= n - i; ++j)
      ss.insert(s.substr(j, i));
  }
  string ans;
  for (auto sss : ss) {
    --k;
    if (k <= 0) {
      ans = sss;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
// g++ -std=c++11 -o2 -Wall ABC097C.cpp -o ./out/ABC097C.out
// ./out/ABC097C.out

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> ss;
  for (int l = 1; l <= 5; ++l) {
    for (int j = 0; j <= n - l; ++j) {
      ss.insert(s.substr(j, l));
    }
  }
  string ans;
  for (auto sss : ss) {
    --k;
    if (k <= 0) {
      ans = sss;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
Problem p03353 (C++)

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

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

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

int main() {
  vector<string> array;
  string s;
  int k;
  cin >> s >> k;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < s.size(); j++) {
      array.push_back(s.substr(j, i));
    }
  }
  sort(array.begin(), array.end());
  unique(array.begin(), array.end());
  cout << array[k - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

  REP(i, s.size()) {
    FOR(j, 1, s.size() + 1) {
      if (i + j <= s.size())
        v.insert(s.substr(i, j));
      else
        break;
    }
  }

  int i = 1;

  for (set<string>::iterator itr = v.begin(); itr != v.end(); ++itr) {
    if (i == k) {
      cout << *itr << endl;
      break;
    }
    i++;
  }
}


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 FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

  REP(i, s.size()) {
    FOR(j, 1, k + 1) {
      if (i + j <= s.size())
        v.insert(s.substr(i, j));
      else
        break;
    }
  }

  int i = 1;

  for (set<string>::iterator itr = v.begin(); itr != v.end(); ++itr) {
    if (i == k) {
      cout << *itr << endl;
      break;
    }
    i++;
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var)                                                             \
  SORT(var);                                                                   \
  REVERSE(var)
#define OPTIMIZE_STDIO                                                         \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.precision(10);                                                          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream &cin, ostream &cout) {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> v;
  FOR(j, 1, n) {
    FOR(i, 0, n - j) { v.push_back(s.substr(i, j)); }
  }
  SORT(v);
  // 重複要素を削除
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v[k - 1] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var)                                                             \
  SORT(var);                                                                   \
  REVERSE(var)
#define OPTIMIZE_STDIO                                                         \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.precision(10);                                                          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream &cin, ostream &cout) {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  vector<string> v;
  FOR(j, 1, min(n, 5)) {
    FOR(i, 0, n - j) { v.push_back(s.substr(i, j)); }
  }
  SORT(v);
  // 重複要素を削除
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v[k - 1] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(), x.end()
// #define x first
// #define y second

using namespace std;
int k;
string s;
set<string> ans;
set<string>::iterator it;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> s >> k;
  rep2(i, 1, max((int)(s.size() + 1), 6)) rep(j, s.size() - i + 1)
      ans.insert(s.substr(j, i));
  for (it = ans.begin(); k > 1; it++, k--)
    ;
  cout << *it << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(), x.end()
// #define x first
// #define y second

using namespace std;
int k;
string s;
set<string> ans;
set<string>::iterator it;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> s >> k;
  rep2(i, 1, min((int)(s.size() + 1), 6)) rep(j, s.size() - i + 1)
      ans.insert(s.substr(j, i));
  for (it = ans.begin(); k > 1; it++, k--)
    ;
  cout << *it << endl;
  return 0;
}
Problem p03353 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())

    subs = set()

    S_sorted = sorted(set(S))
    for c_min in S_sorted:
        indices = [i for i, c in enumerate(S) if c == c_min]
        for i in indices:
            for j in range(i + 1, len(S) + 1):
                subs.add(S[i:j])

        if len(subs) >= K:
            break

    subs = sorted(subs)
    print(subs[K - 1])

    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())

    subs = set()

    S_sorted = sorted(set(S))
    for c_min in S_sorted:
        indices = [i for i, c in enumerate(S) if c == c_min]
        for i in indices:
            for j in range(i + 1, min(len(S) + 1, i + K + 1)):
                subs.add(S[i:j])

        if len(subs) >= K:
            break

    subs = sorted(subs)
    print(subs[K - 1])

    return


if __name__ == "__main__":
    main()
Problem p03353 (C++)

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

using namespace std;

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

  std::vector<std::string> sub;

  for (int left = 0; left < s.size(); ++left) {
    for (int n = 1; n <= s.size() - left; ++n) {
      sub.emplace_back(s.substr(left, n));
    }
  }

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

  std::unique(sub.begin(), sub.end());

  cout << sub[K - 1] << endl;

  return 0;
}


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

using namespace std;

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

  std::vector<std::string> sub;

  for (int left = 0; left < s.size(); ++left) {
    for (int n = 1; n <= K; ++n) {
      sub.emplace_back(s.substr(left, n));
    }
  }

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

  std::unique(sub.begin(), sub.end());

  cout << sub[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

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

Fixed submission:
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define check(v)                                                               \
  rep(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> m;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      string s2 = s.substr(i, j - i + 1);
      m.insert(s2);
    }
  }
  auto ans = m.begin();
  rep(i, k - 1) { ans++; }
  cout << *ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define check(v)                                                               \
  rep(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> m;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size() && j < i + k + 1; j++) {
      string s2 = s.substr(i, j - i + 1);
      m.insert(s2);
    }
  }
  auto ans = m.begin();
  rep(i, k - 1) { ans++; }
  cout << *ans << endl;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

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

  map<string, int>::iterator it = num.begin();
  for (int i = 0; i < K - 1; i++)
    it++;
  cout << it->first << endl;
  return 0;
}

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

using namespace std;

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

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

  map<string, int>::iterator it = num.begin();
  for (int i = 0; i < K - 1; i++)
    it++;
  cout << it->first << 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> t;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      t.insert(s.substr(i, j - i + 1));
    }
  }
  auto itr = t.begin();
  for (int i = 0; i < K - 1; i++)
    itr++;
  cout << *itr << endl;
}


Fixed submission:
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> t;
  for (int i = 0; i < s.size(); i++)
    for (int j = 1; j <= K; j++)
      t.insert(s.substr(i, j));
  auto itr = t.begin();
  for (int i = 0; i < K - 1; i++)
    itr++;
  cout << *itr << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll h, w;
ll direction2[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
bool valid(int a, int b) {
  if (a >= 1 && a <= h && b >= 1 && b <= w)
    return true;
  else
    return false;
}

int main() {
  //    ios_base::sync_with_stdio(false);
  //    cin.tie(NULL);
  string s;
  cin >> s;
  ll k, y = 0;
  cin >> k;
  vector<string> v, v2;

  ll x = 0;
  map<string, ll> m;
  for (int i = 5; i >= 1; i--) {
    for (int j = 1; j <= s.size() - i + 1; j++) {
      if (m[s.substr(j - 1, i)] != 1) {
        x++;
        m[s.substr(j - 1, i)] = 1;
        v.push_back(s.substr(j - 1, i));
      }
    }
  }
  sort(v.begin(), v.end());
  // for(auto i:v)cout<<i<<endl;
  cout << v[k - 1];
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll h, w;
ll direction2[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
bool valid(int a, int b) {
  if (a >= 1 && a <= h && b >= 1 && b <= w)
    return true;
  else
    return false;
}

int main() {
  //    ios_base::sync_with_stdio(false);
  //    cin.tie(NULL);
  string s;
  cin >> s;
  ll k, y = 0;
  cin >> k;
  vector<string> v, v2;

  ll x = 0;
  map<string, ll> m;
  for (int i = min((ll)s.size(), 5ll); i >= 1; i--) {
    for (int j = 1; j <= s.size() - i + 1; j++) {
      if (m[s.substr(j - 1, i)] != 1) {
        x++;
        m[s.substr(j - 1, i)] = 1;
        v.push_back(s.substr(j - 1, i));
      }
    }
  }
  sort(v.begin(), v.end());
  // for(auto i:v)cout<<i<<endl;
  cout << v[k - 1];
  return 0;
}
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 all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;

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

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

int main() {
  string s;
  int K;
  cin >> s >> K;
  vector<string> subStrs;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= min(5, n - i); j++) {
      subStrs.push_back(s.substr(i, j));
    }
  }
  map<string, int> mp;
  rep(i, subStrs.size()) mp[subStrs[i]]++;
  int cnt = 1;
  for (auto p : mp) {
    if (cnt == K) {
      cout << p.first << endl;
      break;
    }
    cnt++;
  }
  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  char s[5001];
  int K;
  cin >> s >> K;

  char sub[5][5001] = {
      "", "", "", "", "",
  };

  for (int i = 0; i < strlen(s); i++) {
    for (int j = 1; j <= strlen(s) - i; j++) {
      bool flag = false;
      char temp[5001];

      strncpy(temp, s + i, j);
      temp[j] = '\0';

      for (int k = 0; k < 5; k++) {
        if (strcmp(sub[k], "") == 0) {
          strcpy(sub[k], temp);
          break;
        }

        int cmp = strcmp(temp, sub[k]);
        if (cmp == 0) {
          break;
        }
        if (cmp < 0) {
          for (int l = K - 1; l > k; l--) {
            strcpy(sub[l], sub[l - 1]);
          }
          strcpy(sub[k], temp);
          break;
        }
        if (k == 5) {
          flag = true;
        }
      }
      if (flag) {
        break;
      }
    }
  }

  cout << sub[K - 1] << endl;

  return 0;
}


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

using namespace std;

int main() {
  char s[5001];
  int K;
  cin >> s >> K;

  char sub[5][5001] = {
      "", "", "", "", "",
  };

  for (int i = 0; i < strlen(s); i++) {
    for (int j = 1; j <= strlen(s) - i; j++) {
      bool flag = false;
      char temp[5001];

      strncpy(temp, s + i, j);
      temp[j] = '\0';

      for (int k = 0; k < 5; k++) {
        if (strcmp(sub[k], "") == 0) {
          strcpy(sub[k], temp);
          break;
        }

        int cmp = strcmp(temp, sub[k]);
        if (cmp == 0) {
          break;
        }
        if (cmp < 0) {
          for (int l = K - 1; l > k; l--) {
            strcpy(sub[l], sub[l - 1]);
          }
          strcpy(sub[k], temp);
          break;
        }
        if (k == 4) {
          flag = true;
        }
      }
      if (flag) {
        break;
      }
    }
  }

  cout << sub[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
  if (judge_exp) {
    cout << ok << endl;
  } else {
    cout << ng << endl;
  }
}

int ncr(int left, int right) {
  right = min(left - right, right);
  int ans = 1;
  for (int i = 1; i <= right; i++) {
    ans = ans * (left - right + i) / i;
  }
  return ans;
}

[[maybe_unused]] const int LIMIT = 1000000256;
[[maybe_unused]] const int tenfive = 100000;

} // namespace atcoder

using namespace atcoder;

int main(void) {
  string mst;
  int k;
  cin >> mst;
  cin >> k;
  set<string> strs;
  string stk;
  // i番目,j文字
  for (int i = 0; i < mst.size(); i++) {
    for (int j = 1; j < 6; j++) {
      // substrのout of range防止
      if (j <= mst.size() - i)
        strs.insert(mst.substr(i, j));
    }
  }
  for (string s : strs)
    cerr << s << endl;
  auto it = strs.begin();
  for (int i = 0; i < k; i++)
    ++it;

  cout << *it << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
  if (judge_exp) {
    cout << ok << endl;
  } else {
    cout << ng << endl;
  }
}

int ncr(int left, int right) {
  right = min(left - right, right);
  int ans = 1;
  for (int i = 1; i <= right; i++) {
    ans = ans * (left - right + i) / i;
  }
  return ans;
}

[[maybe_unused]] const int LIMIT = 1000000256;
[[maybe_unused]] const int tenfive = 100000;

} // namespace atcoder

using namespace atcoder;

int main(void) {
  string mst;
  int k;
  cin >> mst;
  cin >> k;
  set<string> strs;
  string stk;
  // i番目,j文字
  for (int i = 0; i < mst.size(); i++) {
    for (int j = 1; j < 6; j++) {
      // substrのout of range防止
      if (j <= mst.size() - i)
        strs.insert(mst.substr(i, j));
    }
  }
  for (string s : strs)
    cerr << s << endl;
  auto it = strs.begin();
  for (int i = 1; i < k; i++)
    ++it;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e18
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)

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

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

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

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


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

#define INF 1e18
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)

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

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

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), 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;
#define rep(i, n) for (int i = 0; i < n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int len = int(s.size());
  set<string> ans;
  for (int i = 1; i <= len; i++) {
    for (int j = 0; j < len - i + 1; j++) {
      string now = s.substr(j, i);
      ans.insert(now);
    }
  }
  auto itr = ans.begin();
  rep(i, k - 1)++ itr;
  cout << *itr << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int len = int(s.size());
  set<string> ans;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < len - i + 1; j++) {
      string now = s.substr(j, i);
      ans.insert(now);
    }
  }
  auto itr = ans.begin();
  rep(i, k - 1)++ itr;
  cout << *itr << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const int MAX = 5005;

#define ll long long
set<string> a;
string s;
int main() {
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j + i < s.length(); j++) {
      a.insert(s.substr(i, j));
    }
  }
  set<string>::iterator p = a.begin();
  for (int i = 1; i < k; i++)
    p++;
  cout << *p << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const int MAX = 5005;

#define ll long long
set<string> a;
string s;
int main() {
  cin >> s;
  int k;
  cin >> k;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    for (int j = 1; j + i <= len && j <= 5; j++) {
      a.insert(s.substr(i, j));
    }
  }
  set<string>::iterator p = a.begin();
  for (int i = 1; i < k; i++)
    p++;
  cout << *p << 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 (int i = 0; i < (int)(n); i++)
/*既に塗った色の配列　tuple(親、子、その間の辺の色)の配列
  を用意
*/
struct edge {
  int to, color;
};

using Graph = vector<vector<edge>>;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  vector<string> vec;
  set<string> s;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < S.size() - i; j++) {
      s.insert(S.substr(i, j + 1));
    }
  }
  for (auto value : s) {
    vec.push_back(value);
  }
  sort(vec.begin(), vec.end());
  /*rep(i,vec.size()){
    cout << vec[i] << endl;
  }*/
  cout << vec[K - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*既に塗った色の配列　tuple(親、子、その間の辺の色)の配列
  を用意
*/
struct edge {
  int to, color;
};

using Graph = vector<vector<edge>>;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  vector<string> vec;
  set<string> s;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < S.size() - i; j++) {
      if (j + 1 > K)
        break;
      s.insert(S.substr(i, j + 1));
    }
  }
  for (auto value : s) {
    vec.push_back(value);
  }
  sort(vec.begin(), vec.end());
  /*rep(i,vec.size()){
    cout << vec[i] << endl;
  }*/
  cout << vec[K - 1] << endl;
}
Problem p03353 (C++)

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

#ifdef INPUT
#include <sstream>
stringstream input_(R"(
atcoderandatcodeer
5
)");
#define cin input_
#endif

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

  set<string> kyu;

  int length = s.size();

  for (int i = 1; i <= length; i++) {
    for (int j = 0; j < length; j++) {
      kyu.insert(s.substr(j, i));

      if (j + i > length)
        break;
    }

    if (i > length)
      break;
  }

  int count = 0;

  for (auto h = kyu.begin(); h != kyu.end(); h++) {
    count++;
    if (count == k) {
      cout << *h << endl;
      break;
    }
  }
  return 0;
}

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

#ifdef INPUT
#include <sstream>
stringstream input_(R"(
atcoderandatcodeer
5
)");
#define cin input_
#endif

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

  set<string> kyu;

  int length = s.size();

  for (int i = 1; i <= length; i++) {
    for (int j = 0; j < length; j++) {
      kyu.insert(s.substr(j, i));

      if (j + i > length)
        break;
    }

    if (i > 5)
      break;
  }

  int count = 0;

  for (auto h = kyu.begin(); h != kyu.end(); h++) {
    count++;
    if (count == k) {
      cout << *h << endl;
      break;
    }
  }
  return 0;
}
Problem p03353 (C++)

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  set<string> SE;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j <= i; j++) {
      SE.insert(S.substr(j, i - j + 1));
    }
  }
  cout << *next(SE.begin(), K - 1) << "\n";
}

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  set<string> SE;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j <= i; j++) {
      if (i - j + 1 > K)
        continue;
      SE.insert(S.substr(j, i - j + 1));
    }
  }
  cout << *next(SE.begin(), K - 1) << "\n";
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
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> st;
  int l = s.size();
  rep(i, l) {
    for (int j = 1; j + i <= l; j++) {
      string now = s.substr(i, j);
      st.emplace(now);
    }
  }
  auto itr = st.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;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
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> st;
  int l = s.size();
  rep(i, l) {
    for (int j = 1; j + i <= l; j++) {
      if (j > 5)
        continue;
      string now = s.substr(i, j);
      st.emplace(now);
    }
  }
  auto itr = st.begin();
  rep(i, k - 1) { itr++; }
  cout << *itr << endl;
  return 0;
}