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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
bool cmp(string a, string b) {
  for (int i = 0; i < a.size() && i < b.size(); i++)
    if (i < b.size() && a[i] != b[i]) {
      if (a[i] - 'a' < b[i] - 'a')
        return true;
      else
        return false;
    }
  if (a.size() < b.size())
    return true;
  else
    return false;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  map<string, bool> mp;
  vector<string> a;
  for (int i = 0; i < s.size(); i++)
    for (int j = 1; j <= s.size(); j++)
      if (i + j <= s.size() && !mp[s.substr(i, j)]) {
        mp[s.substr(i, j)] = 1;
        a.push_back(s.substr(i, j));
      }
  sort(a.begin(), a.end(), cmp);
  cout << a[k - 1];
  system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
bool cmp(string a, string b) {
  for (int i = 0; i < a.size() && i < b.size(); i++)
    if (i < b.size() && a[i] != b[i]) {
      if (a[i] - 'a' < b[i] - 'a')
        return true;
      else
        return false;
    }
  if (a.size() < b.size())
    return true;
  else
    return false;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  map<string, bool> mp;
  vector<string> a;
  for (int i = 0; i < s.size(); i++)
    for (int j = 1; j <= 5; j++)
      if (i + j <= s.size() && !mp[s.substr(i, j)]) {
        mp[s.substr(i, j)] = 1;
        a.push_back(s.substr(i, j));
      }
  sort(a.begin(), a.end(), cmp);
  cout << a[k - 1];
  system("pause");
  return 0;
}
Problem p03355 (C++)

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

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

  vector<string> v;
  for (int i = 0; i < s.size(); ++i) {
    string cur;
    for (int j = i; j < s.size() && j < j + 10; ++j) {
      cur.push_back(s[j]);
      v.push_back(cur);
    }
  }

  int k;
  cin >> k;

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

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


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

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

  vector<string> v;
  for (int i = 0; i < s.size(); ++i) {
    string cur;
    for (int j = i; j < s.size() && j < i + 10; ++j) {
      cur.push_back(s[j]);
      v.push_back(cur);
    }
  }

  int k;
  cin >> k;

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

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

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

using i64 = long long int;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  for (int i = 0; i < s.size(); ++i) {
    string str = "";
    for (int j = 0; i + j < s.size(); ++j) {
      str.push_back(s[i + j]);
      st.insert(str);
    }
  }

  string ans;
  int cnt = 0;
  for (auto e : st) {
    cnt++;
    if (cnt == k) {
      ans = e;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using i64 = long long int;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  for (int i = 0; i < s.size(); ++i) {
    string str = "";
    for (int j = 0; j < 5; ++j) {
      if (i + j >= s.size())
        break;
      str.push_back(s[i + j]);
      st.insert(str);
    }
  }

  string ans;
  int cnt = 0;
  for (auto e : st) {
    cnt++;
    if (cnt == k) {
      ans = e;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
signed main() {
  string S;
  ll K, N, i, j;
  cin >> S >> K;
  N = S.size();
  vector<string> SUB;
  FOR(j, 1, K) REP(i, N - j + 1) SUB.push_back(S.substr(i, j));
  sort(ALL(SUB));
  j = 0;
  REP(i, K - 1) {
    j++;
    while (SUB.at(j - 1) == SUB.at(j))
      j++;
  }
  cout << SUB.at(j) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
signed main() {
  string S;
  ll K, N, i, j;
  cin >> S >> K;
  N = S.size();
  vector<string> SUB;
  FOR(j, 1, K + 1) REP(i, N - j + 1) SUB.push_back(S.substr(i, j));
  sort(ALL(SUB));
  j = 0;
  REP(i, K - 1) {
    j++;
    while (SUB.at(j - 1) == SUB.at(j))
      j++;
  }
  cout << SUB.at(j) << endl;
  return 0;
}
Problem p03355 (C++)

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<vector<int>> ind(26);
  for (int i = 0; i < s.size(); ++i) {
    ind[s[i] - 'a'].push_back(i);
  }
  set<string> ss;
  for (int i = 0; i < 26; ++i) {
    int prev = -1;
    for (int j = 0; j < ind[i].size(); ++j) {
      int st = ind[i][j];
      string temp;
      if (prev != -1 && s.substr(st, st + 5) == s.substr(prev, prev + 5))
        continue;
      for (int k = st; k < s.size(); ++k) {
        temp.push_back(s[k]);
        ss.insert(temp);
      }
      prev = st;
    }
    if (ss.size() >= k)
      break;
  }
  for (auto i : ss) {
    k--;
    if (k == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<vector<int>> ind(26);
  for (int i = 0; i < s.size(); ++i) {
    ind[s[i] - 'a'].push_back(i);
  }
  set<string> ss;
  for (int i = 0; i < 26; ++i) {
    int prev = -1;
    for (int j = 0; j < ind[i].size(); ++j) {
      int st = ind[i][j];
      string temp;
      // if(prev != -1 && s.substr(st, st + 5) == s.substr(prev, prev + 5))
      //     continue;
      for (int k = st; k < min((int)s.size(), st + 5); ++k) {
        temp.push_back(s[k]);
        ss.insert(temp);
      }
      prev = st;
    }
    if (ss.size() >= k)
      break;
  }
  for (auto i : ss) {
    k--;
    if (k == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03355 (C++)

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<string, int> memo;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    if (memo.size() > 5)
      break;
    for (int start = 0, end = 0; start < s.length(); start++) {
      if (s[start] == ch) {
        vector<string> sub(1);
        sub[0] += s[start];
        memo[sub[0]] = 1;
        int subnum = 0;
        for (end = start + 1; end < s.length(); end++) {
          if (s[end - 1] != ch && s[end] == ch) {
            subnum++;
            sub.push_back("");
          }
          sub[subnum] += s[end];
          string pushsub = "";
          for (int i = 0; i < sub.size(); i++) {
            pushsub += sub[i];
            memo[pushsub] = 1;
          }
        }
      }
    }
  }

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

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<string, int> memo;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    if (memo.size() > 5)
      break;
    for (int start = 0, end = 0; start < s.length(); start++) {
      if (s[start] == ch) {
        string sub = "";
        for (int i = 0; i < 5 && start + i < s.length(); i++) {
          sub += s[start + i];
          memo[sub] = 1;
        }
      }
    }
  }

  int i = 1;
  for (auto p : memo) {
    if (i == k) {
      cout << p.first << endl;
      break;
    }
    i++;
  }
  return 0;
}
Problem p03355 (C++)

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(a) ((int)a.size())

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

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

  for (int i = 0; i < sz(s); i++) {
    string cur = "";
    for (int j = i; j < sz(s); j++) {
      if (sz(res) >= 5) {
        auto it = res.upper_bound(cur);
        if (it == res.end())
          break;
      }
      cur.push_back(s[j]);
      res.insert(cur);
    }
    if (sz(res) > 5) {
      auto it = res.end();
      it--;
      res.erase(it);
    }
  }

  int now = 0;
  for (auto it = res.begin(); it != res.end(); it++) {
    now++;
    if (now == k) {
      cout << *it;
      return 0;
    }
  }

  return 0;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(a) ((int)a.size())

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

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

  for (int i = 0; i < sz(s); i++) {
    string cur = "";
    for (int j = i; j < min(sz(s), i + k); j++) {
      if (sz(res) >= 5) {
        auto it = res.upper_bound(cur);
        if (it == res.end())
          break;
      }
      cur.push_back(s[j]);
      res.insert(cur);
    }
    if (sz(res) > 5) {
      auto it = res.end();
      it--;
      res.erase(it);
    }
  }

  int now = 0;
  for (auto it = res.begin(); it != res.end(); it++) {
    now++;
    if (now == k) {
      cout << *it;
      return 0;
    }
  }

  return 0;
}
Problem p03355 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
  string s;
  int k;
  int cnt = 1;
  string ans;
  map<string, int> sub;
  cin >> s >> k;
  rep(i, s.size()) {
    if (i > 5)
      break;
    for (int j = i; j < s.size(); j++) {
      string S = s.substr(j - i, i + 1);
      sub[S]++;
    }
  }
  for (auto c : sub) {
    if (cnt == k)
      ans = c.first;
    cnt++;
  }
  cout << ans << endl;
}
Problem p03355 (C++)

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

string S;
int k;
set<string> SET;

int main() {
  cin >> S;
  cin >> k;
  for (int i = 0; i < (int)S.length(); ++i) {
    string tmp = "";
    for (int j = i; j < (int)S.length(); ++j) {
      tmp += S[j];
      int counter = 0;
      // cout << tmp << "\n";
      if (SET.find(tmp) == SET.end()) {
        SET.insert(tmp);
        ++counter;
      }
      if (counter == k)
        break;
    }
  }

  string ans;
  for (int i = 1; i <= k; ++i) {
    ans = *SET.begin();
    SET.erase(SET.begin());
  }
  cout << ans << "\n";
  return 0;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

string S;
int k;
set<string> SET;

int main() {
  cin >> S;
  cin >> k;
  for (int i = 0; i < (int)S.length(); ++i) {
    string tmp = "";
    for (int j = i; j < (int)S.length(); ++j) {
      tmp += S[j];
      int counter = 0;
      // cout << tmp << "\n";
      if (SET.find(tmp) == SET.end()) {
        SET.insert(tmp);
        ++counter;
        if (sz(SET) > k) {
          auto it = --SET.end();
          SET.erase(it);
        }
      }
      if (counter == k)
        break;
    }
  }

  string ans;
  for (int i = 1; i <= k; ++i) {
    ans = *SET.begin();
    SET.erase(SET.begin());
  }
  cout << ans << "\n";
  return 0;
}
Problem p03355 (C++)

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

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

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

  cout << *(--top5.end()) << endl;

  return 0;
}


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

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

  set<string> top5;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; i + j <= s.size() && j <= K; j++) {
      top5.insert(s.substr(i, j));
      while (top5.size() > K) {
        top5.erase(--top5.end());
      }
    }
  }

  cout << *(--top5.end()) << endl;

  return 0;
}
Problem p03355 (C++)

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

using namespace std;

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


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

using namespace std;

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

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
const ll LL_MAX(1LL << 60);

#define rep(i, s, e) for (ll i = (s); i < (e); i++)

using namespace std;

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

  string s;
  ll k;
  cin >> s >> k;

  ll len(0);

  set<string> ss;

  rep(i, 0, s.size() + 1) { rep(j, 0, s.size() + 1) ss.insert(s.substr(i, j)); }

  ll m(0);
  for (auto i : ss) {
    if (m == k)
      cout << i << endl;
    ++m;
  }

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
const ll LL_MAX(1LL << 60);

#define rep(i, s, e) for (ll i = (s); i < (e); i++)

using namespace std;

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

  string s;
  ll k;
  cin >> s >> k;

  ll len(0);

  set<string> ss;

  rep(i, 0, s.size() + 1) { rep(j, 0, k + 1) ss.insert(s.substr(i, j)); }

  ll m(0);
  for (auto i : ss) {
    if (m == k)
      cout << i << endl;
    ++m;
  }

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  set<string> S;
  for (int i = 1; i <= 5; i++)
    for (int j = 0; j < s.size() - i + 1; j++)
      S.insert(s.substr(j, i));
  set<string>::iterator it = S.begin();
  int k;
  cin >> k;
  k--;
  while (k--)
    it++;
  cout << *it << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  set<string> S;
  int n = s.size();
  for (int i = 1; i <= min(n, 5); i++)
    for (int j = 0; j < s.size() - i + 1; j++)
      S.insert(s.substr(j, i));
  set<string>::iterator it = S.begin();
  int k;
  cin >> k;
  k--;
  while (k--)
    it++;
  cout << *it << endl;
  return 0;
}
Problem p03355 (C++)

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

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;

string s;
int k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int n = s.length();
  cin >> k;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      v.push_back(s.substr(i, j - 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;

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;

string s;
int k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int n = s.length();
  cin >> k;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= min(6, n) && i + j <= n; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v[k - 1] << endl;

  return 0;
}
Problem p03355 (C++)

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9 + 7)
#define INF (1LL << 60)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n) {
  ll s = sqrt(n);
  ll r = 0;
  for (ll i = 2; i <= s; i++) {
    if ((n % i) == 0) {
      r = 0;
      do {
        r++;
        n = n / i;
      } while ((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if (n > s) {
    prim.push_back({n, 1});
  }
}

void solve() {
  string s;
  cin >> s;
  ll K;
  cin >> K;

  set<string> ss;
  rep(i, s.size()) {
    rep1(j, s.size() - i) {
      ss.insert(s.substr(i, j));
      //      cerr << s.substr(i, j) << " " ;
    }
  }

  for (auto itr : ss) {
    K--;
    //    cerr << K <<  " " << itr << endl;
    if (K <= 0) {
      cout << itr << endl;
      break;
    }
  }
}

int main(void) {
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9 + 7)
#define INF (1LL << 60)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n) {
  ll s = sqrt(n);
  ll r = 0;
  for (ll i = 2; i <= s; i++) {
    if ((n % i) == 0) {
      r = 0;
      do {
        r++;
        n = n / i;
      } while ((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if (n > s) {
    prim.push_back({n, 1});
  }
}

void solve() {
  string s;
  cin >> s;
  ll K;
  cin >> K;

  set<string> ss;
  rep(i, s.size()) {
    rep1(j, s.size() - i) {
      ss.insert(s.substr(i, j));
      //      cerr << s.substr(i, j) << " " ;
      if (ss.size() > 5)
        ss.erase(--ss.end());
    }
  }

  for (auto itr : ss) {
    K--;
    //    cerr << K <<  " " << itr << endl;
    if (K <= 0) {
      cout << itr << endl;
      break;
    }
  }
}

int main(void) {
  // ll t; cin >> t; rep(i, t)
  solve();
}
Problem p03355 (C++)

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<char, vector<string>> mp;

  int sLength = s.size();
  for (int i = 0; i < sLength; ++i) {
    vector<string> tmp;
    for (int j = 0; j < sLength - i; ++j) {
      mp[s[i]].push_back(s.substr(i, j + 1));
    }
  }
  int count = 0;
  k--;

  for (auto pair : mp) {
    std::sort(mp[pair.first].begin(), mp[pair.first].end());
    std::vector<string>::iterator new_end =
        std::unique(mp[pair.first].begin(), mp[pair.first].end());
    mp[pair.first].erase(new_end, mp[pair.first].end());

    if (count <= k && k < count + mp[pair.first].size()) {
      cout << mp[pair.first][k - count] << endl;
      return 0;
    } else {
      count += mp[pair.first].size();
    }
  }

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<char, vector<string>> mp;

  int sLength = s.size();
  for (int i = 0; i < sLength; ++i) {
    vector<string> tmp;
    for (int j = 0; j < 5; ++j) {
      mp[s[i]].push_back(s.substr(i, j + 1));
    }
  }
  int count = 0;
  k--;

  for (auto pair : mp) {
    std::sort(mp[pair.first].begin(), mp[pair.first].end());
    std::vector<string>::iterator new_end =
        std::unique(mp[pair.first].begin(), mp[pair.first].end());
    mp[pair.first].erase(new_end, mp[pair.first].end());

    if (count <= k && k < count + mp[pair.first].size()) {
      cout << mp[pair.first][k - count] << endl;
      return 0;
    } else {
      count += mp[pair.first].size();
    }
  }

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int cnt = 0;
  set<string> moji;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < S.size(); j++) {
      if (S.at(j) == 'a' + i) {
        cnt += S.size() - j;
        string z = string() + S.at(j);
        moji.insert(z);
      }
    }
    if (moji.size() >= 3) {
      break;
    }
    if (cnt >= 15) {
      break;
    }
  }

  set<string> ans;

  for (auto itr = moji.begin(); itr != moji.end(); itr++) {
    string x = *itr;
    for (int i = 0; i < S.size(); i++) {
      if (S.at(i) + string() == x) {
        string T = x;
        ans.insert(T);
        for (int j = i + 1; j < S.size(); j++) {
          T += S.at(j);
          ans.insert(T);
        }
      }
    }
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int cnt = 0;
  set<string> moji;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < S.size(); j++) {
      if (S.at(j) == 'a' + i) {
        cnt += S.size() - j;
        string z = string() + S.at(j);
        moji.insert(z);
      }
    }
    if (moji.size() >= 3) {
      break;
    }
    if (cnt >= 15) {
      break;
    }
  }

  set<string> ans;

  for (auto itr = moji.begin(); itr != moji.end(); itr++) {
    string x = *itr;
    for (int i = 0; i < S.size(); i++) {
      if (S.at(i) + string() == x) {
        string T = x;
        ans.insert(T);
        for (int j = i + 1; j < S.size(); j++) {
          T += S.at(j);
          ans.insert(T);
          if (j >= i + 6) {
            break;
          }
        }
      }
    }
  }

  auto itr = ans.begin();
  for (int i = 0; i < K - 1; i++) {
    itr++;
  }
  cout << *itr << endl;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  ll k;
  cin >> s >> k;
  ll l = s.length();
  set<string> st;
  for (ll pos = 0; pos < l; ++pos) {
    for (ll num = 1; pos + num <= l; ++num)
      st.insert(s.substr(pos, num));
  }
  ll cnt = 1;
  for (auto e : st) {
    if (cnt == k)
      print(e);
    cnt++;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  ll k;
  cin >> s >> k;
  ll l = s.length();
  set<string> st;
  for (ll pos = 0; pos < l; ++pos) {
    for (ll num = 1; num < 6; ++num)
      st.insert(s.substr(pos, num));
  }
  ll cnt = 1;
  for (auto e : st) {
    if (cnt == k)
      print(e);
    cnt++;
  }
  return 0;
}
Problem p03355 (C++)

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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  set<string> a;
  ll c = 0;
  rep(i, 0, n) {
    rep(j, 1, n - i + 1) { a.insert(s.substr(i, j)); }
  }
  ll cnt = 1;
  for (auto e : a) {
    if (cnt == k) {
      cout << e << endl;
      break;
    }
    cnt++;
  }
  return 0;
}

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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  set<string> a;
  ll c = 0;
  rep(i, 0, n) {
    rep(j, 1, min(k + 1, n - i + 1)) { a.insert(s.substr(i, j)); }
  }
  ll cnt = 1;
  for (auto e : a) {
    if (cnt == k) {
      cout << e << endl;
      break;
    }
    cnt++;
  }
  return 0;
}
Problem p03355 (C++)

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  int n = s.length();
  vector<string> sub;
  REP(i, n) for (int j = i; j < n; ++j) sub.push_back(s.substr(i, j - i + 1));
  sort(ALL(sub));
  sub.erase(unique(ALL(sub)), sub.end());
  cout << sub[K - 1] << endl;
  return 0;
}


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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  int n = s.length();
  vector<string> sub;
  REP(i, n) REP(j, K) sub.push_back(s.substr(i, min(j + 1, n - i + 1)));
  sort(ALL(sub));
  sub.erase(unique(ALL(sub)), sub.end());
  cout << sub[K - 1] << endl;
  return 0;
}
Problem p03355 (C++)

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

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

  vector<string> sub;
  for (int i = 1; i <= 5; i++)
    for (int j = 0; j <= s.size() - i; j++)
      sub.push_back(s.substr(j, i));

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

  string prev;
  int ans;
  for (int i = 0; i < sub.size(); i++) {
    if (sub[i] != prev) {
      prev = sub[i];
      K--;
    }

    if (K == 0) {
      ans = i;
      break;
    }
  }

  cout << sub[ans] << endl;

  return 0;
}

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

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

  vector<string> sub;
  for (int i = 1; i <= min((int)s.size(), K); i++)
    for (int j = 0; j <= s.size() - i; j++)
      sub.push_back(s.substr(j, i));

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

  string prev;
  int ans;
  for (int i = 0; i < sub.size(); i++) {
    if (sub[i] != prev) {
      prev = sub[i];
      K--;
    }

    if (K == 0) {
      ans = i;
      break;
    }
  }

  cout << sub[ans] << endl;

  return 0;
}
Problem p03355 (C++)

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

int main() {
  std::string str;
  int n;
  std::cin >> str >> n;
  std::set<char> chs;
  std::map<char, std::deque<int>> pos;
  for (auto i = 0; i < str.size(); i++) {
    chs.insert(str[i]);
    pos[str[i]].push_back(i);
  }

  for (auto c : chs) {
    std::set<std::string> s;
    for (auto i : pos[c]) {
      for (auto j = 1; j <= str.size() - i; j++) {
        s.insert(str.substr(i, j));
      }
    }
    if (s.size() >= n) {
      auto it = s.begin();
      std::advance(it, n - 1);
      std::cout << *it << std::endl;
      return 0;
    }
    n -= s.size();
  }

  return 0;
}

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

int main() {
  std::string str;
  int n;
  std::cin >> str >> n;
  std::set<char> chs;
  std::map<char, std::deque<int>> pos;
  for (auto i = 0; i < str.size(); i++) {
    chs.insert(str[i]);
    pos[str[i]].push_back(i);
  }

  for (auto c : chs) {
    std::set<std::string> s;
    for (auto i : pos[c]) {
      for (auto j = 1; j <= std::min(5ul, str.size() - i); j++) {
        s.insert(str.substr(i, j));
      }
    }
    if (s.size() >= n) {
      auto it = s.begin();
      std::advance(it, n - 1);
      std::cout << *it << std::endl;
      return 0;
    }
    n -= s.size();
  }

  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main() {
  string ss;
  cin >> ss;
  int64 kk;
  cin >> kk;
  set<string> memo;
  for (int64 ii = 0; ii < ss.length(); ii++) {
    for (int64 jj = 1; jj <= (ss.length() - ii); jj++) {
      memo.insert(ss.substr(ii, jj));
    }
  }
  set<string>::iterator ite = memo.begin();
  for (int64 ii = 1; ii < kk; ii++) {
    ite++;
  }
  cout << *ite << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main() {
  string ss;
  cin >> ss;
  int64 kk;
  cin >> kk;
  set<string> memo;
  for (int64 ii = 0; ii < ss.length(); ii++) {
    for (int64 jj = 1; jj <= kk + 2; jj++) {
      memo.insert(ss.substr(ii, jj));
    }
  }
  set<string>::iterator ite = memo.begin();
  for (int64 ii = 1; ii < kk; ii++) {
    ite++;
  }
  cout << *ite << endl;
  return 0;
}
Problem p03355 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  string s;
  int K;
  cin >> s >> K;
  set<string> S;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= s.size(); j++) {
      if (j - i > 5)
        break;
      if (j == 0)
        continue;
      string ss = s.substr(i, j);
      S.insert(ss);
    }
  }
  vector<string> ans;
  for (auto it : S)
    ans.push_back(it);
  sort(rng(ans));
  cout << ans[K - 1] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  string s;
  int K;
  cin >> s >> K;
  set<string> S;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= 5; j++) {
      if (j == 0)
        continue;
      string ss = s.substr(i, j);
      S.insert(ss);
    }
  }
  vector<string> ans;
  for (auto it : S)
    ans.push_back(it);
  sort(rng(ans));
  cout << ans[K - 1] << endl;
  return 0;
}
Problem p03355 (C++)

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

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

  int cnt = 0;
  for (auto x : ans) {
    if (cnt == K - 1) {
      cout << x << endl;
      break;
    }
    cnt++;
  }

  return 0;
}

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

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

  int cnt = 0;
  for (auto x : ans) {
    if (cnt == K - 1) {
      cout << x << endl;
      break;
    }
    cnt++;
  }

  return 0;
}
Problem p03355 (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> v;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j < s.size() - i + 1; ++j) {
      v.push_back(s.substr(i, j));
    }
  }

  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
  cout << v[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> v;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= min(5, (int)s.size() - i); ++j) {
      v.push_back(s.substr(i, j));
    }
  }

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

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define MOD (1000000007LL)
#define MODA(a, b) a = ((a) + (b)) % MOD
#define MODP(a, b) a = ((a) * (b)) % MOD
#define inc(i, l, r) for (int i = (l); i < (r); i++)
#define dec(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))

using LL = long long;
using G = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

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


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define MOD (1000000007LL)
#define MODA(a, b) a = ((a) + (b)) % MOD
#define MODP(a, b) a = ((a) * (b)) % MOD
#define inc(i, l, r) for (int i = (l); i < (r); i++)
#define dec(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))

using LL = long long;
using G = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  set<string> st;
  for (int i = 1; i <= min(10, n); i++) {
    for (int j = 0; j < n - i + 1; j++) {
      st.insert(s.substr(j, i));
    }
  }
  vector<string> v;
  for (auto ss : st) {
    v.push_back(ss);
  }
  sort(v.begin(), v.end());
  cout << v[k - 1] << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> sub; // 部分文字列を全列挙
  for (int i = 0; i < (int)s.size(); i++) {
    for (int j = s.size() - i; j > 0; j--)
      sub.insert(s.substr(i, j));
  }
  int num = 1;
  for (auto v : sub) {
    if (num != K) {
      num++;
      sub.erase(*begin(sub));
    } else {
      cout << *begin(sub) << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  string s;
  int K;
  cin >> s >> K;
  set<string> sub; // 部分文字列を全列挙
  for (int i = 0; i < (int)s.size(); i++) {
    for (int j = min(K, (int)s.size() - i); j > 0; j--)
      sub.insert(s.substr(i, j));
  }
  int num = 1;
  for (auto v : sub) {
    if (num != K) {
      num++;
      sub.erase(*begin(sub));
    } else {
      cout << *begin(sub) << endl;
      return 0;
    }
  }
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef pii point;
using namespace std;

int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll N = S.length();
  unordered_set<string> v;
  REP(i, N) {
    FOR(j, 1, N - i + 1) { v.insert(S.substr(i, j)); }
  }
  vector<string> a;
  for (string s : v)
    a.push_back(s);
  sort(a.begin(), a.end());
  cout << a[K - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef pii point;
using namespace std;

int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll N = S.length();
  unordered_set<string> v;
  REP(i, N) {
    ll t = min(N - i + 1, 6ll);
    FOR(j, 1, t) { v.insert(S.substr(i, j)); }
  }
  vector<string> a;
  for (string s : v)
    a.push_back(s);
  sort(a.begin(), a.end());
  cout << a[K - 1] << endl;
}
Problem p03355 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = (j); i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; (j) <= i; --i)

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

ll n, a, b;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  cin >> a;
  n = (int)s.size();

  vector<string> list;
  rep(i, 0, n) {
    rep(j, i, n) { list.push_back(s.substr(i, j - i + 1)); }
  }
  sort(list.begin(), list.end());
  list.erase(unique(list.begin(), list.end()), list.end());

  cout << list[a - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = (j); i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; (j) <= i; --i)

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

ll n, a, b;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  cin >> a;
  n = (int)s.size();

  vector<string> list;
  rep(i, 0, n) {
    rep(j, 1, a + 1) { list.push_back(s.substr(i, j)); }
  }
  sort(list.begin(), list.end());
  list.erase(unique(list.begin(), list.end()), list.end());

  cout << list[a - 1] << endl;
  return 0;
}
Problem p03355 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(), in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> P;

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

  vector<string> ans;

  rep(i, m + 1) rep(j, m + 1) if (i < j) ans.push_back(s.substr(i, j - i));
  sort(all(ans));
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  cout << ans[n - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(), in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> P;

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

  vector<string> ans;

  rep(i, m + 1) rep(j, m + 1) if (i < j) {
    ans.push_back(s.substr(i, j - i));
    sort(all(ans));
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    if (ans.size() > n)
      ans.pop_back();
  }
  cout << ans[n - 1] << endl;
}
Problem p03355 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  string s;
  cin >> s;
  int K;
  cin >> K;
  map<string, int> m;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; i + j <= s.size(); j++) {
      if (j == 0)
        continue;
      m[s.substr(i, j)]++;
    }
  }
  auto it = m.begin();
  advance(it, K - 1);
  cout << it->first << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  string s;
  cin >> s;
  int K;
  cin >> K;
  map<string, int> m;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= K && i + j <= s.size(); j++) {
      if (j == 0)
        continue;
      m[s.substr(i, j)]++;
    }
  }
  auto it = m.begin();
  advance(it, K - 1);
  cout << it->first << endl;
  return 0;
}
Problem p03355 (C++)

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

using namespace std;

int main() {
  set<string> vs;
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.length();
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= N - i; j++) {
      vs.insert(S.substr(i, j));
    }
  }
  auto itr = vs.begin();
  for (int i = 0; i < K - 1; i++)
    ++itr;
  cout << *itr << endl;
  return 0;
}

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

using namespace std;

int main() {
  set<string> vs;
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.length();
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      vs.insert(S.substr(i, j));
    }
  }
  auto itr = vs.begin();
  for (int i = 0; i < K - 1; i++)
    ++itr;
  cout << *itr << endl;
  return 0;
}
Problem p03355 (C++)

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

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

  cin >> s >> k;

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

  auto itr = sub.begin();
  for (int i = 1; i < k; i++)
    ++itr;

  cout << *itr;

  return 0;
}

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

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

  cin >> s >> k;

  for (int i = 0; i < (int)s.length(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j > (int)s.length())
        break;
      sub.insert(s.substr(i, j));
    }
  }

  auto itr = sub.begin();
  for (int i = 1; i < k; i++)
    ++itr;

  cout << *itr;

  return 0;
}