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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int, int>, 4> fd{make_pair(1, 0), make_pair(-1, 0),
                                  make_pair(0, 1), make_pair(0, -1)};

signed main() {
  int n, l;
  cin >> n >> l;
  vector<string> v;
  string s;
  rep(i, n) {
    cin >> s;
    bool set = false;
    int size = v.size();
    rep(j, size) {
      bool smaller = false;
      rep(k, l) {
        if (s[k] < v[j][k]) {
          smaller = true;
          break;
        }
      }
      if (smaller) {
        set = true;
        v.insert(v.begin() + j, s);
      }
    }
    if (!set)
      v.push_back(s);
  }
  rep(i, v.size()) { cout << v[i]; }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int, int>, 4> fd{make_pair(1, 0), make_pair(-1, 0),
                                  make_pair(0, 1), make_pair(0, -1)};

signed main() {
  int n, l;
  cin >> n >> l;
  string s[100];
  rep(i, n) cin >> s[i];
  sort(s, s + n);
  rep(i, n) cout << s[i];
  cout << endl;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
bool f(string a, string b) {
  string ab = a.append(b);
  string ba = b.append(a);
  return ab.compare(ba) > 0 ? 0 : 1;
}

int main() {
  int n, l;
  cin >> n >> l;
  string arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n, f);
  for (int i = 0; i < n; i++) {
    cout << arr[i];
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
bool f(string a, string b) {
  string ab = a.append(b);
  string ba = b.append(a);
  return ab.compare(ba) > 0 ? 0 : 1;
}

int main() {
  int n, l;
  cin >> n >> l;
  string arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    cout << arr[i];
  }

  return 0;
}
Problem p04044 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> word(m);
  for (int i = 0; i < n; i++)
    cin >> word.at(i);
  sort(word.begin(), word.end());
  for (int i = 0; i < n; i++)
    cout << word.at(i);
  cout << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> word(n);
  for (int i = 0; i < n; i++)
    cin >> word.at(i);
  sort(word.begin(), word.end());
  for (int i = 0; i < n; i++)
    cout << word.at(i);
  cout << endl;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define F first
#define S second
using namespace std;
int n;
int l;
const int N = 100;
string arr[N];
bool cmp(string a, string b) {
  int s = 0;
  while (s < l) {
    if (b[s] - '0' < a[s] - '0') {
      return false;
    }
    s++;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> l;
  string s;
  loop(i, 0, n) {
    cin.ignore();
    cin >> s;
    arr[i] = s;
  }
  sort(arr, arr + n, cmp);
  loop(i, 0, n) { cout << arr[i]; }
  cout << endl;
  return 0;
}


Fixed submission:
#include <iostream>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define F first
#define S second
using namespace std;
int n;
int l;
const int N = 100;
string arr[N];
bool cmp(const string &a, const string &b) {
  return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> l;
  string s;
  loop(i, 0, n) {
    cin.ignore();
    cin >> s;
    arr[i] = s;
  }
  sort(arr, arr + n, cmp);
  loop(i, 0, n) { cout << arr[i]; }
  cout << endl;
  return 0;
}
Problem p04044 (Python)

Buggy submission (status: Runtime Error):
print(
    "".join(sorted([input() for i in range(int("{}".format(input().split().pop(-1))))]))
)


Fixed submission:
print(
    "".join(sorted([input() for i in range(int("{}".format(input().split().pop(0))))]))
)
Problem p04044 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == "__main__":
    n, length = list(map(int, input().split()))
    s = sorted([input() for _ in range(length)])

    print("".join(s))


Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == "__main__":
    n, length = list(map(int, input().split()))
    s = sorted([input() for _ in range(n)])

    print("".join(s))
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()), ((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n, 0, sizeof n))
#define clr1(n) (memset(n, -1, sizeof n))
int dx8[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy8[8] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#else
  // online submission
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  int n, l;
  cin >> n >> l;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(all(v));
  for (int i = 0; i < l; i++)
    cout << v[i];
  cout << endl;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()), ((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n, 0, sizeof n))
#define clr1(n) (memset(n, -1, sizeof n))
int dx8[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy8[8] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#else
  // online submission
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  int n, l;
  cin >> n >> l;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(all(v));
  for (int i = 0; i < n; i++)
    cout << v[i];
  cout << endl;
}
Problem p04044 (C++)

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

int main() {
  int N, L;
  char S[100][100];
  char tmp[100];
  cin >> N >> L;
  for (int i = 0; i < N; i++)
    cin >> S[i];

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (strcmp(S[i], S[j]) > 0) {
        strcpy(tmp, S[j]);
        strcpy(S[j], S[i]);
        strcpy(S[i], tmp);
      }
    }
  }

  for (int i = 0; i < N; i++)
    cout << S[i];
  cout << endl;
}

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

int main() {
  int N, L;
  char S[105][105];
  char tmp[105];
  cin >> N >> L;
  for (int i = 0; i < N; i++)
    cin >> S[i];

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (strcmp(S[i], S[j]) > 0) {
        strcpy(tmp, S[j]);
        strcpy(S[j], S[i]);
        strcpy(S[i], tmp);
      }
    }
  }

  for (int i = 0; i < N; i++)
    cout << S[i];
  cout << endl;
}
Problem p04044 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<string> c(a);
  for (int i = 0; i < a; i++) {
    cin >> c.at(a);
  }
  sort(c.begin(), c.end());
  for (int i = 0; i < a; i++) {
    cout << c.at(i);
  }
  cout << endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<string> c(a);
  for (int i = 0; i < a; i++) {
    cin >> c.at(i);
  }
  sort(c.begin(), c.end());
  for (int i = 0; i < a; i++) {
    cout << c.at(i);
  }
  cout << endl;
  return 0;
}
Problem p04044 (C++)

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

using namespace std;

int main() {
  int n, l;
  string x;
  vector<string> A;
  cin >> n >> l;
  for (int i = 0; i < n; i++) {
    cin >> x;
    A.push_back(x);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < 3; i++) {
    cout << A[i];
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n, l;
  string x;
  vector<string> A;
  cin >> n >> l;
  for (int i = 0; i < n; i++) {
    cin >> x;
    A.push_back(x);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < n; i++) {
    cout << A[i];
  }
  cout << endl;
  return 0;
}
Problem p04044 (C++)

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

int main() {
  int N, L;
  cin >> N >> L;

  string answer;
  vector<string> S(L);

  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());

  for (int i = 0; i < N; i++) {
    answer += S[i];
  }
  cout << answer << endl;
}

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

int main() {
  int N, L;
  cin >> N >> L;

  string answer;
  vector<string> S(N);

  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());

  for (int i = 0; i < N; i++) {
    answer += S[i];
  }
  cout << answer << endl;
}
Problem p04044 (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 rrep(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))    // Reversi rep
#define nfor(i, a, b) for (int(i) = (a); (i) < (b); ++(i))  // Natural for
#define rfor(i, a, b) for (int(i) = (b); (i) >= (a); --(i)) // Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int desc(const void *a, const void *b) { return *(int *)b - *(int *)a; }

int main() {
  int n, l;
  cin >> n >> l;
  string s[n];
  qsort(s, l, sizeof(string), asc);
  rep(i, n) cout << s[i];
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))    // Reversi rep
#define nfor(i, a, b) for (int(i) = (a); (i) < (b); ++(i))  // Natural for
#define rfor(i, a, b) for (int(i) = (b); (i) >= (a); --(i)) // Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int desc(const void *a, const void *b) { return *(int *)b - *(int *)a; }

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  sort(s.begin(), s.end());
  rep(i, n) cout << s.at(i);
  cout << endl;
  return 0;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n, l;
  cin >> n >> l;
  vector<string> str(n);
  for (int i = 0; i < n; i++)
    cin >> str[i];
  sort(str.begin(), str.end());
  for (int i = 0; i < l; i++)
    cout << str[i];
  cout << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n, l;
  cin >> n >> l;
  vector<string> str(n);
  for (int i = 0; i < n; i++)
    cin >> str[i];
  sort(str.begin(), str.end());
  for (int i = 0; i < n; i++)
    cout << str[i];
  cout << endl;
  return 0;
}
Problem p04044 (C++)

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

int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, L;
  while (cin >> N >> L) {
    vector<string> words;
    for (int i = 0; i < N && cin >> words[i]; i++)
      ;
    sort(words.begin(), words.end());
    for (int i = 0; i < N && cout << words[i]; i++)
      ;
  }

  return 0;
}

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

int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, L;
  cin >> N >> L;
  vector<string> words(N);
  for (int i = 0; i < N && cin >> words[i]; i++)
    ;
  sort(words.begin(), words.end());
  for (int i = 0; i < N && cout << words[i]; i++)
    ;
  return 0;
}
Problem p04044 (C++)

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

int main() {
  int N, L;
  vector<string> strings;
  string str;
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    cin >> str;
    ;
    strings.push_back(str);
  }
  sort(strings.begin(), strings.end());
  str = strings[0];
  if (N > 1) {
    for (int i = 1; i < L; i++) {
      str += strings[i];
    }
  }
  cout << str << endl;
  return 0;
}

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

int main() {
  int N, L;
  vector<string> strings;
  string str;
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    cin >> str;
    ;
    strings.push_back(str);
  }
  sort(strings.begin(), strings.end());
  str = strings[0];
  if (N > 1) {
    for (int i = 1; i < N; i++) {
      str += strings[i];
    }
  }
  cout << str << endl;
  return 0;
}
Problem p04044 (Python)

Buggy submission (status: Runtime Error):
N, L = map(int, input().split())
Slist = list(input() for _ in range(N))
print("".join(Slist.sort()))


Fixed submission:
N, L = map(int, input().split())
Slist = list(input() for _ in range(N))
Slist.sort()
print("".join(Slist))
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int N, L;

  cin >> N >> L;

  vector<string> s(L);

  rep(i, N) { cin >> s.at(i); }

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

  rep(i, N) { cout << s.at(i); }
  cout << endl;
}

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

int main() {
  int N, L;

  cin >> N >> L;

  vector<string> s(N);

  rep(i, N) { cin >> s.at(i); }

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

  rep(i, N) { cout << s.at(i); }
  cout << endl;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  rep(i, l) cout << s[i];
  cout << endl;
  return 0;
}


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

int main(void) {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  rep(i, n) cout << s[i];
  cout << endl;
  return 0;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const int MOD = 1e9 + 7;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(), (c).end())
#define SZ(x) ((int)(x).size())
// vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;
bool cmp(string fs, string ss) {
  for (int i = 0; i < fs.length(); i++) {
    if (fs[i] == ss[i]) {

    } else if (fs[i] < ss[i]) {
      return true;
    } else {
      return false;
    }
  }
  return fs.length() - ss.length();
}

int main() {

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

  int n, L;
  cin >> n >> L;
  vector<string> sl(n);

  for (int i = 0; i < n; i++) {
    cin >> sl[i];
  }

  sort(sl.begin(), sl.end(), cmp);

  for (int i = 0; i < L; i++) {
    cout << sl[i];
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const int MOD = 1e9 + 7;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(), (c).end())
#define SZ(x) ((int)(x).size())
// vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;
bool cmp(string fs, string ss) {
  for (int i = 0; i < fs.length(); i++) {
    if (fs[i] == ss[i]) {

    } else if (fs[i] < ss[i]) {
      return true;
    } else {
      return false;
    }
  }
  return fs.length() - ss.length();
}

int main() {

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

  int n, L;
  cin >> n >> L;
  vector<string> sl(n);

  for (int i = 0; i < n; i++) {
    cin >> sl[i];
  }

  sort(sl.begin(), sl.end(), cmp);

  for (int i = 0; i < sl.size(); i++) {
    cout << sl[i];
  }
  cout << endl;

  return 0;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, L;
  cin >> N >> L;
  string arr[N];
  for (int i = 0; i < N; i++)
    cin >> arr[i];
  sort(arr, arr + L);
  for (int i = 0; i < N; i++)
    cout << arr[i];
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, L;
  cin >> N >> L;
  string arr[N];
  for (int i = 0; i < N; i++)
    cin >> arr[i];
  sort(arr, arr + N);
  for (int i = 0; i < N; i++)
    cout << arr[i];
}
Problem p04044 (C++)

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

using namespace std;

int main() {
  int n, l;
  char s[1000][1000], tmp[30];
  cin >> n >> l;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (strcmp(s[j - 1], s[j]) > 0) {
        strcpy(tmp, s[j - 1]);
        strcpy(s[j - 1], s[j]);
        strcpy(s[j], tmp);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n, l;
  char s[1000][1000], tmp[1000];
  cin >> n >> l;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (strcmp(s[j - 1], s[j]) > 0) {
        strcpy(tmp, s[j - 1]);
        strcpy(s[j - 1], s[j]);
        strcpy(s[j], tmp);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;

  return 0;
}
Problem p04044 (C++)

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

bool cmp(string a, string b) {
  if (a <= b)
    return true;
  return false;
}

int main() {
  string x[1200];

  int n, l;
  cin >> n >> l;

  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  sort(x, x + n, cmp);

  for (int i = 0; i < n; i++) {
    cout << x[i];
  }
}


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

bool cmp(string a, string b) {
  if (a < b)
    return true;
  return false;
}

int main() {
  string x[1200];

  int n, l;
  cin >> n >> l;

  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  sort(x, x + n, cmp);

  for (int i = 0; i < n; i++) {
    cout << x[i];
  }
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int l;
  cin >> n >> l;
  vector<string> st(n);
  for (int i = 0; i < l; i++) {
    cin >> st.at(i);
  }
  sort(st.begin(), st.end());
  string anser = "";
  for (int i = 0; i < n; i++) {
    anser = anser + st.at(i);
  }
  cout << anser << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int l;
  cin >> n >> l;
  vector<string> st(n);
  for (int i = 0; i < n; i++) {
    cin >> st.at(i);
  }
  sort(st.begin(), st.end());
  string anser = "";
  for (int i = 0; i < n; i++) {
    anser = anser + st.at(i);
  }
  cout << anser << endl;
  return 0;
}
Problem p04044 (C++)

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

using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  string ans;
  for (int i = 0; i < k; i++) {
    ans += a.at(i);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  string ans;
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p04044 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  rep(i, N) { cin >> S[i]; }
  sort(S.begin(), S.end());
  rep(i, L) { cout << S[i]; }
  cout << "" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  rep(i, N) { cin >> S[i]; }
  sort(S.begin(), S.end());
  rep(i, N) { cout << S[i]; }
  cout << "" << endl;
}
Problem p04044 (Python)

Buggy submission (status: Runtime Error):
N, L = map(int, input().split())
s = [0 for i in range(N)]
for i in range(N):
    s[i] = input()

s.sort()
output = ""
for i in range(L):
    output += s[i]
print(output)


Fixed submission:
N, L = map(int, input().split())
s = [0 for i in range(N)]
for i in range(N):
    s[i] = input()

s.sort()
output = ""
for i in range(N):
    output += s[i]
print(output)
Problem p04044 (C++)

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);

  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

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

  cout << S.at(0) << S.at(1) << S.at(2) << endl;
  return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);

  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

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

  for (int i = 0; i < N; i++) {
    cout << S.at(i);
  }

  cout << endl;

  return 0;
}
Problem p04044 (Python)

Buggy submission (status: Runtime Error):
N, L = map(int, input().split())
S = [input() for i in range(L)]

print("".join(sorted(S)))


Fixed submission:
N, L = map(int, input().split())
S = [input() for i in range(N)]

print("".join(sorted(S)))
Problem p04044 (Python)

Buggy submission (status: Runtime Error):
N, L = map(int, input().split())
S = [input() for i in range(L)]
print(*(sorted(S)), sep="")


Fixed submission:
n, l = map(int, input().split())
s = sorted([input() for i in range(n)])
print(*s, sep="")
Problem p04045 (C++)

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

int parity(int n) {
  if (n * n * n * n % 10 == 1)
    return 1;
  else
    return 0;
}

int power(int x, int y) {
  int64_t n = 1ll;
  for (int i = 0; i < y; i++)
    n *= x;
  return n;
}
int digit(int x, int y) { return x % power(10, y + 1) / power(10, y); }

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> dis(k);
  for (int i = 0; i < k; i++)
    cin >> dis.at(i);
  vector<int> like;
  int j = 0;
  for (int i = 0; i < 10; i++) {
    if (i == dis.at(j))
      j = min(j + 1, k - 1);
    else
      like.push_back(i);
  }
  // cout << like.size() << endl;

  vector<int> likes;
  for (int i = 1; i < 6; i++) {
    if (i == 1) {
      for (int l : like)
        likes.push_back(l);
    } else {
      for (int l : like) {
        for (int j = (power(10 - k, i - 1) - 1) / (9 - k) - 1;
             j < (10 - k) * (power(10 - k, i - 1) - 1) / (9 - k); j++) {
          likes.push_back(l * power(10, i - 1) + likes.at(j));
        }
      }
    }
  }
  for (int nn : likes) {
    if (nn >= n) {
      cout << nn << endl;
      break;
    }
  }
}

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

int parity(int n) {
  if (n * n * n * n % 10 == 1)
    return 1;
  else
    return 0;
}

int power(int x, int y) {
  int64_t n = 1ll;
  for (int i = 0; i < y; i++)
    n *= x;
  return n;
}
int digit(int x, int y) { return x % power(10, y + 1) / power(10, y); }

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> dis(k);
  for (int i = 0; i < k; i++)
    cin >> dis.at(i);
  vector<int> like;
  int j = 0;
  for (int i = 0; i < 10; i++) {
    if (i == dis.at(j))
      j = min(j + 1, k - 1);
    else
      like.push_back(i);
  }
  // cout << like.size() << endl;

  vector<int> likes;
  if (k == 9) {
    int l = like.at(0);
    likes.push_back(l);
    for (int i = 0; i < 6; i++)
      likes.push_back(likes.at(i) * 10 + l);
  } else {
    for (int i = 1; i < 6; i++) {
      if (i == 1) {
        for (int l : like)
          likes.push_back(l);
      } else {
        for (int l : like) {
          for (int j = (power(10 - k, i - 1) - 1) / (9 - k) - 1;
               j < (10 - k) * (power(10 - k, i - 1) - 1) / (9 - k); j++) {
            likes.push_back(l * power(10, i - 1) + likes.at(j));
          }
        }
      }
    }
  }
  for (int nn : likes) {
    if (nn >= n) {
      cout << nn << endl;
      break;
    }
  }
}
Problem p04045 (C++)

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; ++i) {
    char c;
    cin >> c;
    d[c - '0'] = 1;
  }

  int i = n;
  while (1) {
    int m = i;
    while (m > 0) {
      if (d[m % 10] == 1) {
        break;
      }
      m /= 10;
    }
    if (m == 0) {
      cout << i << '\n';
      return 0;
    }
    ++i;
  }
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(9);
  for (int i = 0; i < k; ++i) {
    char c;
    cin >> c;
    d[c - '0'] = 1;
  }

  int i = n;
  while (1) {
    int m = i;
    while (m > 0) {
      if (d[m % 10] == 1) {
        break;
      }
      m /= 10;
    }
    if (m == 0) {
      cout << i << '\n';
      return 0;
    }
    ++i;
  }
}
Problem p04045 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d[i];
  vector<bool> c(10);
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < k; j++) {
      if (i == d[j]) {
        c[i] = false;
        break;
      } else if (j == k - 1)
        c[i] = true;
    }
  }
  while (1) {
    string s = to_string(n);
    bool x = false;
    for (int i = 0; i < s.size(); i++) {
      if (c[s[i]]) {
        if (i == s.size() - 1)
          x = true;
      } else
        break;
    }
    if (x)
      break;
    else
      n++;
  }
  cout << n << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d[i];
  vector<bool> c(10);
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < k; j++) {
      if (i == d[j]) {
        c[i] = false;
        break;
      } else if (j == k - 1)
        c[i] = true;
    }
  }
  while (1) {
    string s = to_string(n);
    bool x = false;
    for (int i = 0; i < s.size(); i++) {
      int p = s[i] - '0';
      if (c[p]) {
        if (i == s.size() - 1)
          x = true;
      } else
        break;
    }
    if (x)
      break;
    else
      n++;
  }
  cout << n << endl;
}
Problem p04045 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());

  for (int i = n; i <= 100000; i++) {
    int m = i;
    int ans = 1;
    while (m > 0) {
      if (binary_search(d.begin(), d.end(), m % 10)) {
        ans = 0;
        break;
      } else {
        m /= 10;
      }
    }
    if (ans) {
      cout << i << endl;
      i = 20000;
    }
  }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());

  for (int i = n; i <= 100000; i++) {
    int m = i;
    int ans = 1;
    while (m > 0) {
      if (binary_search(d.begin(), d.end(), m % 10)) {
        ans = 0;
        break;
      } else {
        m /= 10;
      }
    }
    if (ans) {
      cout << i << endl;
      i = 100000;
    }
  }
}
Problem p04045 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D(N);
  for (int i = 0; i < K; i++)
    cin >> D[i];
  long long ans = N;
  while (1) {
    bool x = 1;
    long long z = ans;
    while (1) {
      for (int i = 0; i < K; i++) {
        if (z % 10 == D[i]) {
          x = 0;
          break;
        }
      }
      z /= 10;
      if (z == 0 || x == 0)
        break;
    }
    if (x) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D(K);
  for (int i = 0; i < K; i++)
    cin >> D[i];
  long long ans = N;
  while (1) {
    bool x = 1;
    long long z = ans;
    while (1) {
      for (int i = 0; i < K; i++) {
        if (z % 10 == D[i]) {
          x = 0;
          break;
        }
      }
      z /= 10;
      if (z == 0 || x == 0)
        break;
    }
    if (x) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
}
Problem p04045 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D = vector<int>(K);
  for (int i = 0; i < K; i++) {
    cin >> D.at(i);
  }

  for (int x = N; x < 100000; x++) {
    int tmp = x;
    int cnt = 0;
    vector<int> s;
    while (tmp != 0) {
      s.at(cnt) = tmp % 10;
      tmp /= 10;
    }
    bool flag = true;

    for (int i = 0; i < K; i++) {
      if (count(s.begin(), s.end(), D.at(i)) > 0)
        flag = false;
    }

    if (flag) {
      cout << x << endl;
      break;
    }
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D = vector<int>(K);
  for (int i = 0; i < K; i++) {
    cin >> D.at(i);
  }

  for (int x = N; x < 100000; x++) {
    int tmp = x;
    int cnt = 0;
    vector<int> s;
    while (tmp != 0) {
      s.push_back(tmp % 10);
      tmp /= 10;
    }
    bool flag = true;

    for (int i = 0; i < K; i++) {
      if (count(s.begin(), s.end(), D.at(i)) > 0)
        flag = false;
    }

    if (flag) {
      cout << x << endl;
      break;
    }
  }
}
Problem p04045 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  unordered_set<int> s;
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    s.insert(d);
  }
  while (true) {
    int temp = n;
    bool ok = false;
    while (temp) {
      int digit = temp % 10;
      if (s.count(digit)) {
        ok = false;
        break;
      }
      temp /= 10;
    }
    if (ok)
      break;
    n++;
  }
  cout << n;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  unordered_set<int> s;
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    s.insert(d);
  }
  while (true) {
    int temp = n;
    bool ok = true;
    while (temp) {
      int digit = temp % 10;
      if (s.count(digit)) {
        ok = false;
        break;
      }
      temp /= 10;
    }
    if (ok)
      break;
    n++;
  }
  cout << n;
}
Problem p04045 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main() {
  int n, k, i, flag;
  cin >> n >> k;
  int d[k];
  char nst[5], dst[5];
  for (i = 0; i < k; i++)
    cin >> d[i];
  while (1) {
    for (i = 0; i < k; i++) {
      sprintf(nst, "%d", n);
      sprintf(dst, "%d", d[i]);
      if (strstr(nst, dst) != NULL) {
        n++;
        flag = 0;
        break;
      } else {
        flag++;
      }
    }
    if (flag == k)
      break;
    flag = 0;
  }
  cout << n << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main() {
  int n, k, i, flag;
  cin >> n >> k;
  int d[k];
  char nst[100], dst[100];
  for (i = 0; i < k; i++)
    cin >> d[i];
  while (1) {
    for (i = 0; i < k; i++) {
      sprintf(nst, "%d", n);
      sprintf(dst, "%d", d[i]);
      if (strstr(nst, dst) != NULL) {
        n++;
        flag = 0;
        break;
      } else {
        flag++;
      }
    }
    if (flag == k)
      break;
    flag = 0;
  }
  cout << n << endl;
  return 0;
}
Problem p04045 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (LL i = 0; i < n; i++)
#define REPR(i, n) for (LL i = n; i >= 0; i--)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define FORR(i, m, n) for (LL i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// #define int long long

/*************** using variables ***************/
int n, k;
vector<int> d;
map<int, bool> mp;
LL ans;
/**********************************************/

bool check_num(LL num) {
  while (num > 0) {
    if (mp[num % 10] == true) {
      return false;
    }
    num /= 10;
  }
  return true;
}

signed main() {
  cin >> n >> k;
  d.resize(n);
  REP(i, k) cin >> d[i];
  REP(i, 10) { mp[i] = false; }
  REP(i, k) mp[d[i]] = true;
  ans = n;
  while (1) {
    if (check_num(ans))
      break;
    ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (LL i = 0; i < n; i++)
#define REPR(i, n) for (LL i = n; i >= 0; i--)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define FORR(i, m, n) for (LL i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// #define int long long

/*************** using variables ***************/
int n, k;
vector<int> d;
map<int, bool> mp;
LL ans;
/**********************************************/

bool check_num(LL num) {
  while (num > 0) {
    if (mp[num % 10] == true) {
      return false;
    }
    num /= 10;
  }
  return true;
}

signed main() {
  cin >> n >> k;
  d.resize(k);
  REP(i, k) cin >> d[i];
  REP(i, 10) { mp[i] = false; }
  REP(i, k) mp[d[i]] = true;
  ans = n;
  while (1) {
    if (check_num(ans))
      break;
    ans++;
  }

  cout << ans << endl;
}
Problem p04045 (C++)

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(n);
  for (int i = 0; i < k; i++)
    cin >> d[i];

  while (true) {
    int m = n;
    bool sflag = true;
    while (m > 0) {
      bool flag = true;
      for (int i = 0; i < k; i++) {
        if (m % 10 == d[i]) {
          flag = false;
          break;
        }
      }
      if (!flag) {
        sflag = false;
        break;
      }
      m /= 10;
    }
    if (sflag) {
      cout << n << endl;
      break;
    }
    n++;
  }
}


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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d[i];

  while (true) {
    int m = n;
    bool sflag = true;
    while (m > 0) {
      bool flag = true;
      for (int i = 0; i < k; i++) {
        if (m % 10 == d[i]) {
          flag = false;
          break;
        }
      }
      if (!flag) {
        sflag = false;
        break;
      }
      m /= 10;
    }
    if (sflag) {
      cout << n << endl;
      break;
    }
    n++;
  }
}
Problem p04045 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++) {
    cin >> d.at(i);
  }
  int ans = 0;
  for (int i = n; n < 10 * n; i++) {
    int nn = n;
    vector<int> w(10);
    int s = 0;

    while (nn != 0) {

      w.at(s) = nn % 10;
      s++;
      nn /= 10;
    }
    int f = 0;
    for (int j = 0; j < s; j++) {
      for (int p = 0; p < k; p++) {
        if (w.at(j) == d.at(p)) {
          f = 1;
          break;
        }
      }
      if (f == 1) {
        break;
      }
    }

    if (f == 0) {
      cout << i << endl;
      break;
    }
  }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for (int i = 0; i < k; i++) {
    cin >> d.at(i);
  }
  int ans = 0;
  for (int i = n; n < 10 * n; i++) {
    int nn = i;
    vector<int> w(10);
    int s = 0;

    while (nn != 0) {

      w.at(s) = nn % 10;
      s++;
      nn /= 10;
    }
    int f = 0;
    for (int j = 0; j < s; j++) {
      for (int p = 0; p < k; p++) {
        if (w.at(j) == d.at(p)) {
          f = 1;
          break;
        }
      }
      if (f == 1) {
        break;
      }
    }

    if (f == 0) {
      cout << i << endl;
      break;
    }
  }
}
Problem p04045 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, num;
  cin >> n >> k;
  vector<int> d(n, 0);
  for (int i = 0; i < k; i++) {
    cin >> num;
    d[num] = 1;
  }

  int ans = n, flag = 0;
  while (1) {
    n = ans;
    while (n > 0) {
      num = n % 10;
      if (d[num] == 1)
        break;
      n /= 10;
      if (n == 0) {
        cout << ans << endl;
        flag = 1;
        break;
      }
    }
    ans++;
    if (flag)
      break;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, num;
  cin >> n >> k;
  vector<int> d(10, 0);
  for (int i = 0; i < k; i++) {
    cin >> num;
    d[num] = 1;
  }

  int ans = n, flag = 0;
  while (1) {
    n = ans;
    while (n > 0) {
      num = n % 10;
      if (d[num] == 1)
        break;
      n /= 10;
      if (n == 0) {
        cout << ans << endl;
        flag = 1;
        break;
      }
    }
    ans++;
    if (flag)
      break;
  }

  return 0;
}
Problem p04045 (C++)

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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f) { cout << (f ? "Yes" : "No") << endl; }

void Print(bool f) { cout << (f ? "YES" : "NO") << endl; }

int main(void) {
  ll n, k, input;
  cin >> n >> k;
  vll d(k);
  rep(i, 0, k) cin >> input, d[input] = 1;

  for (int i = n;; i++) {
    int tmp = i;
    bool f = true;
    while (tmp != 0) {
      if (d[tmp % 10]) {
        f = false;
        break;
      }
      tmp /= 10;
    }
    if (f)
      return cout << i << endl, 0;
  }
}

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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f) { cout << (f ? "Yes" : "No") << endl; }

void Print(bool f) { cout << (f ? "YES" : "NO") << endl; }

int main(void) {
  ll n, k, input;
  cin >> n >> k;
  vll d(10);
  rep(i, 0, k) cin >> input, d[input] = 1;

  for (int i = n;; i++) {
    int tmp = i;
    bool f = true;
    while (tmp != 0) {
      if (d[tmp % 10]) {
        f = false;
        break;
      }
      tmp /= 10;
    }
    if (f)
      return cout << i << endl, 0;
  }
}
Problem p04045 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main(void) {
  char s[11], d[11];
  int i, t, k, c, p, n;
  char o[11];
  char y;
  int flag = 0;
  c = 0;
  scanf("%d %d", &n, &k);
  scanf("%c", &y);
  for (i = 0; i < k; i++) {
    scanf("%c", &d[i]);
    scanf("%c", &y);
  }

  for (t = 0; t >= 0; t++) {
    n = 2000;
    flag = 0;
    sprintf(s, "%d", n);
    for (i = 0; s[i] != '\0'; i++) {

      for (p = 0; p < k; p++) {
        if (d[p] == s[i]) {
          flag = 1;
          n++;
          break;
        }
      }
      if (flag == 1)
        break;
    }
    if (flag == 1) {
      continue;
    }
    break;
  }
  printf("%d\n", n);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  char s[11], d[11];
  int i, t, k, c, p, n;
  char o[11];
  char y;
  int flag = 0;
  c = 0;
  scanf("%d %d", &n, &k);
  scanf("%c", &y);
  for (i = 0; i < k; i++) {
    scanf("%c", &d[i]);
    scanf("%c", &y);
  }

  for (t = 0; t >= 0; t++) {

    flag = 0;
    sprintf(s, "%d", n);
    for (i = 0; s[i] != '\0'; i++) {

      for (p = 0; p < k; p++) {
        if (d[p] == s[i]) {
          flag = 1;
          n++;
          break;
        }
      }
      if (flag == 1)
        break;
    }
    if (flag == 1) {
      continue;
    }
    break;
  }
  printf("%d\n", n);
  return 0;
}
Problem p04045 (C++)

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d.at(i);

  for (int ans = n; ans < n * 10; ans++) {
    string s = to_string(ans);
    bool jg = false;
    for (auto x : d) {
      char c = x + '0';
      if (s.find(c) != -1) {
        break;
      }
      if (x == d.at(s.size() - 1)) {
        jg = true;
        break;
      }
    }
    if (jg) {
      cout << ans << endl;
      return 0;
    }
  }
}


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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> d(k);
  for (int i = 0; i < k; i++)
    cin >> d.at(i);

  for (int ans = n; ans < n * 10; ans++) {
    string s = to_string(ans);
    bool jg = false;
    for (auto x : d) {
      char c = x + '0';
      if (s.find(c) != -1) {
        break;
      }
      if (x == d.at(d.size() - 1)) {
        jg = true;
        break;
      }
    }
    if (jg) {
      cout << ans << endl;
      return 0;
    }
  }
}
Problem p04045 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    D = set(list(map(int, input().split())))
    F = set(list(range(10))) - D
    result = ""
    for n in str(N):
        if int(n) in F:
            result += n
        else:
            result += str(min([f for f in F if f > int(n)]))
    print(result)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    D = list(input().split())

    while True:
        if all([True if n not in D else False for n in list(str(N))]):
            break
        N += 1
    print(N)


if __name__ == "__main__":
    main()