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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// 14719021122270100109
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define pb eb
#define mp make_pair
#define forn(i, n) for (register int i = 0; i < n; i++)
#define Forn(i, n) for (register int i = 1; i <= n; i++)
#define foreach(it, a)                                                         \
  for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define Foreach(it, a)                                                         \
  for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)

inline int in() {
  char c = getchar();
  int neg = 1, x = 0;
  while (!isdigit(c))
    (c == '-') ? neg = -1, c = getchar() : c = getchar();
  while (isdigit(c))
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return neg * x;
}
inline int lcm(int a, int b) { return a * b / __gcd(a, b); }

const int mat[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int MAX = 10;

int N, M, a[MAX];
string dp[10005];

int main() {
  N = in(), M = in();
  forn(i, M) a[i] = in();
  Forn(i, 10000) dp[i] = "&";
  forn(i, N + 1) forn(j, M) {
    if (dp[i] == "&")
      continue;
    int id = i + mat[a[j]];
    string t1 = dp[id], t2 = dp[i] + (char)('0' + a[j]);
    if (dp[id] == "&" || t1.size() < t2.size())
      dp[id] = t2;
    else if (t1.size() == t2.size())
      dp[id] = max(t1, t2);
  }
  cout << dp[N] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// 14719021122270100109
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define pb eb
#define mp make_pair
#define forn(i, n) for (register int i = 0; i < n; i++)
#define Forn(i, n) for (register int i = 1; i <= n; i++)
#define foreach(it, a)                                                         \
  for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define Foreach(it, a)                                                         \
  for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)

inline int in() {
  char c = getchar();
  int neg = 1, x = 0;
  while (!isdigit(c))
    (c == '-') ? neg = -1, c = getchar() : c = getchar();
  while (isdigit(c))
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return neg * x;
}
inline int lcm(int a, int b) { return a * b / __gcd(a, b); }

const int mat[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int MAX = 10;

int N, M, a[20005];
string dp[20005];

int main() {
  N = in(), M = in();
  forn(i, M) a[i] = in();
  Forn(i, 10000) dp[i] = "&";
  forn(i, N + 1) forn(j, M) {
    if (dp[i] == "&")
      continue;
    int id = i + mat[a[j]];
    string t1 = dp[id], t2 = dp[i] + (char)('0' + a[j]);
    if (dp[id] == "&" || t1.size() < t2.size())
      dp[id] = t2;
    else if (t1.size() == t2.size())
      dp[id] = max(t1, t2);
  }
  cout << dp[N] << endl;
  return 0;
}
Problem p03128 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());

  int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int dp[1009] = {0};
  int dig_num[1009] = {0};

  rep(i, n) {
    int max_cnt = -INF;
    for (auto aj : a) {
      if (i + 1 - num[aj] < 0)
        continue;
      int tmp_cnt = dp[i + 1 - num[aj]] + 1;
      if (tmp_cnt > max_cnt) {
        max_cnt = tmp_cnt;
        dig_num[i + 1] = aj;
      }
    }
    dp[i + 1] = max_cnt;
  }

  int cur = n;
  rep(i, dp[n]) {
    cout << dig_num[cur];
    cur -= num[dig_num[cur]];
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());

  int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int dp[10009] = {0};
  int dig_num[10009] = {0};

  rep(i, n) {
    int max_cnt = -INF;
    for (auto aj : a) {
      if (i + 1 - num[aj] < 0)
        continue;
      int tmp_cnt = dp[i + 1 - num[aj]] + 1;
      if (tmp_cnt > max_cnt) {
        max_cnt = tmp_cnt;
        dig_num[i + 1] = aj;
      }
    }
    dp[i + 1] = max_cnt;
  }

  int cur = n;
  rep(i, dp[n]) {
    cout << dig_num[cur];
    cur -= num[dig_num[cur]];
  }
  cout << endl;

  return 0;
}
Problem p03128 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  int N, M;
  cin >> N >> M;
  auto A = make_vec<int>(N);
  REP(i, M) { cin >> A.at(i); }
  sort(ALL(A), greater<int>());

  vector<int> dp(N + 4, -INF);
  dp[0] = 0;
  REP(i, N + 1) {
    REP(j, M) {
      if (i >= num[A[j]]) {
        dp[i] = max(dp[i], dp[i - num[A[j]]] + 1);
      }
    };
  }

  int cur = N;
  string S = "";
  while (cur > 0) {
    for (auto a : A) {
      // cout << "cur:" << cur << " a:" << a << endl;
      if (cur - num[a] >= 0) {
        if (dp[cur - num[a]] == dp[cur] - 1) {
          cur = cur - num[a];
          S.push_back(a + '0');
          break;
        }
      }
    }
  }
  cout << S << endl;

  return 0;
}


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); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  int N, M;
  cin >> N >> M;
  auto A = make_vec<int>(M);
  REP(i, M) { cin >> A.at(i); }
  sort(ALL(A), greater<int>());

  vector<int> dp(N + 4, -INF);
  dp[0] = 0;
  REP(i, N + 1) {
    REP(j, M) {
      if (i >= num[A[j]]) {
        dp[i] = max(dp[i], dp[i - num[A[j]]] + 1);
      }
    };
  }

  int cur = N;
  string S = "";
  while (cur > 0) {
    for (auto a : A) {
      // cout << "cur:" << cur << " a:" << a << endl;
      if (cur - num[a] >= 0) {
        if (dp[cur - num[a]] == dp[cur] - 1) {
          cur = cur - num[a];
          S.push_back(a + '0');
          break;
        }
      }
    }
  }
  cout << S << endl;

  return 0;
}
Problem p03128 (C++)

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

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

signed main() {
  int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }

  int dp[1001] = {};
  for (int i = 0; i < M; i++) {
    dp[num[A[i]]] = 1;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (i > num[A[j]]) {
        if (dp[i] <= dp[i - num[A[j]]] + 1) {
          dp[i] = dp[i - num[A[j]]] + 1;
        }
      }
    }
    if (dp[i] == 0)
      dp[i] = -1000;
  }

  sort(A.begin(), A.end(), greater<int>());
  string ans = "";
  while (N > 0) {
    for (int i = 0; i < M; i++) {
      if (N - num[A[i]] >= 0) {
        if (dp[N - num[A[i]]] != -1000 && dp[N - num[A[i]]] == dp[N] - 1) {
          ans += to_string(A[i]);
          N -= num[A[i]];
          break;
        }
      }
    }
  }
  cout << ans << endl;
}


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

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

signed main() {
  int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }

  int dp[10001] = {};
  for (int i = 0; i < M; i++) {
    dp[num[A[i]]] = 1;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (i > num[A[j]]) {
        if (dp[i] <= dp[i - num[A[j]]] + 1) {
          dp[i] = dp[i - num[A[j]]] + 1;
        }
      }
    }
    if (dp[i] == 0)
      dp[i] = -1000;
  }

  sort(A.begin(), A.end(), greater<int>());
  string ans = "";
  while (N > 0) {
    for (int i = 0; i < M; i++) {
      if (N - num[A[i]] >= 0) {
        if (dp[N - num[A[i]]] != -1000 && dp[N - num[A[i]]] == dp[N] - 1) {
          ans += to_string(A[i]);
          N -= num[A[i]];
          break;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03128 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  sort(a.begin(), a.end());
  vector<string> dp(n + 1);
  int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int mn = 9;
  rep(i, m) {
    dp[cost[a[i]]] = to_string(a[i]);
    mn = min(mn, cost[a[i]]);
  }
  for (int i = 2 * mn; i <= n; i++) {
    rep(j, m) {
      if (i - cost[a[j]] >= 0) {
        string tmp;
        if (to_string(a[j])[0] >= dp[i - cost[a[j]]][0])
          tmp = to_string(a[j]) + dp[i - cost[a[j]]];
        else
          tmp = dp[i - cost[a[j]]] + to_string(a[j]);
        if (tmp.size() >= dp[i].size())
          dp[i] = tmp;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  sort(a.begin(), a.end());
  vector<string> dp(n + 1);
  int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int mn = 9;
  rep(i, m) {
    if (cost[a[i]] <= n) {
      dp[cost[a[i]]] = to_string(a[i]);
      mn = min(mn, cost[a[i]]);
    }
  }
  for (int i = 2 * mn; i <= n; i++) {
    rep(j, m) {
      if (i - cost[a[j]] >= 0) {
        string tmp;
        if (to_string(a[j])[0] >= dp[i - cost[a[j]]][0])
          tmp = to_string(a[j]) + dp[i - cost[a[j]]];
        else
          tmp = dp[i - cost[a[j]]] + to_string(a[j]);
        if (tmp.size() >= dp[i].size())
          dp[i] = tmp;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
Problem p03128 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  int dp[1010];
  fill(dp, dp + n, -1);
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int need[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (i - need[a[j]] >= 0) {
        dp[i] = max(dp[i], dp[i - need[a[j]]] + 1);
      }
    }
  }
  sort(a.begin(), a.end(), greater<int>());
  string ans;
  for (int j = n; dp[j];) {
    for (int i = 0; i < m; i++) {
      if (j - need[a[i]] >= 0) {
        if (dp[j] == dp[j - need[a[i]]] + 1) {
          j -= need[a[i]];
          ans += a[i] + '0';
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  int dp[10010];
  fill(dp, dp + n, -1);
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int need[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (i - need[a[j]] >= 0) {
        dp[i] = max(dp[i], dp[i - need[a[j]]] + 1);
      }
    }
  }
  sort(a.begin(), a.end(), greater<int>());
  string ans;
  for (int j = n; dp[j];) {
    for (int i = 0; i < m; i++) {
      if (j - need[a[i]] >= 0) {
        if (dp[j] == dp[j - need[a[i]]] + 1) {
          j -= need[a[i]];
          ans += a[i] + '0';
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03128 (C++)

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

signed main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (auto &ai : a)
    cin >> ai;

  vector<int> need = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  auto add = [](string s, int a) {
    s += to_string(a);
    sort(s.begin(), s.end(), greater<>());
    return s;
  };
  auto cmp = [](string &s, string &t) {
    // operator <
    int n = s.size();
    int m = t.size();
    if (n < m)
      return true;
    if (n > m)
      return false;
    assert(n == m);
    for (int i = 0; i < n; ++i) {
      if (s[i] < t[i]) {
        return true;
      }
      if (s[i] > t[i]) {
        return false;
      }
    }
    return false;
  };
  auto chmax = [&cmp](string &s, string t) {
    if (cmp(s, t))
      s = t;
  };

  vector<string> dp(n + 1);
  for (int i = 0; i <= n; ++i) {
    for (auto const &ai : a) {
      if (i - need[ai] < 0)
        continue;
      if (dp[i - need[ai]] == "" && i - need[ai] != 0)
        continue;
      chmax(dp[i], add(dp[i - need[ai]], ai));
    }
  }
  cout << (dp[n]) << endl;
}

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

signed main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (auto &ai : a)
    cin >> ai;

  vector<int> need = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  auto add = [](string s, int a) {
    s += to_string(a);
    int n = s.size();
    for (int i = n - 1; i - 1 >= 0; --i) {
      if (s[i - 1] > s[i])
        break;
      swap(s[i - 1], s[i]);
    }
    return s;
  };
  auto cmp = [](string &s, string &t) {
    // operator <
    int n = s.size();
    int m = t.size();
    if (n < m)
      return true;
    if (n > m)
      return false;
    assert(n == m);
    for (int i = 0; i < n; ++i) {
      if (s[i] < t[i]) {
        return true;
      }
      if (s[i] > t[i]) {
        return false;
      }
    }
    return false;
  };
  auto chmax = [&cmp](string &s, string t) {
    if (cmp(s, t))
      s = t;
  };

  vector<string> dp(n + 1);
  for (int i = 0; i <= n; ++i) {
    for (auto const &ai : a) {
      if (i - need[ai] < 0)
        continue;
      if (dp[i - need[ai]] == "" && i - need[ai] != 0)
        continue;
      chmax(dp[i], add(dp[i - need[ai]], ai));
    }
  }
  cout << (dp[n]) << endl;
}
Problem p03128 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool dp[10005][5005];
ll use[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
  for (int i = 0; i < 10005; i++) {
    for (int j = 0; j < 5005; j++)
      dp[i][j] = false;
  }
  dp[0][0] = true;
  ll n, m;
  cin >> n >> m;
  vector<ll> v;
  for (int i = 0; i < m; i++) {
    ll a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<ll>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5000; j++) {
      if (dp[i][j]) {
        for (int k = 0; k < m; k++) {
          dp[i + use[v[k]]][j + 1] = true;
        }
      }
    }
  }

  vector<ll> vec;
  int kt;
  for (kt = 5004; kt >= 0; kt--) {
    if (dp[n][kt])
      break;
  }
  vector<ll> ans;
  ll ks = n;

  for (; kt > 0; kt--) {
    for (int i = 0; i < m; i++) {
      if (ks - use[v[i]] >= 0) {
        if (dp[ks - use[v[i]]][kt - 1]) {
          ans.push_back(v[i]);
          ks -= use[v[i]];
          break;
        }
      }
    }
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i];
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool dp[10005][5005];
ll use[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
  for (int i = 0; i < 10005; i++) {
    for (int j = 0; j < 5005; j++)
      dp[i][j] = false;
  }
  dp[0][0] = true;
  ll n, m;
  cin >> n >> m;
  vector<ll> v;
  for (int i = 0; i < m; i++) {
    ll a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<ll>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5000; j++) {
      if (dp[i][j]) {
        for (int k = 0; k < m; k++) {
          if (i + use[v[k]] < 10005)
            dp[i + use[v[k]]][j + 1] = true;
        }
      }
    }
  }

  vector<ll> vec;
  int kt;
  for (kt = 5004; kt >= 0; kt--) {
    if (dp[n][kt])
      break;
  }
  vector<ll> ans;
  ll ks = n;

  for (; kt > 0; kt--) {
    for (int i = 0; i < m; i++) {
      if (ks - use[v[i]] >= 0) {
        if (dp[ks - use[v[i]]][kt - 1]) {
          ans.push_back(v[i]);
          ks -= use[v[i]];
          break;
        }
      }
    }
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i];
  cout << endl;
}
Problem p03128 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
string MAX(string x, string y) {
  if (x.size() > y.size())
    return x;
  if (x.size() < y.size())
    return y;
  return max(x, y);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a.at(i);
  vector<int> nums = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  vector<string> dp(2000, ""); // dp[i]->i本のマッチを使って作れる最大の整数
  rep(i, n) {
    if (i != 0 && dp.at(i) == "")
      continue;
    rep(j, m) {
      int A = a.at(j);
      int N = nums.at(A);
      dp.at(i + N) = MAX(dp.at(i + N), dp.at(i) + to_string(A));
    }
  }

  cout << dp.at(n) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
string MAX(string x, string y) {
  if (x.size() > y.size())
    return x;
  if (x.size() < y.size())
    return y;
  return max(x, y);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a.at(i);
  vector<int> nums = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  vector<string> dp(20000, ""); // dp[i]->i本のhマッチを使って作れる最大の整数
  rep(i, n) {
    if (i != 0 && dp.at(i) == "")
      continue;
    rep(j, m) {
      int A = a.at(j);
      int N = nums.at(A);
      dp.at(i + N) = MAX(dp.at(i + N), dp.at(i) + to_string(A));
    }
  }

  cout << dp.at(n) << endl;
}
Problem p03128 (C++)

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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i < n + 1; i++)

int main() {
  int N, M;
  int A[9];
  cin >> N >> M;
  rep(i, M) {
    cin >> A[i];
    A[i]--;
  }
  int num[9];
  num[0] = 2;
  num[1] = 5;
  num[2] = 5;
  num[3] = 4;
  num[4] = 5;
  num[5] = 6;
  num[6] = 3;
  num[7] = 7;
  num[8] = 6;
  int d[8];
  rep(i, 8) d[i] = -1;
  rep(i, M) { d[num[A[i]]] = max(d[num[A[i]]], A[i] + 1); }
  string dp[10000];
  rep(i, N + 1) dp[i] = "a";
  dp[0] = "";
  Rep(i, N) {
    rep(j, 8) {
      if (d[j] < 0)
        continue;
      if (i - j < 0)
        continue;
      if (dp[i - j][0] == 'a')
        continue;
      if (dp[i][0] == 'a')
        dp[i] = to_string(d[j]) + dp[i - j];
      else {
        if (dp[i].size() > 1 + dp[i - j].size())
          continue;
        else if (dp[i].size() == 1 + dp[i - j].size()) {
          if (dp[i][0] < to_string(d[j])[0])
            dp[i] = to_string(d[j]) + dp[i - j];
        } else
          dp[i] = to_string(d[j]) + dp[i - j];
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i < n + 1; i++)

int main() {
  int N, M;
  int A[9];
  cin >> N >> M;
  rep(i, M) {
    cin >> A[i];
    A[i]--;
  }
  int num[9];
  num[0] = 2;
  num[1] = 5;
  num[2] = 5;
  num[3] = 4;
  num[4] = 5;
  num[5] = 6;
  num[6] = 3;
  num[7] = 7;
  num[8] = 6;
  int d[8];
  rep(i, 8) d[i] = -1;
  rep(i, M) { d[num[A[i]]] = max(d[num[A[i]]], A[i] + 1); }
  string dp[10001];
  rep(i, N + 1) dp[i] = "a";
  dp[0] = "";
  Rep(i, N) {
    rep(j, 8) {
      if (d[j] < 0)
        continue;
      if (i - j < 0)
        continue;
      if (dp[i - j][0] == 'a')
        continue;
      if (dp[i][0] == 'a')
        dp[i] = to_string(d[j]) + dp[i - j];
      else {
        if (dp[i].size() > 1 + dp[i - j].size())
          continue;
        else if (dp[i].size() == 1 + dp[i - j].size()) {
          if (dp[i][0] < to_string(d[j])[0])
            dp[i] = to_string(d[j]) + dp[i - j];
        } else
          dp[i] = to_string(d[j]) + dp[i - j];
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}
Problem p03128 (C++)

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> sticks{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> can(m);
  for (int i = 0; i < m; i++)
    cin >> can[i];
  sort(can.begin(), can.end());
  reverse(can.begin(), can.end());

  vector<int> dp(n + 1); // dp[i]=i本でできる最大桁数
  for (int i = 1; i <= n; i++) {
    for (auto x : can) {
      if (i - sticks[x] >= 0)
        dp[i] = max(dp[i], dp[i - sticks[x]] + 1);
    }
  }

  int remain = n;
  while (remain > 0) {
    for (auto x : can) {
      if (dp[remain - sticks[x]] == dp[remain] - 1)
        if (dp[remain - sticks[x]] > 0 || remain - sticks[x] == 0) {
          remain -= sticks[x];
          cout << x;
          break;
        }
    }
  }
  cout << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> sticks{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> can(m);
  for (int i = 0; i < m; i++)
    cin >> can[i];
  sort(can.begin(), can.end());
  reverse(can.begin(), can.end());

  vector<int> dp(n + 1); // dp[i]=i本でできる最大桁数
  for (int i = 1; i <= n; i++)
    dp[i] = -1145141919;
  for (int i = 1; i <= n; i++) {
    for (auto x : can) {
      if (i - sticks[x] >= 0)
        dp[i] = max(dp[i], dp[i - sticks[x]] + 1);
    }
  }

  int remain = n;
  while (remain > 0) {
    for (auto x : can) {
      if (dp[remain - sticks[x]] == dp[remain] - 1)
        if (dp[remain - sticks[x]] > 0 || remain - sticks[x] == 0) {
          remain -= sticks[x];
          cout << x;
          break;
        }
    }
  }
  cout << endl;

  return 0;
}
Problem p03129 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N;
  int K;
  cin >> N >> K;

  if (N % 2 == 1)
    N = (N + 1) / 2;
  else
    N /= 2;
  if (N >= K)
    printf("YES");
  else
    printf("NO");
  while (1)
    ;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N;
  int K;
  cin >> N >> K;

  if (N % 2 == 1)
    N = (N + 1) / 2;
  else
    N /= 2;
  if (N >= K)
    printf("YES");
  else
    printf("NO");
}
Problem p03129 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define pb push_back
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int MOD = 1e9 + 7;
using namespace std;

int32_t main() {
  IOS
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int s = i + 2, j = 0;
    for (j = 2; j <= k && s <= n; j++) {
      s += 2;
    }
    if (j > k) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define pb push_back
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int MOD = 1e9 + 7;
using namespace std;

int32_t main() {
  IOS int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int s = i + 2, j = 0;
    for (j = 2; j <= k && s <= n; j++) {
      s += 2;
    }
    if (j > k) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
Problem p03129 (C++)

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

int main() {
  int cnt[5] = {0};
  for (int i = 0; i < 3; i++) {
    int a, b;
    cin >> a >> b;
    cnt[a]++, cnt[b]++;
  }
  bool ok = 1;
  for (int i = 1; i <= 4; i++)
    if (cnt[i] == 3)
      ok = 0;
  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  cout << (k * 2 <= n + 1 ? "YES" : "NO") << endl;
  return 0;
}
Problem p03129 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  if (n == 1) {
    if (k == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    return 0;
  }
  n--;
  k--;
  if (2 <= n / k) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    if (1 <= n)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    return 0;
  }
  n--;
  k--;
  if (2 <= n / k) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
Problem p03129 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define x first
#define y second

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;

  int n, k;
  cin >> n >> k;

  if (k <= (ceil((double)n / 2))) {
    cout << "YES";
  } else {
    cout << "NO";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define x first
#define y second

int32_t main() {
#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  IOS;

  int n, k;
  cin >> n >> k;

  if (k <= (ceil((double)n / 2))) {
    cout << "YES";
  } else {
    cout << "NO";
  }

  return 0;
}
Problem p03129 (C++)

Buggy submission (status: Runtime Error):
/** source code by coolreshab **/

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

#define MAX 100000
#define MAX1 100000
#define inf 1000000000
#define mod 1000000007
#define ll long long

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  // freopen("out.txt","w",stdout);

  // begin
  int n, k, x;
  cin >> n >> k;
  if (n & 1) {
    x = n / 2;
    x++;
  } else
    x = n / 2;
  if (x >= k)
    cout << "YES";
  else
    cout << "NO";
  // end

  return 0;
}


Fixed submission:
/** source code by coolreshab **/

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

#define MAX 100000
#define MAX1 100000
#define inf 1000000000
#define mod 1000000007
#define ll long long

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // begin
  int n, k, x;
  cin >> n >> k;
  if (n & 1) {
    x = n / 2;
    x++;
  } else
    x = n / 2;
  if (x >= k)
    cout << "YES";
  else
    cout << "NO";
  // end

  return 0;
}
Problem p03129 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x, y) (x < (y) ? x = (y) : 0)
#define dn(x, y) (x > (y) ? x = (y) : 0)
#define ad(x, y) (x = (x + (y)) % mod)
using namespace std;

int read() {
  int x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
ll readll() {
  ll x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
int main() {
  int a, b;
  scanf("%d%d", &a, b);
  puts((b <= (a + 1 >> 1)) ? "YES" : "NO");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x, y) (x < (y) ? x = (y) : 0)
#define dn(x, y) (x > (y) ? x = (y) : 0)
#define ad(x, y) (x = (x + (y)) % mod)
using namespace std;

int read() {
  int x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
ll readll() {
  ll x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  puts((b <= (a + 1 >> 1)) ? "YES" : "NO");
  return 0;
}
Problem p03130 (Python)

Buggy submission (status: Runtime Error):
def solution(path1, path2, path3):
    counts = [0, 0, 0, 0]
    paths = [path1, path2, path3]
    for path in paths:
        counts[path[0] - 1] += 1
        counts[path[1] - 1] += 1

    countsOfCounts = [0, 0]
    for count in counts:
        if count == 1:
            if countsOfCounts[0] == 2:
                return "NO"
            countsOfCounts[0] += 1
        elif count == 2:
            if countsOfCounts[1] == 2:
                return "NO"
            countsOfCounts[1] += 1
        else:
            return "NO"
    return "YES"


s1, s2, s3 = input().split("\n")
path1 = [int(s) for s in s1.split(" ")]
path2 = [int(s) for s in s2.split(" ")]
path3 = [int(s) for s in s3.split(" ")]

print(solution(path1, path2, path3))


Fixed submission:
def solution(path1, path2, path3):
    counts = [0, 0, 0, 0]
    paths = [path1, path2, path3]
    for path in paths:
        counts[path[0] - 1] += 1
        counts[path[1] - 1] += 1

    countsOfCounts = [0, 0]
    for count in counts:
        if count == 1:
            if countsOfCounts[0] == 2:
                return "NO"
            countsOfCounts[0] += 1
        elif count == 2:
            if countsOfCounts[1] == 2:
                return "NO"
            countsOfCounts[1] += 1
        else:
            return "NO"
    return "YES"


path1 = [int(s) for s in input().split(" ")]
path2 = [int(s) for s in input().split(" ")]
path3 = [int(s) for s in input().split(" ")]

print(solution(path1, path2, path3))
Problem p03130 (C++)

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

int main() {
  std::vector<std::pair<int, int>> list;

  for (int i = 0; i < 3; ++i) {
    int n, k;
    std::cin >> n;
    std::cin >> k;
    list.emplace_back(n, k);
  }

  int a[4] = {0};
  bool flg = false;
  for (auto c : list) {
    a[c.first]++;
    a[c.second]++;
  }
  int cnt = 0;
  for (int i = 0; i < 4; ++i) {
    if (a[i] == 2)
      cnt++;
  }
  if (cnt == 2)
    flg = true;
  if (flg)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;

  return 0;
}

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

int main() {
  std::vector<std::pair<int, int>> list;

  for (int i = 0; i < 3; ++i) {
    int n, k;
    std::cin >> n;
    std::cin >> k;
    list.emplace_back(n, k);
  }

  int a[4] = {0};
  bool flg = false;
  for (auto c : list) {
    a[c.first - 1]++;
    a[c.second - 1]++;
  }
  int cnt = 0;
  for (int i = 0; i < 4; ++i) {
    if (a[i] == 2)
      cnt++;
  }
  if (cnt == 2)
    flg = true;
  if (flg)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;

  return 0;
}
Problem p03130 (C++)

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

int main() {
  int i;
  vector<int> v(5);
  rep(i, 6) {
    cin >> i;
    v.at(i)++;
  }
  if (v.at(1) <= 2 && v.at(2) <= 2 && v.at(3) <= 2 && v.at(4) <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main() {
  int i;
  vector<int> v(5);
  rep(j, 6) {
    cin >> i;
    v.at(i)++;
  }
  if (v.at(1) <= 2 && v.at(2) <= 2 && v.at(3) <= 2 && v.at(4) <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03130 (C++)

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

using namespace std;

int mat[4][4] = {0};

int check(int i, int j);

int main(void) {
  int p, n;

  for (int i = 0; i < 3; i++) {
    cin >> p >> n;
    mat[p - 1][n - 1] = 1;
    mat[n - 1][p - 1] = 1;
  }
  /*
  for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
          cout << mat[i][j];
      }
      cout << endl;
  }
  */

  if (check(0, 0) == 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

int check(int i, int j) {
  if (mat[i][j] == 0) {
    // printf("check(%d,%d) %d  ==> check(%d,%d)\n",i,j,mat[i][j],i,j+1);
    if (j + 1 < 4) {
      return check(i, j + 1);
    } else if (i + 1 < 4) {
      return check(i + 1, 0);
    } else {
      return 0;
    }
  } else if (mat[i][j] == 1) {
    mat[j][i] = 0;
    // printf("check(%d,%d) %d ==> check(%d,%d)\n",i,j + 1,mat[i][j],j,0);
    return check(j, 0) + 1;
  }
}


Fixed submission:
#include <iostream>

using namespace std;

int mat[4][4] = {0};

int check(int i, int j);

int main(void) {
  int p, n;

  for (int i = 0; i < 3; i++) {
    cin >> p >> n;
    mat[p - 1][n - 1] = 1;
    mat[n - 1][p - 1] = 1;
  }
  /*
  for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
          cout << mat[i][j];
      }
      cout << endl;
  }
  */

  if (check(0, 0) == 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

int check(int i, int j) {
  if (mat[i][j] == 0) {
    // printf("check(%d,%d) %d  ==> check(%d,%d)\n",i,j,mat[i][j],i,j+1);
    if (j + 1 < 4) {
      return check(i, j + 1);
    }
    /*
    else if(i + 1 < 4){
        return check(i + 1, 0);
    }
    */
    else {
      return 0;
    }
  } else if (mat[i][j] == 1) {
    mat[j][i] = 0;
    // printf("check(%d,%d) %d ==> check(%d,%d)\n",i,j + 1,mat[i][j],j,0);
    return check(j, 0) + 1;
  }
}
Problem p03131 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define FORL(i, x) for (int i = head[x]; i; i = nxt[i])
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define PB push_back
#define MP make_pair
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll k, a, b;
  scanf("%lld%lld%lld", &k, &a, &b);

  ll ans = ((k - (a - 1)) / 2) * (b - a) + k % (((k - (a - 1)) / 2)) + 1;

  chmax(ans, k + 1);

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define FORL(i, x) for (int i = head[x]; i; i = nxt[i])
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define PB push_back
#define MP make_pair
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll k, a, b;
  scanf("%lld%lld%lld", &k, &a, &b);

  ll ans = ((k - (a - 1)) / 2) * (b - a) + a + (k - (a - 1)) % 2;

  chmax(ans, k + 1);

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define maxn 100000 + 5
typedef long long int ll;
const double INF = 1e20;
const double pi = acos(-1.0);
int vis[5];
int main() {
  ll k, a, b;
  scanf("%lld%lld%lld", &k, &a, &b);
  if (b - a <= 1) {
    printf("%lld", k + 1);
  } else {
    ll ans = 1;
    ans += (a - 1);
    k -= (a - 1);
    // cout<<k<<endl;
    ans += (k / 2) * (b - a);
    k -= (k / 2) * 2;
    if (k == 1)
      ans++;
    printf("%lld", ans);
  }
  while (1)
    getchar();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define maxn 100000 + 5
typedef long long int ll;
const double INF = 1e20;
const double pi = acos(-1.0);
int vis[5];
int main() {
  ll k, a, b;
  scanf("%lld%lld%lld", &k, &a, &b);
  if (b - a <= 1) {
    printf("%lld", k + 1);
  } else {
    ll ans = 1;
    ans += (a - 1);
    k -= (a - 1);
    // cout<<k<<endl;
    ans += (k / 2) * (b - a);
    k -= (k / 2) * 2;
    if (k == 1)
      ans++;
    printf("%lld", ans);
  }
  // while(1)getchar();
  return 0;
}
Problem p03131 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b)                                                            \
  {                                                                            \
    if (a < b)                                                                 \
      a = b;                                                                   \
  }
#define chmin(a, b)                                                            \
  {                                                                            \
    if (a > b)                                                                 \
      a = b;                                                                   \
  }
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 101010;
static const ll MOD = 1e9 + 7;

int main(void) {
  ll k, a, b;
  cin >> k >> a >> b;

  ll ans = max(1 + k, (b - a) / (k / 2) + k % 2);
  pt(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b)                                                            \
  {                                                                            \
    if (a < b)                                                                 \
      a = b;                                                                   \
  }
#define chmin(a, b)                                                            \
  {                                                                            \
    if (a > b)                                                                 \
      a = b;                                                                   \
  }
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 101010;
static const ll MOD = 1e9 + 7;

int main(void) {
  ll k, a, b;
  cin >> k >> a >> b;

  ll t = a - 1;
  ll ans = max(1 + k, a + (b - a) * ((k - t) / 2) + (k - t) % 2);
  pt(ans);
}
Problem p03131 (C++)

Buggy submission (status: Runtime Error):
// submitted by Himj
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i, s, e) for (i = s; i < e; i++)
#define ms(arr, val) memset(arr, val, sizeof(arr))
using namespace std;

const int mxn = 2e5 + 1;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    ll k, a, b, cur = 1;
    cin >> k >> a >> b;
    if (b - a > 2) {
      ll temp = min(a - cur, k);
      k -= temp;
      cur += temp;
      temp = k / 2;
      cur += temp * (b - a);
      if (k % 2)
        cur++;
    } else
      cur += k;
    cout << cur;
  }
  return 0;
}


Fixed submission:
// submitted by Himj
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i, s, e) for (i = s; i < e; i++)
#define ms(arr, val) memset(arr, val, sizeof(arr))
using namespace std;

const int mxn = 2e5 + 1;

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

  int t = 1;
  // cin>>t;
  while (t--) {
    ll k, a, b, cur = 1;
    cin >> k >> a >> b;
    if (b - a > 2) {
      ll temp = min(a - cur, k);
      k -= temp;
      cur += temp;
      temp = k / 2;
      cur += temp * (b - a);
      if (k % 2)
        cur++;
    } else
      cur += k;
    cout << cur;
  }
  return 0;
}