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

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template <class T> void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main() {
  ll N, M, V, P;
  cin >> N >> M >> V >> P;
  ll A[N];
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  ll l = 0;
  while (A[N - P] - A[l] > M)
    l++;
  ll r = (N - 1) - P;
  while (l != r) {
    ll mid = (l + r) / 2;
    ll num = 0;
    rep(i, N - (P - 1)) { num += M - max((ll)0, A[i] - A[mid]); }
    // cout << mid << " " << num << endl;
    if (num >= (V - (P - 1)) * M)
      r = mid;
    else
      l = mid + 1;
  }
  ll result = N - l;
  cout << result << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template <class T> void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main() {
  ll N, M, V, P;
  cin >> N >> M >> V >> P;
  ll A[N];
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  ll l = 0;
  while (A[N - P] - A[l] > M)
    l++;
  ll r = (N - 1) - P;
  r = max(l, r);
  while (l != r) {
    ll mid = (l + r) / 2;
    ll num = 0;
    rep(i, N - (P - 1)) { num += M - max((ll)0, A[i] - A[mid]); }
    // cout << mid << " " << num << endl;
    if (num >= (V - (P - 1)) * M)
      r = mid;
    else
      l = mid + 1;
  }
  ll result = N - l;
  cout << result << endl;
  return 0;
}
Problem p02824 (C++)

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int N, M, V, P, A[MAXN];

bool chk(int idx) {
  int x = A[idx], a = idx - 1;
  if (V - P - a <= 0)
    return (x + M >= A[N - P + 1]);
  if (A[N - P + 1] > x + M)
    return 0;
  ll sum = 0;
  for (int i = idx + 1; i <= N - P + 1; i++)
    sum += x + M - A[i];
  return (sum >= 1LL * (V - P - a) * M);
}

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

  freopen("in.txt", "r", stdin);

  cin >> N >> M >> V >> P;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  sort(A + 1, A + 1 + N);

  int l = 1, r = N - P, ans = P;
  while (l <= r) {
    int mid = l + r >> 1;
    if (chk(mid)) {
      r = mid - 1;
      ans = N - mid + 1;
    } else
      l = mid + 1;
  }

  cout << ans;
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int N, M, V, P, A[MAXN];

bool chk(int idx) {
  int x = A[idx], a = idx - 1;
  if (V - P - a <= 0)
    return (x + M >= A[N - P + 1]);
  if (A[N - P + 1] > x + M)
    return 0;
  ll sum = 0;
  for (int i = idx + 1; i <= N - P + 1; i++)
    sum += x + M - A[i];
  return (sum >= 1LL * (V - P - a) * M);
}

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

  cin >> N >> M >> V >> P;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  sort(A + 1, A + 1 + N);

  int l = 1, r = N - P, ans = P;
  while (l <= r) {
    int mid = l + r >> 1;
    if (chk(mid)) {
      r = mid - 1;
      ans = N - mid + 1;
    } else
      l = mid + 1;
  }

  cout << ans;
}
Problem p02824 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 10005;

inline int read() {
  int ret, f = 1;
  char c;
  while ((c = getchar()) && (c < '0' || c > '9'))
    if (c == '-')
      f = -1;
  ret = c - '0';
  while ((c = getchar()) && (c >= '0' && c <= '9'))
    ret = (ret << 3) + (ret << 1) + c - '0';
  return ret * f;
}

int n, m, v, p, a[maxn];

bool check(int x) {
  int val = a[x] + m, cnt = 0;
  ll rst = 1LL * (v - 1) * m;
  for (int i = n; i > x; --i) {
    if (a[i] > val) {
      ++cnt;
      rst -= m;
    } else {
      if (cnt < p - 1) {
        ++cnt;
        rst -= m;
      } else {
        rst -= (val - a[i]);
      }
    }
  }
  if (cnt >= p)
    return 0;
  return rst <= 1LL * m * (x - 1);
}

int main() {
  n = read();
  m = read();
  v = read();
  p = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read();
  sort(a + 1, a + n + 1);
  int l = 1, r = n, mid, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", n - ans + 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 100005;

inline int read() {
  int ret, f = 1;
  char c;
  while ((c = getchar()) && (c < '0' || c > '9'))
    if (c == '-')
      f = -1;
  ret = c - '0';
  while ((c = getchar()) && (c >= '0' && c <= '9'))
    ret = (ret << 3) + (ret << 1) + c - '0';
  return ret * f;
}

int n, m, v, p, a[maxn];

bool check(int x) {
  int val = a[x] + m, cnt = 0;
  ll rst = 1LL * (v - 1) * m;
  for (int i = n; i > x; --i) {
    if (a[i] > val) {
      ++cnt;
      rst -= m;
    } else {
      if (cnt < p - 1) {
        ++cnt;
        rst -= m;
      } else {
        rst -= (val - a[i]);
      }
    }
  }
  if (cnt >= p)
    return 0;
  return rst <= 1LL * m * (x - 1);
}

int main() {
  n = read();
  m = read();
  v = read();
  p = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read();
  sort(a + 1, a + n + 1);
  int l = 1, r = n, mid, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", n - ans + 1);
  return 0;
}
Problem p02824 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#define mxn 10010
#define pii pair<int, int>
#define fr first
#define sc second
#define mp make_pair
#define LL long long
using namespace std;
const int mod = 1e9 + 7;
int n, m, K, N, sl, fh, ans, a[mxn];
LL s[mxn];
int rd() {
  sl = 0;
  fh = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-')
      fh = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    sl = sl * 10 + ch - '0', ch = getchar();
  return sl * fh;
}
int main() {
  n = rd();
  m = rd();
  K = rd();
  ans = N = rd();
  K = max(1, K - N + 1);
  for (int i = 1; i <= n; ++i)
    a[i] = rd();
  sort(a + 1, a + n + 1, [&](const int &x, const int &y) { return x > y; });
  for (int i = 1; i <= n; ++i)
    s[i] = s[i - 1] + a[i];
  for (int i = N + 1; i <= n; ++i)
    if (i + K - 1 <= n)
      ans += a[i] + m >= a[N];
    else if (a[i] + m >= a[N])
      ans += 1ll * (i - N) * (a[i] + m) - s[i - 1] + s[N - 1] >=
             1ll * m * (K - (n - i + 1));
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#define mxn 1000010
#define pii pair<int, int>
#define fr first
#define sc second
#define mp make_pair
#define LL long long
using namespace std;
const int mod = 1e9 + 7;
int n, m, K, N, sl, fh, ans, a[mxn];
LL s[mxn];
int rd() {
  sl = 0;
  fh = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-')
      fh = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    sl = sl * 10 + ch - '0', ch = getchar();
  return sl * fh;
}
int main() {
  n = rd();
  m = rd();
  K = rd();
  ans = N = rd();
  K = max(1, K - N + 1);
  for (int i = 1; i <= n; ++i)
    a[i] = rd();
  sort(a + 1, a + n + 1, [&](const int &x, const int &y) { return x > y; });
  for (int i = 1; i <= n; ++i)
    s[i] = s[i - 1] + a[i];
  for (int i = N + 1; i <= n; ++i)
    if (i + K - 1 <= n)
      ans += a[i] + m >= a[N];
    else if (a[i] + m >= a[N])
      ans += 1ll * (i - N) * (a[i] + m) - s[i - 1] + s[N - 1] >=
             1ll * m * (K - (n - i + 1));
  printf("%d\n", ans);
  return 0;
}
Problem p02824 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 100005;
int n, m, v, p, a[maxn], ans;
ll b[maxn];
inline int cmp1(int x, int y) { return x > y; }
inline int read() {
  int res = 0, f_f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f_f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) - '0' + ch, ch = getchar();
  return res * f_f;
}
int main() {
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
  n = read(), m = read(), v = read(), p = read(), ans = p;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  sort(a + 1, a + n + 1, cmp1);
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] + a[i];
  }
  for (int i = p + 1; i <= n; i++) {
    if (a[i] + m < a[p])
      continue;
    ll delta = 1ll * max(0, v - (p - 1) - (n - i + 1)) * m;
    if (delta == 0) {
      ans++;
      continue;
    }
    ll w = 1ll * m * (i - p) - (b[i - 1] - b[p - 1] - 1ll * a[i] * (i - p));
    if (w >= delta)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 100005;
int n, m, v, p, a[maxn], ans;
ll b[maxn];
inline int cmp1(int x, int y) { return x > y; }
inline int read() {
  int res = 0, f_f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f_f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) - '0' + ch, ch = getchar();
  return res * f_f;
}
int main() {
  n = read(), m = read(), v = read(), p = read(), ans = p;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  sort(a + 1, a + n + 1, cmp1);
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] + a[i];
  }
  for (int i = p + 1; i <= n; i++) {
    if (a[i] + m < a[p])
      continue;
    ll delta = 1ll * max(0, v - (p - 1) - (n - i + 1)) * m;
    if (delta == 0) {
      ans++;
      continue;
    }
    ll w = 1ll * m * (i - p) - (b[i - 1] - b[p - 1] - 1ll * a[i] * (i - p));
    if (w >= delta)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02824 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF = pow(10, 18);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vl a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll A = -1, B = n;
  ll M;
  while (A != B) {
    M = (A + B) / 2;
    bool ok = false;
    bool sub = true;
    ll s = 0;
    // a[M]で条件満たすの?
    FOR(i, M + 1, n - p + 1) {
      if (a[M] + m - a[i] >= 0) {
        s += (a[M] + m - a[i]);
      } else
        sub = false;
    }
    if ((M + 1) * m + s >= m * (v - p + 1)) {
      ok = true;
    }
    // にぶたん
    if (ok && sub) {
      A = min(A, B);
      B = M;
    } else {
      B = max(A, B);
      A = M + 1;
    }
  }
  cout << n - A << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF = pow(10, 18);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vl a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll A = 0, B = n - 1;
  ll M;
  while (A != B) {
    M = (A + B) / 2;
    bool ok = false;
    bool sub = true;
    ll s = 0;
    // a[M]で条件満たすの?
    FOR(i, M + 1, n - p + 1) {
      if (a[M] + m - a[i] >= 0) {
        s += (a[M] + m - a[i]);
      } else
        sub = false;
    }
    if ((M + 1) * m + s >= m * (v - p + 1)) {
      ok = true;
    }
    // にぶたん
    if (ok && sub) {
      A = min(A, B);
      B = M;
    } else {
      B = max(A, B);
      A = M + 1;
    }
  }
  cout << n - A << endl;
}
Problem p02824 (C++)

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

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  vector<ll> ruiseki(n);
  ll tmp; // cin >> tmp;
  // a.at(0) = tmp;
  // ruiseki.at(0) = tmp;
  for (ll i = 0; i < n; i++) {
    cin >> tmp;
    a.at(i) = tmp;
    // ruiseki.at(i) = ruiseki.at(i-1) + tmp;
  }
  sort(a.begin(), a.end(), greater<ll>());
  ruiseki.at(0) = a.at(0);
  for (ll i = 1; i < n; i++) {
    ruiseki.at(i) = a.at(i) + ruiseki.at(i - 1);
  }
  ll vn = (n - v) * m;
  // ll cum = 0;
  ll ans = 0;
  ll ruiseki_p = ruiseki.at(p - 2);
  for (int j = p; j < n; j++) {
    if ((ruiseki.at(j - 1) - ruiseki_p) <= vn)
      ans++;
  }
  cout << p + ans << endl;
}

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

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  vector<ll> ruiseki(n);
  ll tmp; // cin >> tmp;
  // a.at(0) = tmp;
  // ruiseki.at(0) = tmp;
  for (ll i = 0; i < n; i++) {
    cin >> tmp;
    a.at(i) = tmp;
    // ruiseki.at(i) = ruiseki.at(i-1) + tmp;
  }
  sort(a.begin(), a.end(), greater<ll>());
  ruiseki.at(0) = a.at(0);
  for (ll i = 1; i < n; i++) {
    ruiseki.at(i) = a.at(i) + ruiseki.at(i - 1);
  }
  ll vn = (n - v) * m;
  // ll cum = 0;
  ll ans = 0;
  ll ruiseki_p;
  if (1 < p) {
    ruiseki_p = ruiseki.at(p - 2);
  } else {
    ruiseki_p = 0;
  }
  for (int j = 1; j <= n - p; j++) {
    if (a.at(p + j - 1) + m < a.at(p - 1)) {
    } else {
      ll R = (ruiseki.at(p + j - 2) - ruiseki_p) - a.at(p + j - 1) * j;
      if (R <= vn)
        ans++;
    }
  }
  cout << p + ans << endl;
}
Problem p02824 (C++)

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end(), greater<ll>());
  vector<ll> plusM(n);
  for (int i = 0; i < n; i++) {
    plusM.at(i) = a.at(i) + m;
  }
  ll cnt = p;
  ll larger_cnt = 0;
  ll larger_sum = 0;
  for (ll i = p; i < n; i++) {
    ll cur = plusM.at(i);
    if (a.at(p - 1) > cur) {
      break;
    }
    ll point = m * (v - (p - 1) - (n - i));
    ll cur_larger =
        plusM.rend() -
        upper_bound(plusM.rbegin() + n - i, plusM.rend() - p + 1, cur) -
        (p - 1);
    ll cur_smaller = i - p + 1 - cur_larger;
    for (int j = p - 1 + larger_cnt; j < p + cur_larger - 1; j++) {
      larger_sum += cur - a.at(j);
    }
    larger_cnt = cur_larger;
    if (point <= cur_smaller * m + larger_sum) {
      cnt++;
      larger_sum -= larger_cnt * (cur - plusM.at(i + 1));
    } else {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end(), greater<ll>());
  vector<ll> plusM(n);
  for (int i = 0; i < n; i++) {
    plusM.at(i) = a.at(i) + m;
  }
  ll cnt = p;
  ll larger_cnt = 0;
  ll larger_sum = 0;
  for (ll i = p; i < n; i++) {
    ll cur = plusM.at(i);
    if (a.at(p - 1) > cur) {
      break;
    }
    ll point = m * (v - (p - 1) - (n - i));
    ll cur_larger =
        plusM.rend() -
        upper_bound(plusM.rbegin() + n - i, plusM.rend() - p + 1, cur) -
        (p - 1);
    ll cur_smaller = i - p + 1 - cur_larger;
    for (int j = p - 1 + larger_cnt; j < p + cur_larger - 1; j++) {
      larger_sum += cur - a.at(j);
    }
    larger_cnt = cur_larger;
    if (point <= cur_smaller * m + larger_sum) {
      cnt++;
      if (i != n - 1) {
        larger_sum -= larger_cnt * (cur - plusM.at(i + 1));
      }
    } else {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02824 (C++)

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

using namespace std;

long long Sum[100005], A[100005];

long long extra(int poz, int len, int init) {
  return (Sum[poz] - Sum[poz - len]) - 1LL * len * init;
}

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

  int n, m, v, p;
  cin >> n >> m >> v >> p;
  for (int i = 1; i <= n; i++)
    cin >> A[i];

  sort(A + 1, A + n + 1);

  for (int i = 1; i <= n; i++)
    Sum[i] = Sum[i - 1] + A[i];

  int rez = 0;
  int ind = 1;
  for (int i = 1; i <= n; i++) {
    while (A[ind + 1] <= A[i] + m)
      ind++;

    if (n - ind + 1 > p)
      continue;

    long long cr = 1LL * (i - 1) * m + 1LL * (n - ind + 1) * m +
                   1LL * (ind - i) * (A[i] + m) - (Sum[ind] - Sum[i]);
    long long total = 1LL * m * v;
    if (cr >= total) {
      rez++;
      continue;
    }

    int add = 0;
    for (int j = 16; j >= 0; j--)
      if (ind - (add + (1 << j)) + 1 > i &&
          cr + extra(ind, add + (1 << j), A[i]) < total)
        add += (1 << j);

    add++;
    if (n - ind + 1 + add <= p)
      rez++;
  }
  cout << rez << "\n";
  return 0;
}


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

using namespace std;

long long Sum[100005], A[100005];

long long extra(int poz, int len, int init) {
  return (Sum[poz] - Sum[poz - len]) - 1LL * len * init;
}

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

  int n, m, v, p;
  cin >> n >> m >> v >> p;
  for (int i = 1; i <= n; i++)
    cin >> A[i];

  sort(A + 1, A + n + 1);

  for (int i = 1; i <= n; i++)
    Sum[i] = Sum[i - 1] + A[i];

  int rez = 0;
  int ind = 1;
  for (int i = 1; i <= n; i++) {
    while (A[ind + 1] <= A[i] + m && ind + 1 <= n)
      ind++;

    if (n - ind + 1 > p)
      continue;

    long long cr = 1LL * (i - 1) * m + 1LL * (n - ind + 1) * m +
                   1LL * (ind - i) * (A[i] + m) - (Sum[ind] - Sum[i]);
    long long total = 1LL * m * v;
    if (cr >= total) {
      rez++;
      continue;
    }

    int add = 0;
    for (int j = 16; j >= 0; j--)
      if (ind - (add + (1 << j)) + 1 > i &&
          cr + extra(ind, add + (1 << j), A[i]) < total)
        add += (1 << j);

    add++;
    if (n - ind + 1 + add <= p)
      rez++;
  }
  cout << rez << "\n";
  return 0;
}
Problem p02825 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
int n, k;
std::string s[4][7] = {
    {"aacd", "bbcd", "cdaa", "cdbb"},
    {"aa.ab", ".bbab", "a.cca", "a.a.a", "bbabb"},
    {"aacd..", "bbcd..", "cd..aa", "cd..bb", "..aacd", "..bbcd"},
    {"aacd...", "bbcd...", "cd.aa..", "cd...bb", "..a.baa", "..a.b.b",
     "..bbaab"}};
int main() {
  std::cin >> n, k = n & 3;
  if (n < 3)
    std::cout << "-1\n";
  else if (n == 3)
    std::cout << "aab\nb.b\nbaa\n";
  else
    for (int i = 1; i <= n; ++i) {
      std::string t(n, '.');
      i < n - k - 4 ? t.replace(i / 4 * 4, 4, s[0][i % 4])
                    : t.replace(n - k - 4, k + 4, s[k][i - n + k + 4]);
      std::cout << t << '\n';
    }
}


Fixed submission:
#include <iostream>
#include <string>
int n, k;
std::string s[4][7] = {
    {"aacd", "bbcd", "cdaa", "cdbb"},
    {"aa.ab", ".bbab", "a.cca", "a.a.a", "bbabb"},
    {"aacd..", "bbcd..", "cd..aa", "cd..bb", "..aacd", "..bbcd"},
    {"aacd...", "bbcd...", "cd.aa..", "cd...bb", "..a.baa", "..a.b.b",
     "..bbaab"}};
int main() {
  std::cin >> n, k = n & 3;
  if (n < 3)
    std::cout << "-1\n";
  else if (n == 3)
    std::cout << "aab\nb.b\nbaa\n";
  else
    for (int i = 0; i < n; ++i) {
      std::string t(n, '.');
      i < n - k - 4 ? t.replace(i / 4 * 4, 4, s[0][i % 4])
                    : t.replace(n - k - 4, k + 4, s[k][i - n + k + 4]);
      std::cout << t << '\n';
    }
}
Problem p02825 (C++)

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

#define x first
#define y second
#define all(x) begin(x), end(x)
typedef long long ll;

const int MAX_N = 1024;

char ans[MAX_N][MAX_N];

char for4[][5] = {"aacd", "bbcd", "efgg", "efhh"};
char for5[][6] = {"aabbc", "hii.c", "h..jd", "g..jd", "gffee"};

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 2) {
    cout << "-1\n";
  } else if (n == 3) {
    cout << "aa.\n..b\n..b\n";
  } else if (n == 6) {
    cout << "aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n";
  } else if (n == 7 || n == 11) {
    assert(0);
  } else {
    int offset = 0;
    int oldn = n;
    while (n % 4 != 0) {
      for (int i = 0; i < 5; ++i)
        for (int j = 0; j < 5; ++j)
          ans[i + offset][j + offset] = for5[i][j];
      offset += 5;
      n -= 5;
    }
    while (n) {
      for (int i = 0; i < 4; ++i)
        for (int j = 0; j < 4; ++j)
          ans[i + offset][j + offset] = for4[i][j];
      offset += 4;
      n -= 4;
    }
    n = oldn;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (ans[i][j])
          cout << ans[i][j];
        else
          cout << ".";
      }
      cout << "\n";
    }
  }
  return 0;
}

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

#define x first
#define y second
#define all(x) begin(x), end(x)
typedef long long ll;

const int MAX_N = 1024;

char ans[MAX_N][MAX_N];

char for4[][5] = {"aacd", "bbcd", "efgg", "efhh"};
char for5[][6] = {"aabbc", "hii.c", "h..jd", "g..jd", "gffee"};

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 2) {
    cout << "-1\n";
  } else if (n == 3) {
    cout << "aa.\n..b\n..b\n";
  } else if (n == 6) {
    cout << "aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n";
  } else if (n == 7) {
    cout << "\
.aabaa.\n\
a..b..a\n\
a.cc..a\n\
bb..dbb\n\
a...d.a\n\
a..b..a\n\
.aabaa.\n";
  } else if (n == 11) {
    cout << "\
.aabaa.....\n\
a..b..a....\n\
a.cc..a....\n\
bb..dbb....\n\
a...d.a....\n\
a..b..a....\n\
.aabaa.....\n\
.......aacd\n\
.......bbcd\n\
.......efaa\n\
.......efbb\n\
";
  } else {
    int offset = 0;
    int oldn = n;
    while (n % 4 != 0) {
      for (int i = 0; i < 5; ++i)
        for (int j = 0; j < 5; ++j)
          ans[i + offset][j + offset] = for5[i][j];
      offset += 5;
      n -= 5;
    }
    while (n) {
      for (int i = 0; i < 4; ++i)
        for (int j = 0; j < 4; ++j)
          ans[i + offset][j + offset] = for4[i][j];
      offset += 4;
      n -= 4;
    }
    n = oldn;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (ans[i][j])
          cout << ans[i][j];
        else
          cout << ".";
      }
      cout << "\n";
    }
  }
  return 0;
}
Problem p02826 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np

n, m = map(int, input().split())

coef = np.minimum(np.arange(n, 1, -1), np.arange(1, n))
dp = np.zeros(n, dtype=np.int64)
dp[0] = 1
for c in coef:
    w = np.zeros(n, dtype=np.int64)
    w[::c] = 1
    dp = np.convolve(dp, w, mode="full")[:n] % m

print((dp * np.arange(n, 0, -1) % m).sum() % m)


Fixed submission:
import numpy as np

n, m = map(int, input().split())

coef = np.minimum(np.arange(n, 1, -1), np.arange(1, n))
dp = np.zeros(n, dtype=np.int64)
dp[0] = 1
for c in coef:
    ndp = np.zeros(n, dtype=np.int64)
    for i in range(0, n, c):
        ndp[i:] += dp[: n - i]
    dp = ndp % m

print((dp * np.arange(n, 0, -1) % m).sum() % m)
Problem p02826 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int ans = 0, n, m;
Int dp[5500];
int main() {
  dp[0] = 1;
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    Int need = 0;
    if (i >= n - n / 2 + 1)
      need = n - i + 2;
    else
      need = n / 2 + 1;
    if (i <= n / 2 + 1)
      need -= n / 2 + 1 - i + 1;
    //        cout << need << endl;
    for (int j = n; j >= 0; j--) {
      for (int k = need; k <= j; k += need) {
        dp[j] += dp[j - k];
        dp[j] %= m;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    //        cout << i << " " << dp[i] << endl;
    ans += dp[i] * (n - i) % m;
    ans %= m;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int ans = 0, n, m;
Int dp[5500];
int main() {
  dp[0] = 1;
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    Int need = 0;
    if (i >= n - n / 2 + 1)
      need = n - i + 2;
    else
      need = n / 2 + 1;
    if (i <= n / 2 + 1)
      need -= n / 2 + 1 - i + 1;
    //        cout << need << endl;
    for (int j = need; j <= n; j++) {
      dp[j] += dp[j - need];
      dp[j] %= m;
    }
  }
  for (int i = 0; i < n; i++) {
    //        cout << i << " " << dp[i] << endl;
    ans += dp[i] * (n - i) % m;
    ans %= m;
  }
  cout << ans << endl;
  return 0;
}
Problem p02826 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
int n;
int M;
int dp[2][5005][5005];
inline void add(int &a, int b) {
  a += b;
  if (a >= M)
    a -= M;
}
int main() {
  scanf("%d%d", &n, &M);
  int p = 0, q = 1;
  for (int i = 1; i <= n; i++)
    dp[p][n - i + 1][i] = 1;
  int k = (n + 3) / 2;
  for (int i = 2; i < k; i++) {
    //	cout<<i<<endl;
    int lim = min(n, n / (i - 1) + 1);
    for (int j = 1; j <= lim * 2; j++)
      for (int k = 1; k <= n; k++)
        dp[q][j][k] = 0;
    for (int k = 1; k <= n; k++) // sum
    {
      int ans = 0, presum = 0;
      for (int j = lim; j >= 1; j--) // val=j-1
      {
        add(presum, dp[p][j][k]);
        add(ans, presum);
        if (k - j + 1 > 0) {
          add(dp[q][j][k - j + 1], ans);
        }
      }
    }
    swap(p, q);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      add(ans, dp[p][i][j] * 1ll * (n & 1 ? 1 : i) % M);
    }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
int n;
int M;
int dp[2][5005][5005];
inline void add(int &a, int b) {
  a += b;
  if (a >= M)
    a -= M;
}
int main() {
  scanf("%d%d", &n, &M);
  int p = 0, q = 1;
  for (int i = 1; i <= n; i++)
    dp[p][n - i + 1][i] = 1;
  int k = (n + 3) / 2;
  for (int i = 2; i < k; i++) {
    //	cout<<i<<endl;
    int lim = min(n, n / (i - 1) + 1);
    for (int j = 1; j <= lim * 2 && j <= n; j++)
      for (int k = 1; k <= n; k++)
        dp[q][j][k] = 0;
    for (int k = 1; k <= n; k++) // sum
    {
      int ans = 0, presum = 0;
      for (int j = lim; j >= 1; j--) // val=j-1
      {
        add(presum, dp[p][j][k]);
        add(ans, presum);
        if (k - j + 1 > 0) {
          add(dp[q][j][k - j + 1], ans);
        }
      }
    }
    swap(p, q);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      add(ans, dp[p][i][j] * 1ll * (n & 1 ? 1 : i) % M);
    }
  printf("%d\n", ans);
  return 0;
}
Problem p02827 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 50000
#define M 100000
using namespace std;
int n, m, op, a[M + 5], b[M + 5];
char ans[N + 5];
class UniformingSolver {
private:
  int p[N + 5];
  bitset<N + 5> S[N + 5];

public:
  I void Solve() {
    RI i, j;
    for (i = 1; i <= n; ++i)
      S[i].set(i);
    for (i = 1; i <= m; ++i)
      S[a[i]] = S[b[i]] = S[a[i]] | S[b[i]];
    for (i = 1; i <= n; ++i)
      if (S[i].count() == n) {
        for (p[i] = 1, j = m; j; --j)
          p[a[j]] ? (p[b[j]] = 1, ans[j] = '^')
                  : (p[a[j]] = p[b[j]], ans[j] = 'v');
        puts(ans + 1);
        return;
      }
    puts("-1");
  }
} S1;
class NonUniformingSolver {
private:
  int t[N + 5], k[N + 5];

public:
  I void Solve() {
    RI i;
    if (n <= 2)
      return (void)(puts("-1"));
    for (i = 1; i <= n; ++i)
      k[t[i] = i] = 1;
#define U(x, y) (--k[t[x]], ++k[t[x] = t[y]])
    for (i = m; i; --i)
      k[t[a[i]]] <= k[t[b[i]]] ? (ans[i] = '^', U(b[i], a[i]))
                               : (ans[i] = 'v', U(a[i], b[i]));
    puts(ans + 1);
  }
} S2;
int main() {
  RI i;
  for (scanf("%d%d%d", &n, &m, &op), i = 1; i <= m; ++i)
    scanf("%d%d", a + i, b + i);
  return op == 1 ? S1.Solve() : S2.Solve(), 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 50000
#define M 100000
using namespace std;
int n, m, op, a[M + 5], b[M + 5];
char ans[M + 5];
class UniformingSolver {
private:
  int p[N + 5];
  bitset<N + 5> S[N + 5];

public:
  I void Solve() {
    RI i, j;
    for (i = 1; i <= n; ++i)
      S[i].set(i);
    for (i = 1; i <= m; ++i)
      S[a[i]] = S[b[i]] = S[a[i]] | S[b[i]];
    for (i = 1; i <= n; ++i)
      if (S[i].count() == n) {
        for (p[i] = 1, j = m; j; --j)
          p[a[j]] ? (p[b[j]] = 1, ans[j] = '^')
                  : (p[a[j]] = p[b[j]], ans[j] = 'v');
        puts(ans + 1);
        return;
      }
    puts("-1");
  }
} S1;
class NonUniformingSolver {
private:
  int t[N + 5], k[N + 5];

public:
  I void Solve() {
    RI i;
    if (n <= 2)
      return (void)(puts("-1"));
    for (i = 1; i <= n; ++i)
      k[t[i] = i] = 1;
#define U(x, y) (--k[t[x]], ++k[t[x] = t[y]])
    for (i = m; i; --i)
      k[t[a[i]]] <= k[t[b[i]]] ? (ans[i] = '^', U(b[i], a[i]))
                               : (ans[i] = 'v', U(a[i], b[i]));
    puts(ans + 1);
  }
} S2;
int main() {
  RI i;
  for (scanf("%d%d%d", &n, &m, &op), i = 1; i <= m; ++i)
    scanf("%d%d", a + i, b + i);
  return op == 1 ? S1.Solve() : S2.Solve(), 0;
}
Problem p02827 (C++)

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

int N, M, T, s[100003], t[100003], dis[100003];
bitset<50003> now[50003];

namespace sub1 {
void work() {
  for (int i = 1; i <= N; ++i)
    now[i].set(i);
  for (int i = 1; i <= M; ++i)
    now[s[i]] = now[t[i]] = now[s[i]] | now[t[i]];
  for (int i = 1; i <= N; ++i)
    if (now[i].count() == N) {
      dis[i] = 100000;
      for (int j = M; j; --j)
        if (dis[s[j]] && !dis[t[j]])
          dis[t[j]] = j;
        else if (dis[t[j]] && !dis[s[j]])
          dis[s[j]] = j;
      for (int j = 1; j <= M; ++j)
        putchar(dis[s[j]] < dis[t[j]] ? 'v' : '^');
      return;
    }
  puts("-1");
}
} // namespace sub1

int pot[50003], f[50003];
char str[50003];
namespace sub2 {
void work() {
  if (N == 2) {
    puts("-1");
    return;
  }
  for (int i = 1; i <= N; ++i)
    pot[f[i] = i] = 1;
  for (int j = M; j; --j)
    if (pot[f[s[j]]] < pot[f[t[j]]]) {
      str[j] = '^';
      --pot[f[t[j]]];
      ++pot[f[t[j]] = f[s[j]]];
    } else {
      str[j] = 'v';
      --pot[f[s[j]]];
      ++pot[f[s[j]] = f[t[j]]];
    }
  printf("%s\n", str + 1);
}
} // namespace sub2

int main() {
  ios::sync_with_stdio(0);
  cin >> N >> M >> T;
  for (int i = 1; i <= M; ++i)
    cin >> s[i] >> t[i];
  if (T == 1)
    sub1::work();
  else
    sub2::work();
  return 0;
}


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

int N, M, T, s[100003], t[100003], dis[100003];
bitset<50003> now[50003];

namespace sub1 {
void work() {
  for (int i = 1; i <= N; ++i)
    now[i].set(i);
  for (int i = 1; i <= M; ++i)
    now[s[i]] = now[t[i]] = now[s[i]] | now[t[i]];
  for (int i = 1; i <= N; ++i)
    if (now[i].count() == N) {
      dis[i] = 100000;
      for (int j = M; j; --j)
        if (dis[s[j]] && !dis[t[j]])
          dis[t[j]] = j;
        else if (dis[t[j]] && !dis[s[j]])
          dis[s[j]] = j;
      for (int j = 1; j <= M; ++j)
        putchar(dis[s[j]] < dis[t[j]] ? 'v' : '^');
      return;
    }
  puts("-1");
}
} // namespace sub1

int pot[50003], f[50003];
char str[100003];
namespace sub2 {
void work() {
  if (N == 2) {
    puts("-1");
    return;
  }
  for (int i = 1; i <= N; ++i)
    pot[f[i] = i] = 1;
  for (int j = M; j; --j)
    if (pot[f[s[j]]] < pot[f[t[j]]]) {
      str[j] = '^';
      --pot[f[t[j]]];
      ++pot[f[t[j]] = f[s[j]]];
    } else {
      str[j] = 'v';
      --pot[f[s[j]]];
      ++pot[f[s[j]] = f[t[j]]];
    }
  printf("%s\n", str + 1);
}
} // namespace sub2

int main() {
  ios::sync_with_stdio(0);
  cin >> N >> M >> T;
  for (int i = 1; i <= M; ++i)
    cin >> s[i] >> t[i];
  if (T == 1)
    sub1::work();
  else
    sub2::work();
  return 0;
}
Problem p02829 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().split())
print(6 - a - b)


Fixed submission:
a = int(input())
b = int(input())
print(6 - a - b)
Problem p02829 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 + 9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll t = 1;
  // cin>>t;

  while (t--) {
    ll a, b;
    cin >> a >> b;
    ll x = 1 ^ 2 ^ 3;
    cout << (x ^ a ^ b);
  }
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 + 9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

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

  ll t = 1;
  // cin>>t;

  while (t--) {
    ll a, b;
    cin >> a >> b;
    ll x = 1 ^ 2 ^ 3;
    cout << (x ^ a ^ b);
  }
}
Problem p02829 (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 REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= 3; i++) {
    if (i != a && i != b) {
      cout << i << endl;
      return 1;
    }
  }
}

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << 6 - (a + b) << endl;
}
Problem p02829 (C++)

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

#define fa(x, v) for (auto x : v)
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll) int(s.length())
#define sz(v) (ll) int(v.size())
#define MOD 1000000007

void Fast_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
  freopen("output.out", "w", stdout);
  freopen("debug.out", "w", stderr);
#endif
}

// Code Here

int main() {
  Fast_IO();
  ll a, b;
  cin >> a >> b;
  if (a > b)
    swap(a, b);
  if (a == 1 && b == 2)
    cout << 3;
  else if (a == 1 && b == 3)
    cout << 2;
  else
    cout << 1;
  return 0;
}

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

#define fa(x, v) for (auto x : v)
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll) int(s.length())
#define sz(v) (ll) int(v.size())
#define MOD 1000000007

void Fast_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
  freopen("output.out", "w", stdout);
  freopen("debug.out", "w", stderr);
#endif
}

// Code Here

int main() {
  // Fast_IO();
  ll a, b;
  cin >> a >> b;
  if (a > b)
    swap(a, b);
  if (a == 1 && b == 2)
    cout << 3;
  else if (a == 1 && b == 3)
    cout << 2;
  else
    cout << 1;
  return 0;
}
Problem p02829 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
                chrono::high_resolution_clock::now().time_since_epoch())
                .count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 100005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr, val) memset(arr, val, sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

#undef int
int main() {
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("ip.txt", "r", stdin);
  freopen("op.txt", "w", stdout);
#endif

  int a, b;
  cin >> a >> b;
  a ^= b;

  cout << a << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
                chrono::high_resolution_clock::now().time_since_epoch())
                .count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 100005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr, val) memset(arr, val, sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

#undef int
int main() {
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int a, b;
  cin >> a >> b;
  a ^= b;

  cout << a << endl;

  return 0;
}
Problem p02829 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  int c = 6 - a - b;
  cout << c;
  return 1;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int c = 6 - a - b;
  cout << c;
  return 0;
}
Problem p02829 (C++)

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

using namespace std;

typedef long long ll;

#define sz(s) (int)s.size()
#define endl '\n'

void PLAY() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  PLAY();

  int a, b;
  cin >> a >> b;
  cout << 6 - (a + b) << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(s) (int)s.size()
#define endl '\n'

void PLAY() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  PLAY();

  int a, b;
  cin >> a >> b;
  cout << 6 - (a + b) << endl;

  return 0;
}
Problem p02829 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().split())
ans = 6 - (a + b)
print(ans)


Fixed submission:
a = int(input())
b = int(input())
print(6 - a - b)
Problem p02829 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> ans{1, 2, 3};
  ans.erase(ans.begin() + a - 1);
  ans.erase(ans.begin() + b - 1);
  cout << ans.at(0) << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  for (int i = 1; i < 4; i++) {
    if (i != a && i != b) {
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p02829 (C++)

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

int main() {
  int a, b;
  std::cin >> a >> b;
  return 6 - a - b;
}


Fixed submission:
#include <iostream>

int main() {
  int a, b;
  std::cin >> a >> b;
  std::cout << 6 - a - b;
  return 0;
}
Problem p02829 (C++)

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

int main() {
  int A;
  int B;
  int quizChoice = 6;

  cin >> A;
  cin >> B;

  quizChoice -= (A + B);

  return quizChoice;
}

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

int main() {
  int A;
  int B;
  int quizChoice = 6;

  cin >> A;
  cin >> B;

  quizChoice -= (A + B);

  cout << quizChoice;

  return 0;
}
Problem p02830 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[100], b[100], c[100];
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[i] = '\0';
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  b[i] = '\0';
  // cout<<a<<"  "<<b<<endl;
  int j = 0;
  for (i = 0; i < n; i++, j = j + 2) {
    c[j] = a[i];
    c[j + 1] = b[i];
    // cout<<"cj="<<c[j]<<"  "<<"j+1="<<c[j+1]<<endl;
    // j=j+2;
  }
  c[n * 2] = '\0';
  cout << c << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[101], b[101], c[204];
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[i] = '\0';
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  b[i] = '\0';
  // cout<<a<<"  "<<b<<endl;
  int j = 0;
  for (i = 0; i < n; i++, j = j + 2) {
    c[j] = a[i];
    c[j + 1] = b[i];
    // cout<<"cj="<<c[j]<<"  "<<"j+1="<<c[j+1]<<endl;
    // j=j+2;
  }
  c[n * 2] = '\0';
  cout << c << endl;

  return 0;
}
Problem p02830 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(void) {
  int len, i, j = 0;
  char str1[100], str2[100], str3[200];

  scanf("%d", &len);
  scanf("%s %s", str1, str2);

  for (i = 0; i <= len; i++) {
    str3[j] = str1[i];
    j++;
    str3[j] = str2[i];
    j++;
  }

  printf("%s\n", str3);

  return 0;
}


Fixed submission:
#include <stdio.h>

int main(void) {
  int len, i, j = 0;
  char str1[101], str2[101], str3[202];

  scanf("%d", &len);
  scanf("%s %s", str1, str2);

  for (i = 0; i <= len; i++) {
    str3[j] = str1[i];
    j++;
    str3[j] = str2[i];
    j++;
  }

  printf("%s\n", str3);

  return 0;
}
Problem p02830 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char a[n], b[n];
  string s = "";
  scanf("%s%s", a[n], b[n]);
  for (int i = 0; i < n; i++) {
    s += a[i];
    s += b[i];
  }
  cout << s << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s = "", a, b;
  cin >> n;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    s += a[i];
    s += b[i];
  }
  cout << s << "\n";
  return 0;
}
Problem p02830 (C++)

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

using namespace std;

int n, i;
string s, t;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int n, i;
string s, t;
int main() {
  cin >> n >> s >> t;
  for (i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  return 0;
}
Problem p02830 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 1e9 + 7;
void chmod(ll &M) {
  if (M >= mod)
    M %= mod;
  else if (M < 0) {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}
ll modpow(ll x, ll n) {
  if (n == 0)
    return 1;
  ll res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}

int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

using namespace std;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  string R;
  rep(i, 2 * N) {
    R += S.at(i);
    R += T.at(i);
  }

  cout << R << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 1e9 + 7;
void chmod(ll &M) {
  if (M >= mod)
    M %= mod;
  else if (M < 0) {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}
ll modpow(ll x, ll n) {
  if (n == 0)
    return 1;
  ll res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}

int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

using namespace std;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  string R;
  rep(i, N) {
    R += S.at(i);
    R += T.at(i);
  }

  cout << R << endl;
}
Problem p02830 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << "\n";
  return 1;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << "\n";
}