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;
  int k;
  cin >> s >> k;

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

  // for (auto& e : sub) {
  //   cout << e << endl;
  // }

  auto iter = sub.begin();
  for (int i = 0; i < k - 1; i++) {
    iter++;
  }
  cout << *iter << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;

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

  // for (auto& e : sub) {
  //   cout << e << endl;
  // }

  auto iter = sub.begin();
  for (int i = 0; i < k - 1; i++) {
    iter++;
  }
  cout << *iter << 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++)

string s;
int K;
set<string> subs;

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

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

  cout << *(subs.rbegin()) << 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 < (int)N; i++)

string s;
int K;
set<string> subs;

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

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

  cout << *(subs.rbegin()) << endl;

  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> substr;
  int j = 1;
  while (1) {
    if (j > s.size())
      break;
    for (int i = 0; i < s.size() + 1 - j; i++) {
      substr.insert(s.substr(i, j));
    }
    j += 1;
  }
  vector<string> ans(substr.begin(), substr.end());
  cout << ans[k - 1] << endl;
  return 0;
}

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> substr;
  int j = 1;
  while (1) {
    if (j > fmin(5, s.size()))
      break;
    for (int i = 0; i < s.size() + 1 - j; i++) {
      substr.insert(s.substr(i, j));
    }
    j += 1;
  }
  vector<string> ans(substr.begin(), substr.end());
  cout << ans[k - 1] << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORL(i, a, b) for (ll i = (a); i < (b); ++i)
#define REPL(i, n) FORL(i, 0, n)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REPR(i, n) FORR(i, n, 0)

using namespace std;

int main() {
  string s;
  int K;
  cin >> s;
  scanf("%d", &K);

  vector<string> ST;

  REP(i, s.length()) {
    FOR(j, 1, K) {
      string c = s.substr(i, j);
      ST.push_back(c);
    }
  }

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

  auto itr = ST.begin() + K - 1;
  cout << *itr << endl;

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORL(i, a, b) for (ll i = (a); i < (b); ++i)
#define REPL(i, n) FORL(i, 0, n)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REPR(i, n) FORR(i, n, 0)

using namespace std;

int main() {
  string s;
  int K;
  cin >> s;
  scanf("%d", &K);

  vector<string> ST;

  REP(i, s.length()) {
    FOR(j, 1, K + 1) {
      string c = s.substr(i, j);
      ST.push_back(c);
    }
  }

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

  auto itr = ST.begin() + K - 1;
  cout << *itr << endl;

  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  int N;
  cin >> s;
  cin >> N;
  vector<string> t;
  string tmp;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j >= s.size())
        break;
      tmp = s.substr(i, j);
      t.push_back(tmp);
    }
  }

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

  cout << t[N - 1] << endl;
}


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

int main() {
  string s;
  int N;
  cin >> s;
  cin >> N;
  vector<string> t;
  string tmp;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j <= s.size()) {
        tmp = s.substr(i, j);
        t.push_back(tmp);
      }
    }
  }

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

  cout << t[N - 1] << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <chrono>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ull = unsigned long long int;

#define rep(i, n, m) for (long long int i = n; i < (long long int)(m); i++)
#define INF (1 << 29)
#define MD 1000000007

int main() {

  string str;
  int k;

  cin >> str >> k;

  vector<string> word;

  rep(i, 0, str.length()) {
    rep(j, 1, k + 1) {
      if (i + j < str.length()) {
        word.push_back(str.substr(i, j));
      }
    }
  }

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

  cout << word[k - 1] << endl;

  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <chrono>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ull = unsigned long long int;

#define rep(i, n, m) for (long long int i = n; i < (long long int)(m); i++)
#define INF (1 << 29)
#define MD 1000000007

int main() {

  string str;
  int k;

  cin >> str >> k;

  vector<string> word;

  rep(i, 0, str.length()) {
    rep(j, 1, k + 1) {
      if (i + j <= str.length()) {
        word.push_back(str.substr(i, j));
      }
    }
  }

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

  cout << word[k - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

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

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

int main() {
  string s;
  int K;
  cin >> s >> K;
  int size = s.size();
  map<string, ll> mp;
  rep(1, i, 6) {
    rep(0, j, size - i + 1) {
      string sub = s.substr(j, i);
      mp[sub];
    }
  }
  int k = 1;
  for (auto m : mp) {
    if (k == K) {
      cout << m.first << endl;
    }
    k++;
  }
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007
using namespace std;

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  if (s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  vector<string> dic;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; i + j <= s.length(); j++) {
      string temp = s.substr(i, j);
      dic.push_back(temp);
    }
  }
  sort(dic.begin(), dic.end());
  int temp = 1;
  for (int i = 1; i < dic.size(); i++) {
    if (dic[i] != dic[i - 1])
      temp++;
    if (temp == k) {
      cout << dic[i] << endl;
      return 0;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007
using namespace std;

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  if (s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  vector<string> dic;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= k && i + j <= s.length(); j++) {
      string temp = s.substr(i, j);
      dic.push_back(temp);
    }
  }
  sort(dic.begin(), dic.end());
  int temp = 1;
  for (int i = 1; i < dic.size(); i++) {
    if (dic[i] != dic[i - 1])
      temp++;
    if (temp == k) {
      cout << dic[i] << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> strs;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; i + j - 1 < s.size(); j++) {
      string ss = s.substr(i, j);
      strs.insert(ss);
    }
  }
  int cnt = 0;
  for (auto ss : strs) {
    cnt++;
    if (cnt == k) {
      cout << ss << endl;
      break;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> strs;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      string ss = s.substr(i, j);
      strs.insert(ss);
    }
  }
  int cnt = 0;
  for (auto ss : strs) {
    cnt++;
    if (cnt == k) {
      cout << ss << endl;
      break;
    }
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < N; i++)

long long INF = 1000000000000000000;
long long mod = 1000000007;
using namespace std;

int main() {

  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<vector<int>> v(26); // 各alphabetの文字の格納位置

  rep(i, s.size()) { v[s[i] - 'a'].push_back(i); }
  set<string> ans;
  int cnt = 0;
  rep(i, 26) {
    int t = 0;
    if (v[i].empty())
      continue;
    while (t < v[i].size()) {
      int start = v[i][t];
      string p;
      while (start < s.size()) {
        p.append(1, s[start]);
        if (ans.find(p) == ans.end()) {
          ans.insert(p);
          cnt++;
        }
        start++;
      }
      t++;
    }
    if (cnt >= k)
      break;
  }

  auto it = ans.begin();

  it = next(it, k - 1);

  cout << *it << endl;

  return 0;
}
/*
aba
4

b

atcoderandatcodeer
5

andat

z
1

z
*/

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < N; i++)

long long INF = 1000000000000000000;
long long mod = 1000000007;
using namespace std;

int main() {

  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<vector<int>> v(26); // 各alphabetの文字の格納位置

  rep(i, s.size()) { v[s[i] - 'a'].push_back(i); }
  set<string> ans;
  int cnt = 0;
  rep(i, 26) {
    int t = 0;
    if (v[i].empty())
      continue;
    while (t < v[i].size()) {
      int start = v[i][t];
      string p;
      while (start < s.size() && p.size() <= k) {
        p.append(1, s[start]);
        if (ans.find(p) == ans.end()) {
          ans.insert(p);
          cnt++;
        }
        start++;
      }
      t++;
    }
    if (cnt >= k)
      break;
  }

  auto it = ans.begin();

  it = next(it, k - 1);

  cout << *it << endl;

  return 0;
}
/*
aba
4

b

atcoderandatcodeer
5

andat

z
1

z
*/
Problem p03353 (C++)

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

using namespace std;

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

  cin >> s;
  cin >> K;

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

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

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

using namespace std;

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

  cin >> s;
  cin >> K;

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

  auto itr = set_.begin();
  for (int i = 1; i < K; i++) {
    itr++;
  }
  cout << *(itr) << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
  for (const T &v : vs)
    os << v << " ";
  return os;
}
int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N = s.size();
  set<string> ss;
  for (int i = 0; i < N; ++i) {
    string x;
    for (int j = 0; i + j < N; ++j) {
      x += s[i + j];
      ss.insert(x);
    }
  }
  auto it = ss.begin();
  for (int i = 0; i < K - 1; ++i)
    ++it;
  cout << *it << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
  for (const T &v : vs)
    os << v << " ";
  return os;
}
int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N = s.size();
  set<string> ss;
  for (int i = 0; i < N; ++i) {
    string x;
    for (int j = 0; i + j < N && j <= 5; ++j) {
      x += s[i + j];
      ss.insert(x);
    }
  }
  auto it = ss.begin();
  for (int i = 0; i < K - 1; ++i)
    ++it;
  cout << *it << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#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()
#define ll long long
#define INF 1000000000000000000

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  map<string, int> ma;
  int N = s.size();
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= N; j++) {
      string ss = s.substr(i, j);
      ma[ss] = 1;
    }
  }

  int i = 0;
  for (auto m : ma) {
    if (i == K - 1) {
      cout << m.first << endl;
      return 0;
    }
    i++;
  }
}

Fixed submission:
#include <algorithm>
#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()
#define ll long long
#define INF 1000000000000000000

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  map<string, int> ma;
  int N = s.size();
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      string ss = s.substr(i, j);
      ma[ss] = 1;
    }
  }

  int i = 0;
  for (auto m : ma) {
    if (i == K - 1) {
      cout << m.first << endl;
      return 0;
    }
    i++;
  }
}
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, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  set<string> subs;

  rep2(i, 1, s.size() + 1) {
    rep(j, s.size() - i + 1) subs.insert(s.substr(j, i));
  }

  auto it = subs.begin();
  rep(i, K - 1) it++;

  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, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  set<string> subs;

  rep(i, s.size()) {
    ll max_len = min((ll)5, (ll)(s.size() - i));

    rep2(j, 1, max_len + 1) subs.insert(s.substr(i, j));
  }

  auto it = subs.begin();
  rep(i, K - 1) it++;

  cout << (*it) << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k, n, i, j;
  set<string> z;
  cin >> s >> k;
  n = s.length();
  for (i = 0; i < n; i++)
    for (j = 1; j <= n - i; j++)
      z.insert(s.substr(i, j));
  cout << *next(z.begin(), k - 1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k, n, i, j;
  set<string> z;
  cin >> s >> k;
  n = s.length();
  for (i = 0; i < n; i++)
    for (j = 1; j <= min(n - i, 5); j++)
      z.insert(s.substr(i, j));
  cout << *next(z.begin(), k - 1) << endl;
}
Problem p03353 (C++)

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

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

  vector<string> t;

  for (int k = 0; k < (int)(s.size() - 1); k++) {
    for (int l = 0; l < 5; l++) {
      t.push_back(s.substr(k, l + 1));
    }
  }
  sort(t.begin(), t.end());
  unique(t.begin(), t.end());
  cout << t[pos - 1] << endl;
}

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

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

  vector<string> t;

  for (int k = 0; k < (int)s.size(); k++) {
    for (int l = 0; l < 5; l++) {
      t.push_back(s.substr(k, l + 1));
    }
  }
  sort(t.begin(), t.end());
  unique(t.begin(), t.end());
  cout << t[pos - 1] << endl;
}
Problem p03353 (C++)

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v)                                                                 \
  cerr << "- " << #v << endl;                                                  \
  rep(i, v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a, b) ((a) + ((b)-1)) / (b)
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template <class T> T gcd(const T &a, const T &b) {
  return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  vector<string> a;
  rep(i, n) rep(j, n - i) {
    string t = s.substr(i, j + 1);
    a.push_back(t);
  }
  sort(ALL(a));
  UNIQUE(a);
  string ans = a[k - 1];
  cout << ans << endl;
}


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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v)                                                                 \
  cerr << "- " << #v << endl;                                                  \
  rep(i, v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a, b) ((a) + ((b)-1)) / (b)
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template <class T> T gcd(const T &a, const T &b) {
  return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  vector<string> a;
  rep(i, n) {
    int len = min(n - i, k);
    rep(j, len) {
      string t = s.substr(i, j + 1);
      a.push_back(t);
    }
  }
  sort(ALL(a));
  UNIQUE(a);
  string ans = a[k - 1];
  cout << ans << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()   // reverse
#define strall(v) (v).cbegin(), (v).cend() // const_itterator
#define IN(a, b, x) (a <= x && x < b)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<ll>>;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename t, typename u, typename Comp = less<>>
bool chmax(t &xmax, const u &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}
template <typename t, typename u, typename Comp = less<>>
bool chmin(t &xmin, const u &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}
const int INF = 1e9;
const ll infl = ll(1e18) + 5;

/*
 *ios::sync_with_stdio(false);
 *cin.tie(0);
 */

int main() {
  set<string> st;
  string str;
  int k;
  cin >> str >> k;
  for (int i = 0; i < str.size(); i++) {
    for (int j = 1; i + j <= str.size(); j++) {
      st.insert(str.substr(i, j));
    }
  }
  int cnt = 1;
  string ans;
  for (auto s : st) {
    if (k == cnt)
      ans = s;
    cnt++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()   // reverse
#define strall(v) (v).cbegin(), (v).cend() // const_itterator
#define IN(a, b, x) (a <= x && x < b)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<ll>>;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename t, typename u, typename Comp = less<>>
bool chmax(t &xmax, const u &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}
template <typename t, typename u, typename Comp = less<>>
bool chmin(t &xmin, const u &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}
const int INF = 1e9;
const ll infl = ll(1e18) + 5;

/*
 *ios::sync_with_stdio(false);
 *cin.tie(0);
 */

int main() {
  set<string> st;
  string str;
  int k;
  cin >> str >> k;
  for (int i = 0; i < str.size(); i++) {
    for (int j = 1; j <= k; j++) {
      st.insert(str.substr(i, j));
    }
  }
  int cnt = 1;
  string ans;
  for (auto s : st) {
    if (k == cnt)
      ans = s;
    cnt++;
  }
  cout << ans << endl;
}
Problem p03353 (C++)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main() {
  string s;
  cin >> s;
  int K;
  scanf("%d", &K);
  set<string> cong;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    for (int len = 1; i + len <= n; ++len) {
      cong.insert(s.substr(i, len));
    }
  }
  vector<string> v(cong.begin(), cong.end());
  sort(v.begin(), v.end());
  printf("%s\n", v[K - 1].c_str());
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main() {
  string s;
  cin >> s;
  int K;
  scanf("%d", &K);
  set<string> cong;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    for (int len = 1; len <= K; ++len) {
      cong.insert(s.substr(i, len));
    }
  }
  vector<string> v(cong.begin(), cong.end());
  sort(v.begin(), v.end());
  printf("%s\n", v[K - 1].c_str());
  return 0;
}
Problem p03353 (C++)

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

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


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

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= min(5, (int)s.size() - i); ++j) {
      st.insert(s.substr(i, j));
    }
  }
  for (auto &&i : st) {
    if (--k == 0) {
      cout << i << "\n"s;
      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 rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> data;
  rep(i, s.size()) {
    rep3(j, 1, k) { data.insert(s.substr(i, j)); }
  }
  auto itr = data.begin();
  rep(i, k) itr++;
  cout << *itr << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> data;
  rep(i, s.size()) {
    rep3(j, 1, k) { data.insert(s.substr(i, j)); }
  }
  auto itr = data.begin();
  rep(i, k - 1) itr++;
  cout << *itr << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

// #include<bits/stdc++.h>

int main() {

  string s;
  cin >> s;
  int n;
  cin >> n;
  int x = s.size();
  vector<string> z;
  map<string, bool> v;
  for (int i = 0; i < x; i++) {
    string p;
    for (int j = i; j < x; j++) {

      p += s[j];
      if (!v[p])
        z.push_back(p);
      v[p] = 1;
    }
  }
  sort(z.begin(), z.end());
  cout << z[n - 1] << endl;

  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

// #include<bits/stdc++.h>

int main() {

  string s;
  cin >> s;
  int n;
  cin >> n;
  int x = s.size();
  vector<string> z;
  map<string, bool> v;
  for (int i = 0; i < x; i++) {
    string p;
    for (int j = i; j < min(x, i + 6); j++) {

      p += s[j];
      if (!v[p])
        z.push_back(p);
      v[p] = 1;
    }
  }
  sort(z.begin(), z.end());
  cout << z[n - 1] << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9 + 7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

long long int gcd(long long int m, long long int n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
long long int lcm(long long int number1, long long int number2) {
  return number1 * number2 / gcd(number1, number2);
}
int main() {

  string S;
  cin >> S;
  ll K;
  cin >> K;
  vector<string> date;

  for (ll i = 1; i <= K + 1; i++) {
    for (ll j = 0; j <= S.size() - i; j++) {
      if (j + i - 1 <= S.size() - 1) {
        date.push_back(S.substr(j, i));
      }
    }
  }

  sort(all(date));
  unique(all(date));

  cout << date[K - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9 + 7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

long long int gcd(long long int m, long long int n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
long long int lcm(long long int number1, long long int number2) {
  return number1 * number2 / gcd(number1, number2);
}
int main() {

  string S;
  cin >> S;
  ll K;
  cin >> K;
  vector<string> date;

  for (ll i = 1; i <= min(K, S.size()); i++) {
    for (ll j = 0; j <= S.size() - i; j++) {
      if (j + i - 1 <= S.size() - 1) {
        date.push_back(S.substr(j, i));
      }
    }
  }

  sort(all(date));
  unique(all(date));

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

Buggy submission (status: Runtime Error):
/**
 *      ABC 97 C
 *      author  : kyomukyomupurin
 *      created : 2018-10-05 12:54:41
 **/

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

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

  string s;
  cin >> s;
  int_fast16_t K;
  cin >> K;

  vector<string> sub;

  for (auto i = 1; i <= (int_fast32_t)s.size(); ++i) {
    for (auto j = 0; j < (int_fast32_t)s.size() - i + 1; ++j) {
      sub.push_back(s.substr(j, i));
    }
  }

  sort(sub.begin(), sub.end());
  auto result = unique(sub.begin(), sub.end());
  sub.erase(result, sub.end());

  cout << sub[K - 1] << '\n';
  return 0;
}

Fixed submission:
/**
 *      ABC 97 C
 *      author  : kyomukyomupurin
 *      created : 2018-10-05 12:54:41
 **/

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

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

  string s;
  cin >> s;
  int_fast16_t K;
  cin >> K;

  vector<string> sub;

  for (auto i = 1; i <= min(K, (int_fast32_t)s.size()); ++i) {
    for (auto j = 0; j < (int_fast32_t)s.size() - i + 1; ++j) {
      sub.push_back(s.substr(j, i));
    }
  }

  sort(sub.begin(), sub.end());
  auto result = unique(sub.begin(), sub.end());
  sub.erase(result, sub.end());

  cout << sub[K - 1] << '\n';
  return 0;
}
Problem p03353 (C++)

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream &operator>>(istream &I, vector<T> &v) {
  for (T &e : v)
    I >> e;
  return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
  for (const T &e : v)
    O << e << ' ';
  return O;
}

void _main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = sz(s);
  vector<string> a;
  for (int i = 0; i < n; i++) {
    string ss;
    for (int j = i; j < n; j++) {
      ss += s[j];
      a.emplace_back(ss);
    }
  }

  sort(all(a));
  a.resize(unique(all(a)) - a.begin());
  cout << a[k - 1] << '\n';
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //        freopen("input.txt", "r", stdin);
  int _t = 1;
  //        cin >> _t;
  while (_t--)
    _main();
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream &operator>>(istream &I, vector<T> &v) {
  for (T &e : v)
    I >> e;
  return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
  for (const T &e : v)
    O << e << ' ';
  return O;
}

void _main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = sz(s);
  vector<string> a;
  for (int i = 0; i < n; i++) {
    string ss;
    for (int j = i; j < n && j - i + 1 <= k; j++) {
      ss += s[j];
      a.emplace_back(ss);
    }
  }

  sort(all(a));
  a.resize(unique(all(a)) - a.begin());
  cout << a[k - 1] << '\n';
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //        freopen("input.txt", "r", stdin);
  int _t = 1;
  //        cin >> _t;
  while (_t--)
    _main();
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long int lli;
const int MaxN = 200005;
#define fst first
#define snd second
#define mp make_pair
lli mcd(lli a, lli b) {
  if (a == 0)
    return b;
  return mcd(b % a, a);
}
set<string> res;
int main() {
  lli t, N, Q, i, j, p, q, c = 0;
  string word;
  string aux;
  cin >> word;
  N = word.size();
  cin >> Q;
  for (i = 0; i < N; i++) {
    aux = word[i];
    res.insert(aux);
    for (j = i + 1; j < N; j++) {
      aux.push_back(word[j]);
      res.insert(aux);
    }
  }
  set<string>::iterator it;
  for (it = res.begin(); it != res.end(); it++) {
    c += 1;
    if (c == Q) {
      cout << *it;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long int lli;
const int MaxN = 200005;
#define fst first
#define snd second
#define mp make_pair
lli mcd(lli a, lli b) {
  if (a == 0)
    return b;
  return mcd(b % a, a);
}
set<string> res;
int main() {
  lli t, N, Q, i, j, p, q, c = 0;
  string word;
  string aux;
  cin >> word;
  N = word.size();
  cin >> Q;
  for (i = 0; i < N; i++) {
    aux = word[i];
    res.insert(aux);
    for (j = i + 1; j < min(lli(N), i + 50); j++) {
      aux.push_back(word[j]);
      res.insert(aux);
    }
  }
  set<string>::iterator it;
  for (it = res.begin(); it != res.end(); it++) {
    c += 1;
    if (c == Q) {
      cout << *it;
    }
  }
}
Problem p03353 (C++)

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

using namespace std;

using ll = long long;

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

  string s;
  int k;

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

  int cnt = 0;
  for (auto it : sub) {
    ++cnt;
    if (cnt == k) {
      cout << it << endl;
      break;
    }
  }

  return 0;
}


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

using namespace std;

using ll = long long;

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

  string s;
  int k;

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

  int cnt = 0;
  for (auto it : sub) {
    ++cnt;
    if (cnt == k) {
      cout << it << endl;
      break;
    }
  }

  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++)
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  string cur;
  map<string, int> m;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    cur = "";
    for (int j = i; j < n; j++) {
      cur += s[j];
      m[cur]++;
    }
  }
  auto p = m.begin();
  rep(i, k - 1) p++;
  cout << p->first << endl;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  string cur;
  map<string, int> m;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    cur = "";
    for (int j = i; j < i + k && j < n; j++) {
      cur += s[j];
      m[cur]++;
    }
  }
  auto p = m.begin();
  rep(i, k - 1) p++;
  cout << p->first << endl;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
  string s, t = "abcdefghijklmnopqrstupwxyz";
  cin >> s;
  ll k;
  cin >> k;
  ll ss = s.size(), cnt = 0, j = 0;
  vector<string> v;
  for (ll j = 0; j < 26; j++) {
    for (ll i = 0; i < ss; i++) {
      if (s[i] == t[j]) {
        for (ll l = 1; l <= (ss - i); l++) {
          string p = s.substr(i, l);
          ll a = 0;
          for (ll o = 0; o < v.size(); o++)
            if (p == v[o])
              a = 1;
          if (a != 1)
            cnt++, v.push_back(p);
        }
      }
    }
    if (cnt >= k)
      break;
  }
  sort(v.begin(), v.end());
  cout << v[k - 1] << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
  string s, t = "abcdefghijklmnopqrstupwxyz";
  cin >> s;
  ll k;
  cin >> k;
  ll ss = s.size(), cnt = 0, j = 0;
  vector<string> v;
  for (ll j = 0; j < 26; j++) {
    for (ll i = 0; i < ss; i++) {
      if (s[i] == t[j]) {
        for (ll l = 1; l <= (ss - i); l++) {
          if (l > k)
            break;
          string p = s.substr(i, l);
          ll a = 0;
          for (ll o = 0; o < v.size(); o++)
            if (p == v[o])
              a = 1;
          if (a != 1)
            cnt++, v.push_back(p);
        }
      }
    }
    if (cnt >= k)
      break;
  }
  sort(v.begin(), v.end());
  cout << v[k - 1] << endl;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  string str;
  int k;

  vector<string> vec;

  cin >> str;
  cin >> k;

  vec.push_back("");

  if (str.length() == (unsigned int)k) {
    cout << str << endl;
    return 0;
  }

  for (auto it1 = str.cbegin(); it1 != str.cend(); ++it1) {
    for (auto it2 = it1; it2 != str.cend(); ++it2) {
      string s = str.substr(it1 - str.cbegin(), it2 - it1 + 1);
      // cout << s << endl;
      if (s != "")
        vec.push_back(s);
    }
  }

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

  // for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
  //   string s = *it;
  //   cout << s << endl;
  // }

  for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
    if ((it - vec.cbegin()) == k) {
      string s = *it;
      cout << s << endl;
    }
  }

  return 0;
}


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

using namespace std;

int main() {
  string str;
  int k;

  vector<string> vec;

  cin >> str;
  cin >> k;

  vec.push_back("");

  if (str.length() == (unsigned int)k) {
    cout << str << endl;
    return 0;
  }

  for (auto it1 = str.cbegin(); it1 != str.cend(); ++it1) {
    for (auto it2 = it1; it2 != str.cend() && it2 - it1 <= 5; ++it2) {
      string s = str.substr(it1 - str.cbegin(), it2 - it1 + 1);
      // cout << s << endl;
      if (s != "")
        vec.push_back(s);
    }
  }

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

  // for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
  //   string s = *it;
  //   cout << s << endl;
  // }

  for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
    if ((it - vec.cbegin()) == k) {
      string s = *it;
      cout << s << endl;
    }
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  string s;
  int K;
  cin >> s >> K;
  vector<string> v;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      v.push_back(s.substr(i, j - i + 1));
    }
  }
  sort(v.begin(), v.end());
  set<string> a(v.begin(), v.end());
  vector<string> w(a.begin(), a.end());
  sort(w.begin(), w.end());
  /*for(int i=0;i<v.size();i++){
      cout<<w[i]<<endl;
  }*/
  cout << w[K - 1] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  string s;
  int K;
  cin >> s >> K;
  vector<string> v;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= 5; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  sort(v.begin(), v.end());
  set<string> a(v.begin(), v.end());
  vector<string> w(a.begin(), a.end());
  sort(w.begin(), w.end());
  /*for(int i=0;i<v.size();i++){
      cout<<w[i]<<endl;
  }*/
  cout << w[K - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

  int l = S.length();
  vector<string> dic;
  map<string, int> D;

  int count = 0;
  for (int i = 0; i < l; i++) {
    for (int j = 1; i + j <= l; j++) {
      string a = S.substr(i, j);
      if (D[a] == 0) {
        dic.push_back(a);
        count++;
      }
      D[a]++;
    }
  }

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

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

  return 0;
}

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

using namespace std;

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

  int l = S.length();
  vector<string> dic;
  map<string, int> D;

  int count = 0;
  for (int i = 0; i < l; i++) {
    for (int j = 1; i + j <= l && j <= 5; j++) {
      string a = S.substr(i, j);
      if (D[a] == 0) {
        dic.push_back(a);
        count++;
      }
      D[a]++;
    }
  }

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

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

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  string s;
  int k;
  cin >> s >> 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());
  sub.erase(unique(sub.begin(), sub.end()), sub.end());
  cout << sub.at(k - 1) << endl;
  return 0;
}


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

using namespace std;

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