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

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

using namespace std;

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

  uint64_t K;
  cin >> K;

  set<string> t;
  for (uint64_t left = 0; left < s.size(); ++left) {
    for (uint64_t length = 1; length <= s.size() - left; ++length) {
      // cerr << "[" << left << ", " << length << "]: " << s.substr(left,
      // length) << endl;
      t.insert(s.substr(left, length));
    }
  }

  auto itr = t.begin();
  advance(itr, K - 1);
  cout << *itr << endl;

  return 0;
}

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

using namespace std;

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

  uint64_t K;
  cin >> K;

  set<string> t;
  for (uint64_t left = 0; left < s.size(); ++left) {
    for (uint64_t length = 1; length <= K; ++length) {
      t.insert(s.substr(left, length));
    }
  }

  auto itr = t.begin();
  advance(itr, K - 1);
  cout << *itr << endl;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i, a, b) for (ll i = (a); i <= (ll)(b); ++i)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}

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

  set<string> st;

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

  // から文字列消すkesu
  st.erase("");
  int i = 1;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    if (i == k) {
      cout << *itr << endl;
      break;
    }
    i++;
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i, a, b) for (ll i = (a); i <= (ll)(b); ++i)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}

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

  set<string> st;

  rep(i, s.size()) {
    rep(j, s.size() - i + 1) {
      st.insert(s.substr(i, j));
      if (j > 5)
        break;
    }
  }

  // から文字列消すkesu
  st.erase("");
  int i = 1;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    if (i == k) {
      cout << *itr << endl;
      break;
    }
    i++;
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

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


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

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

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

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int N;
  cin >> N;
  vector<string> cand;
  for (int s = 0; s < S.size(); s++) {
    for (int e = s; e < S.size() && e - s + 1 <= N; e++) {
      cand.push_back(S.substr(s, e - s + 1));
    }
  }
  sort(cand.begin(), cand.end());
  unique(cand.begin(), cand.end());
  cout << cand[N - 2];
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int N;
  cin >> N;
  vector<string> cand;
  for (int s = 0; s < S.size(); s++) {
    for (int e = s; e < S.size() && e - s + 1 <= N; e++) {
      cand.push_back(S.substr(s, e - s + 1));
    }
  }
  sort(cand.begin(), cand.end());
  unique(cand.begin(), cand.end());
  cout << cand[N - 1];
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  string s;
  cin >> s;
  int ctr = 0, k;
  cin >> k;
  int siz = (int)s.size();
  map<string, int> mp;
  rep(i, siz) {
    FOR(j, 1, siz) {
      string subs = s.substr(i, j);
      if (mp[subs] >= 1)
        continue;
      mp[subs]++;
    }
  }
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    ctr++;
    if (ctr == k) {
      cout << itr->first << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  string s;
  cin >> s;
  int ctr = 0, k;
  cin >> k;
  int siz = (int)s.size();
  map<string, int> mp;
  rep(i, siz) {
    FOR(j, 1, k) {
      string subs = s.substr(i, j);
      if (mp[subs] >= 1)
        continue;
      mp[subs]++;
    }
  }
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    ctr++;
    if (ctr == k) {
      cout << itr->first << endl;
      break;
    }
  }
  return 0;
}
Problem p03353 (C++)

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

#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

using namespace std;

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


Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

using namespace std;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

  set<string> dic;

  for (int i = 0; i < n - 1; i++) {
    for (int j = 1; j + i <= n && j <= k; j++) {

      string sb = s.substr(i, j);

      // cout << sb << endl;
      dic.insert(sb);
    }
  }

  auto p = dic.begin();
  for (int i = 1; i < k; i++) {
    p++;
  }

  cout << *p << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

  set<string> dic;

  for (int i = 0; i < n; i++) {
    for (int j = 1; j + i <= n && j <= k; j++) {

      string sb = s.substr(i, j);

      // cout << sb << endl;
      dic.insert(sb);
    }
  }

  auto p = dic.begin();
  for (int i = 1; i < k; i++) {
    p++;
  }

  cout << *p << endl;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  string tmp;
  vector<string> fin;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size(); j++) {
      tmp = s.substr(i, j);
      fin.push_back(tmp);
    }
  }

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  string tmp;
  vector<string> fin;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k; j++) {
      tmp = s.substr(i, j);
      fin.push_back(tmp);
    }
  }

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

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

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

int main() {

  string s;
  cin >> s;
  int K;
  cin >> K;

  set<string> dict;
  for (char n = 'a'; n <= 'z'; n++) {
    int index = s.find(string{n});
    while (index != std::string::npos) {
      for (int i = 1; i <= s.length() - index; i++) {
        dict.insert(s.substr(index, i));
      }
      index = s.find(string{n}, index + 1);
    }
    if (dict.size() >= K)
      break;
  }

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

  return 0;
}

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

int main() {

  string s;
  cin >> s;
  int K;
  cin >> K;

  set<string> dict;
  for (char n = 'a'; n <= 'z'; n++) {
    int index = s.find(string{n});
    while (index != std::string::npos) {
      for (int i = 1; i <= min(K, (int)(s.length() - index)); i++) {
        dict.insert(s.substr(index, i));
      }
      index = s.find(string{n}, index + 1);
    }
    if (dict.size() >= K)
      break;
  }

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

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main(void) {
  string s;
  int k;
  cin >> s;
  cin >> k;
  vector<string> vec;
  for (int i = 0; i < s.size(); i++) {
    string ins = "";
    for (int j = i; j < s.size(); j++) {
      ins += s[j];
      vec.push_back(ins);
      // cout << ins << "\n";
    }
  }
  vector<string> ans;
  sort(vec.begin(), vec.end());
  ans.push_back(vec[0]);
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i] != vec[i - 1])
      ans.push_back(vec[i]);
  }
  cout << ans[k - 1];
  // cout << vec[k - 1];
}

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

using namespace std;

int main(void) {
  string s;
  int k;
  cin >> s;
  cin >> k;
  vector<string> vec;
  for (int i = 0; i < s.size(); i++) {
    string ins = "";
    for (int j = i; j < min(i + 5, (int)s.size()); j++) {
      ins += s[j];
      vec.push_back(ins);
      // cout << ins << "\n";
    }
  }
  vector<string> ans;
  sort(vec.begin(), vec.end());
  ans.push_back(vec[0]);
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i] != vec[i - 1])
      ans.push_back(vec[i]);
  }
  cout << ans[k - 1];
  // cout << vec[k - 1];
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define MOD 1000000007
using namespace std;
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;
}

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


Fixed submission:
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define MOD 1000000007
using namespace std;
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;
}

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

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

int main() {
  int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
  string s;
  string x[10];
  cin >> s;
  for (b = 0; b < 5; b++) {

    for (a = 0; a < s.length(); a++) {
      x[b] += "z";
    }
  }
  cin >> a;
  for (b = 0; b < s.length(); b++) {
    for (c = 1; c <= s.length() - b; c++) {
      if (s.substr(b, c) != x[0] && s.substr(b, c) != x[1] &&
          s.substr(b, c) != x[2] && s.substr(b, c) != x[3] &&
          s.substr(b, c) != x[4]) {

        if (s.substr(b, c) < x[0]) {

          x[4] = x[3];
          x[3] = x[2];
          x[2] = x[1];
          x[1] = x[0];
          x[0] = s.substr(b, c);
        } else if (s.substr(b, c) < x[1]) {
          x[4] = x[3];
          x[3] = x[2];
          x[2] = x[1];
          x[1] = s.substr(b, c);
        } else if (s.substr(b, c) < x[2]) {
          x[4] = x[3];
          x[3] = x[2];
          x[2] = s.substr(b, c);
        } else if (s.substr(b, c) < x[3]) {
          x[4] = x[3];
          x[3] = s.substr(b, c);
        } else if (s.substr(b, c) < x[4]) {
          x[4] = s.substr(b, c);
        }
      }
    }
  }

  cout << x[a - 1] << endl;

  return 0;
}


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

int main() {
  int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
  string s;
  string x[10];
  cin >> s;
  for (b = 0; b < 5; b++) {

    for (a = 0; a < s.length(); a++) {
      x[b] += "z";
    }
  }
  cin >> a;
  for (b = 0; b < s.length(); b++) {
    for (c = 1; c <= s.length() - b; c++) {
      if (s.substr(b, c) >= x[4]) {
        break;
      }
      if (s.substr(b, c) != x[0] && s.substr(b, c) != x[1] &&
          s.substr(b, c) != x[2] && s.substr(b, c) != x[3] &&
          s.substr(b, c) != x[4]) {

        if (s.substr(b, c) < x[0]) {

          x[4] = x[3];
          x[3] = x[2];
          x[2] = x[1];
          x[1] = x[0];
          x[0] = s.substr(b, c);
        } else if (s.substr(b, c) < x[1]) {
          x[4] = x[3];
          x[3] = x[2];
          x[2] = x[1];
          x[1] = s.substr(b, c);
        } else if (s.substr(b, c) < x[2]) {
          x[4] = x[3];
          x[3] = x[2];
          x[2] = s.substr(b, c);
        } else if (s.substr(b, c) < x[3]) {
          x[4] = x[3];
          x[3] = s.substr(b, c);
        } else if (s.substr(b, c) < x[4]) {
          x[4] = s.substr(b, c);
        }
      }
    }
  }

  cout << x[a - 1] << endl;

  return 0;
}
Problem p03353 (C++)

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  for (int i = 0; i < s.length(); i++) {
    string tmp = "";
    for (int j = i; j < s.length(); j++) {
      tmp += s[j];
      se.insert(tmp);
    }
  }

  int i = 0;
  for (set<string>::iterator it = se.begin(); it != se.end(); it++) {
    i++;
    if (i != k)
      continue;
    cout << *it << endl;
  }

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  for (int i = 0; i < s.length(); i++) {
    string tmp = "";
    int l = min(i + 5, (int)s.length());
    for (int j = i; j < l; j++) {
      tmp += s[j];
      se.insert(tmp);
    }
  }

  int i = 0;
  for (set<string>::iterator it = se.begin(); it != se.end(); it++) {
    i++;
    if (i != k)
      continue;
    cout << *it << endl;
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  set<string> st;
  REP(i, S.size()) {
    FOR(j, 1, S.size() - i + 1) { st.insert(S.substr(i, j)); }
  }

  auto itr = st.begin();
  REP(i, K - 1) { itr++; }
  cout << *itr << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  set<string> st;
  REP(i, S.size()) {
    FOR(j, 1, 6) { st.insert(S.substr(i, min(j, (int)S.size() - i))); }
  }

  auto itr = st.begin();
  REP(i, K - 1) { itr++; }
  cout << *itr << endl;
}
Problem p03353 (C++)

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

int main() {
  string s, sub;
  int K, cost;
  cin >> s >> K;
  vector<string> v;

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

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

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

  return 0;
}

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

int main() {
  string s, sub;
  int K, cost;
  cin >> s >> K;
  vector<string> v;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= K; j++) {
      sub = s.substr(i, j);
      v.push_back(sub);
    }
  }

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

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

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  map<string, int> mp;
  for (int i = 0; i <= n - 1; i++) {   // 始点
    for (int j = 1; j <= n - i; j++) { // いくつ取り出すか
      string tmp = s.substr(i, j);
      mp[tmp]++;
    }
  }
  vector<string> l(0);
  for (auto p : mp)
    l.push_back(p.first);
  sort(l);
  cout << l[k - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  map<string, int> mp;
  for (int i = 0; i <= n - 1; i++) {   // 始点
    for (int j = 1; j <= n - i; j++) { // いくつ取り出すか
      string tmp = s.substr(i, j);
      if (tmp.size() <= k)
        mp[tmp]++;
    }
  }
  vector<string> l(0);
  for (auto p : mp)
    l.push_back(p.first);
  sort(l);
  cout << l[k - 1] << endl;
}
Problem p03353 (C++)

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> st;
  for (int i = 1; i <= s.size(); i++) {
    for (int l = 0; l < s.size(); l++) {
      if (l + i > s.size())
        break;

      string sub = s.substr(l, i);
      st.insert(sub);
    }
  }

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

  return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> st;
  for (int i = 1; i <= K; i++) {
    for (int l = 0; l < s.size(); l++) {
      if (l + i > s.size())
        break;

      string sub = s.substr(l, i);
      st.insert(sub);
    }
  }

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

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i > 0; --i)
#define CI cin >>
#define CO cout <<
#define EN << endl
#define all(x) (x).begin(), (x).end()
#define asn ans
using namespace std;
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
using ll = long long;

int main() {
  string s;
  CI s;
  int k;
  CI k;
  vector<string> vs;

  if (s.size() == 1) {
    CO s EN;
    return 0;
  }

  int tmp = s.length();

  REP(i, s.length()) {
    FOR(j, 1, s.length() + 1) { vs.push_back(s.substr(i, j)); }
  }

  sort(all(vs));
  vs.erase(unique(vs.begin(), vs.end()), vs.end());

  CO vs[k - 1] EN;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i > 0; --i)
#define CI cin >>
#define CO cout <<
#define EN << endl
#define all(x) (x).begin(), (x).end()
#define asn ans
using namespace std;
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
using ll = long long;

int main() {
  string s;
  CI s;
  int k;
  CI k;
  vector<string> vs;

  if (s.size() == 1) {
    CO s EN;
    return 0;
  }

  int tmp = s.length();

  REP(i, s.length()) {
    FOR(j, 1, k) { vs.push_back(s.substr(i, j)); }
  }

  sort(all(vs));
  vs.erase(unique(vs.begin(), vs.end()), vs.end());

  CO vs[k - 1] EN;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

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

  auto itr = st.begin();
  for (int i = 1; i < K; ++i) {
    ++itr;
  }

  cout << *itr << endl;

  return 0;
}


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

using namespace std;

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

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

  auto itr = st.begin();
  for (int i = 1; i < K; ++i) {
    ++itr;
  }

  cout << *itr << endl;

  return 0;
}
Problem p03353 (C++)

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

string s;
std::vector<string> v;

int main() {
  int i, j, K;

  std::cin >> s;
  std::cin >> K;
  for (i = 0; i < s.size(); i++) {
    for (j = 1; j <= s.size(); j++) {
      v.push_back(s.substr(i, j));
    }
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

  std::cout << v[K - 1] << '\n';

  return 0;
}


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

string s;
std::vector<string> v;

int main() {
  int i, j, K;

  std::cin >> s;
  std::cin >> K;
  for (i = 0; i < s.size(); i++) {
    for (j = 1; j < 6; j++) {
      v.push_back(s.substr(i, j));
    }
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());

  std::cout << v[K - 1] << '\n';

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
/**
 * @author torith
 * @date 2018-10-10
 */

#include <bits/stdc++.h>

using namespace std;

int main() {

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

  string s;
  cin >> s;
  int K;
  cin >> K;

  // substringの列挙
  vector<string> S;
  for (int i = s.size(); i > 0; --i) {
    int j = 0;
    while (j + i <= s.size()) {
      S.push_back(s.substr(j, i));
      j++;
    }
  }

  // ソート＆重複削除
  sort(S.begin(), S.end());
  unique(S.begin(), S.end());

  cout << S[K - 1] << "\n";

  return 0;
}


Fixed submission:
/**
 * @author torith
 * @date 2018-10-10
 */

#include <bits/stdc++.h>

using namespace std;

int main() {

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

  string s;
  cin >> s;
  int K;
  cin >> K;

  // substringの列挙
  vector<string> S;
  for (int i = min(K, int(s.size())); i > 0; --i) {
    int j = 0;
    while (j + i <= s.size()) {
      S.push_back(s.substr(j, i));
      j++;
    }
  }

  // ソート＆重複削除
  sort(S.begin(), S.end());
  unique(S.begin(), S.end());

  cout << S[K - 1] << "\n";

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main() {

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

  vector<string> subb;

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

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

  int counter = 1;
  if (k == 1) {
    cout << subb[0] << endl;
  } else {
    for (int i = 1; i < subb.size(); i++) {
      if (subb[i] != subb[i - 1]) {
        counter++;
        if (counter == k) {
          cout << subb[i] << endl;
        }
      }
    }
  }
}

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

using namespace std;

int main() {

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

  vector<string> subb;

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

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

  int counter = 1;
  if (k == 1) {
    cout << subb[0] << endl;
  } else {
    for (int i = 1; i < subb.size(); i++) {
      if (subb[i] != subb[i - 1]) {
        counter++;
        if (counter == k) {
          cout << subb[i] << endl;
        }
      }
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string str;
  int k;
  vector<string> v;
  cin >> str >> k;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= str.length() - i; j++) {
      v.push_back(str.substr(j, i));
    }
  }
  sort(v.begin(), v.end());
  if (k == 1) {
    cout << v[0] << endl;
    return 0;
  } else {
    for (int i = 1, j = 1; i < v.size(); i++) {
      if (v[i] != v[i - 1]) {
        j++;
      }
      if (k == j) {
        cout << v[i] << endl;
        return 0;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string str;
  int k;
  vector<string> v;
  cin >> str >> k;
  int len = min(k, (int)str.size());
  for (int i = 1; i <= len; i++) {
    for (int j = 0; j <= str.length() - i; j++) {
      v.push_back(str.substr(j, i));
    }
  }
  sort(v.begin(), v.end());
  if (k == 1) {
    cout << v[0] << endl;
    return 0;
  } else {
    for (int i = 1, j = 1; i < v.size(); i++) {
      if (v[i] != v[i - 1]) {
        j++;
      }
      if (k == j) {
        cout << v[i] << endl;
        return 0;
      }
    }
  }
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> res;
  int right = 0;
  rep(i, n) {
    string tmp = "";
    tmp += s[i];
    res.insert(tmp);
    for (int j = i + 1; j < n; j++) {
      tmp += s[j];
      res.insert(tmp);
    }
  }
  int index = 1;
  for (auto itr = res.begin(); itr != res.end(); ++itr) {
    if (index == k) {
      cout << *itr << "\n";
      return 0;
    }
    index++;
  }
}

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> res;
  int right = 0;
  rep(i, n) {
    string tmp = "";
    tmp += s[i];
    res.insert(tmp);
    for (int j = i + 1; j < n; j++) {
      tmp += s[j];
      if (tmp.size() > k)
        break;
      res.insert(tmp);
    }
  }
  int index = 1;
  for (auto itr = res.begin(); itr != res.end(); ++itr) {
    if (index == k) {
      cout << *itr << "\n";
      return 0;
    }
    index++;
  }
}
Problem p03353 (C++)

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for (int i = st; i < ed; i++)
#define repn(i, st, ed) for (int i = st; i <= ed; i++)
#define repb(i, ed, st) for (int i = ed; i >= st; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI = 3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

// Main Code
map<char, vector<int>> mp;
set<string> v;
int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  rep(i, 0, s.length()) mp[s[i]].pb(i);
  int kz = k + 1;
  for (auto x : mp) {
    char ch = x.f;
    vector<int> pos = x.s;
    bool fir = true;
    for (auto p : pos) {
      string ss = "";
      int kk = k + 1;
      rep(i, p, s.length()) {
        ss += s[i];
        if (v.find(ss) == v.end()) {
          kk--;
          v.insert(ss);
        }
        if (kk == 0)
          break;
      }
    }
    kz--;
    if (kz == 0)
      break;
  }
  for (auto x : v) {
    k--;
    if (k == 0) {
      cout << x << endl;
      break;
    }
  }
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for (int i = st; i < ed; i++)
#define repn(i, st, ed) for (int i = st; i <= ed; i++)
#define repb(i, ed, st) for (int i = ed; i >= st; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI = 3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

// Main Code
map<char, vector<int>> mp;
set<string> v;
int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  rep(i, 0, s.length()) mp[s[i]].pb(i);
  int kz = k + 1;
  for (auto x : mp) {
    char ch = x.f;
    vector<int> pos = x.s;
    bool fir = true;
    for (auto p : pos) {
      string ss = "";
      int kk = k + 1;
      rep(i, p, s.length()) {
        ss += s[i];
        v.insert(ss);
        kk--;
        if (kk == 0)
          break;
      }
    }
    kz--;
    if (kz == 0)
      break;
  }
  for (auto x : v) {
    k--;
    if (k == 0) {
      cout << x << endl;
      break;
    }
  }
}
Problem p03353 (C++)

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

string s;
int k;

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

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

  set<string> set1(vec.begin(), vec.end());
  vector<string> vec2(set1.begin(), set1.end());

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

  return 0;
}

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

string s;
int k;

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

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

  set<string> set1(vec.begin(), vec.end());
  vector<string> vec2(set1.begin(), set1.end());

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

  return 0;
}
Problem p03353 (C++)

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

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

  // 全探索。S[i]に対して部分文字列の配列を作っていく
  vector<string> vec;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= N - i; j++) {
      vec.push_back(S.substr(i, j));
    }
  }

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

  string ans;
  ans = vec[K - 1];
  cout << ans << endl;
  return 0;
}

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

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

  // 全探索。S[i]に対して部分文字列の配列を作っていく
  vector<string> vec;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      vec.push_back(S.substr(i, j));
    }
  }

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

  string ans;
  ans = vec[K - 1];
  cout << ans << endl;
  return 0;
}
Problem p03353 (C++)

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

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

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

  map<string, int> m;

  int n = s.size();
  rep(i, n) {
    for (int j = 1; j <= n - i; j++) {
      // cout << i << "|" << j << "-" << s.substr(i, j) << endl;
      m[s.substr(i, j)]++;
    }
  }

  int idx = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (idx == k - 1) {
      cout << itr->first << endl;
      break;
    }
    idx++;
  }

  return 0;
}

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

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

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

  map<string, int> m;

  int n = s.size();
  rep(i, n) {
    for (int j = 1; j <= n - i && j <= k; j++) {
      // cout << i << "|" << j << "-" << s.substr(i, j) << endl;
      m[s.substr(i, j)]++;
    }
  }

  int idx = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (idx == k - 1) {
      cout << itr->first << endl;
      break;
    }
    idx++;
  }

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

int main(void) {

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

  vector<string> s_set;

  if (s.length() == 1) {
    cout << s << endl;
    return 0;
  }

  for (int i = 1; i <= s.length(); i++) {
    for (int j = 0; j < s.length() - i + 1; j++) {
      s_set.push_back(s.substr(j, i));
    }
  }

  for (string kk : s_set) {
    // cout << kk << endl;
  }

  // cout << endl;

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

  for (string kk : s_set) {
    // cout << kk << endl;
  }

  // cout << endl;

  s_set.erase(unique(s_set.begin(), s_set.end()), s_set.end());

  for (string kk : s_set) {
    // cout << kk << endl;
  }

  // cout << endl;

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

  return 0;
}


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

using namespace std;

int main(void) {

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

  vector<string> s_set;

  if (s.length() == 1) {
    cout << s << endl;
    return 0;
  }

  for (int i = 1; i <= s.length() and i <= 5; i++) {
    for (int j = 0; j < s.length() - i + 1; j++) {
      s_set.push_back(s.substr(j, i));
    }
  }

  for (string kk : s_set) {
    // cout << kk << endl;
  }

  // cout << endl;

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

  for (string kk : s_set) {
    // cout << kk << endl;
  }

  // cout << endl;

  s_set.erase(unique(s_set.begin(), s_set.end()), s_set.end());

  for (string kk : s_set) {
    // cout << kk << endl;
  }

  // cout << endl;

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

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (int i = (a), i##Len_ = (b); i < i##Len_; i++)
const char *LF = "\n";
namespace {
struct _ {
  _() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} a;
} // namespace

set<string> sub;

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

  REP(i, S.size()) {
    FOR(j, i, S.size()) { sub.insert(S.substr(i, j - i + 1)); }
  }

  int cnt = 0;
  for (auto &i : sub) {
    if (++cnt == K) {
      cout << i << LF;
      return 0;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (int i = (a), i##Len_ = (b); i < i##Len_; i++)
const char *LF = "\n";
namespace {
struct _ {
  _() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} a;
} // namespace

set<string> sub;

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

  int nk = 0;
  for (int i = 0; i < 26; i++) {
    char c = 'a' + i;
    for (int j = 0; j < S.size(); j++) {
      if (S[j] == c) {
        for (int k = j; k < min(S.size(), (size_t)(j + K)); k++) {
          auto ret = sub.insert(S.substr(j, k - j + 1));
          if (ret.second)
            nk++;
        }
      }
    }
    if (nk >= K)
      break;
  }

  int cnt = 0;
  for (auto &i : sub) {
    if (++cnt == K) {
      cout << i << LF;
      return 0;
    }
  }

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
string ss[100000];
set<string> sets;
int main() {
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size(); j++) {
      string t = s.substr(i, j);
      if (t.size() <= k)
        sets.insert(s.substr(i, j));
    }
  }
  set<string>::iterator it = sets.begin();
  std::advance(it, k - 1);
  string x = *it;
  cout << x << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
string ss[100000];
set<string> sets;
int main() {
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size() - i; j++) {
      string t = s.substr(i, j);
      if (t.size() <= k)
        sets.insert(s.substr(i, j));
    }
  }
  set<string>::iterator it = sets.begin();
  std::advance(it, k - 1);
  string x = *it;
  cout << x << endl;

  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <set>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> q;
  char c = 'a';
  while (q.size() <= k) {
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == c) {
        for (int j = 0; j <= s.length(); j++) {
          string t = s.substr(i, j);
          q.insert(t);
          // cout<<t<<endl;
        }
      }
    }
    c++;
  }
  int i;
  set<string>::iterator it;
  for (i = 0, it = q.begin(); i < k && it != q.end(); it++, i++)
    ;
  cout << (*it) << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <set>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> q;
  char c = 'a';
  while (q.size() <= k) {
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == c) {
        for (int j = 0; j <= 10; j++) {
          string t = s.substr(i, j);
          q.insert(t);
          // cout<<t<<endl;
        }
      }
    }
    c++;
  }
  int i;
  set<string>::iterator it;
  for (i = 0, it = q.begin(); i < k && it != q.end(); it++, i++)
    ;
  cout << (*it) << endl;
  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

  int N = str.length();
  int i, j;
  set<string> sub_str;

  for (i = 0; i < N; i++) {
    for (j = 1; j < N - i + 1; j++) {
      sub_str.insert(str.substr(i, j));
    }
  }

  auto itr = sub_str.begin();
  for (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() {
  string str;
  int K;
  cin >> str;
  cin >> K;

  int N = str.length();
  int i, j;
  set<string> sub_str;

  for (i = 0; i < N; i++) {
    for (j = 1; j < N - i + 1; j++) {
      if (j > K)
        break;
      sub_str.insert(str.substr(i, j));
    }
  }

  auto itr = sub_str.begin();
  for (i = 0; i < K - 1; i++)
    itr++;

  cout << *itr << endl;

  return 0;
}
Problem p03353 (C++)

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

using namespace std;

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

  vector<string> subs;
  for (int si = 0; si < s.size(); si++) {
    for (int len = 1; len <= s.size() - si; len++)
      subs.push_back(s.substr(si, len));
  }

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

  auto n = unique(subs.begin(), subs.end());
  subs.erase(n, subs.end());

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


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

using namespace std;

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

  vector<string> subs;
  for (int si = 0; si < s.size(); si++) {
    for (int len = 1; len <= k; len++)
      subs.push_back(s.substr(si, len));
  }

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

  auto n = unique(subs.begin(), subs.end());
  subs.erase(n, subs.end());

  cout << subs.at(k - 1) << endl;
  return 0;
}
Problem p03353 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x)                                                              \
  rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N, M, K;
string S, T;
vector<int> A;
vector<int> B;
//=============================
void input() {
  cin >> S;
  cin >> K;
}
//=============================
void func() {}
//=============================
void solve() {
  set<string> st;
  priority_queue<string, vector<string>, greater<string>> q;

  int N = S.size();
  rep(i, N) {
    for (int j = 1; j <= N; ++j) {
      // i to j substring
      string ts = S.substr(i, j);
      if (st.find(ts) != st.end()) // found
      {
        // do nothing
      } else {
        st.insert(ts);
        q.push(ts);
      }
    }
  }

  vector<string> anss;
  rep(i, K) {
    string x = q.top();
    q.pop();
    anss.push_back(x);
  }
  cout << anss[K - 1] << endl;
}
//=============================
signed main() {
  input();
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x)                                                              \
  rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N, M, K;
string S, T;
vector<int> A;
vector<int> B;
//=============================
void input() {
  cin >> S;
  cin >> K;
}
//=============================
void func() {}
//=============================
void solve() {
  set<string> st;
  priority_queue<string, vector<string>, greater<string>> q;

  int N = S.size();
  rep(i, N) {
    for (int j = 1; j <= K; ++j) {
      // i to j substring
      string ts = S.substr(i, j);
      if (st.find(ts) != st.end()) // found
      {
        // do nothing
      } else {
        st.insert(ts);
        q.push(ts);
      }
    }
  }

  vector<string> anss;
  rep(i, K) {
    string x = q.top();
    q.pop();
    anss.push_back(x);
  }
  cout << anss[K - 1] << endl;
}
//=============================
signed main() {
  input();
  solve();
  return 0;
}