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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ifor(i, n) for (i = 0; i < n; i++)
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, n, t = INT_MAX, p = INT_MAX, j = 0, x, a = 0, b, l = 0, r = 0, c, y, m,
            q;
  string s;
  cin >> a >> b >> m;
  int ara[a];
  int arr[b];
  for (i = 0; i < a; i++) {
    cin >> ara[i];
  }
  for (i = 0; i < b; i++) {
    cin >> arr[i];
  }
  for (j = 0; j < m; j++) {
    cin >> x >> y >> c;

    l = ara[x - 1] + arr[y - 1] - c;
    p = min(p, l);
  }
  for (i = 0; i < a; i++) {
    for (j = 0; j < b; j++) {
      q = ara[i] + arr[j];
      t = min(q, t);
    }
  }
  cout << min(p, t) << endl;

  return EXIT_SUCCESS;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ifor(i, n) for (i = 0; i < n; i++)
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, n, t = INT_MAX, p = INT_MAX, j = 0, x, a = 0, b, l = 0, r = 0, c, y, m,
            q;
  string s;
  cin >> a >> b >> m;
  int ara[a];
  int arr[b];
  for (i = 0; i < a; i++) {
    cin >> ara[i];
  }
  for (i = 0; i < b; i++) {
    cin >> arr[i];
  }
  for (j = 0; j < m; j++) {
    cin >> x >> y >> c;

    l = ara[x - 1] + arr[y - 1] - c;
    p = min(p, l);
  }
  sort(ara, ara + a);
  sort(arr, arr + b);
  t = arr[0] + ara[0];
  cout << min(p, t) << endl;

  return EXIT_SUCCESS;
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define rep(i, l, r) for (int(i) = (l); (i) < (r); (i)++)
using namespace std;
int main() {
  ll A, B, M;
  cin >> A >> B >> M;
  vector<ll> a(A), b(B);
  ll mia, mib = 1e9;
  rep(i, 0, A) {
    cin >> a[i];
    mia = min(mia, a[i]);
  }
  rep(i, 0, B) {
    cin >> b[i];
    mib = min(mib, b[i]);
  }

  ll ans = mia + mib;
  rep(i, 0, M) {
    rep(j, 0, M) {
      ll x, y, c;
      cin >> x >> y >> c;
      ans = min(ans, a[x - 1] + b[y - 1] - c);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define rep(i, l, r) for (int(i) = (l); (i) < (r); (i)++)
using namespace std;
int main() {
  ll A, B, M;
  cin >> A >> B >> M;
  vector<ll> a(A), b(B);
  ll mia, mib = 1e9;
  rep(i, 0, A) {
    cin >> a[i];
    mia = min(mia, a[i]);
  }
  rep(i, 0, B) {
    cin >> b[i];
    mib = min(mib, b[i]);
  }

  ll ans = mia + mib;
  rep(i, 0, M) {
    ll x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  cout << ans << endl;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<long long> a(A), b(B), x(M), y(M), c(M);
  rep(i, A) cin >> a.at(i);
  rep(i, B) cin >> b.at(i);
  rep(i, M) cin >> x.at(i) >> y.at(i) >> c.at(i);
  long long mini = 200000;
  rep(i, M) {
    if ((a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i)) <= mini) {
      mini = (a.at(x.at(i - 1)) + b.at(y.at(i - 1)) - c.at(i));
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (mini > a.at(0) + b.at(0))
    mini = a.at(0) + b.at(0);
  cout << mini << endl;
}

Fixed submission:
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<long long> a(A), b(B), x(M), y(M), c(M);
  rep(i, A) cin >> a.at(i);
  rep(i, B) cin >> b.at(i);
  rep(i, M) cin >> x.at(i) >> y.at(i) >> c.at(i);
  long long mini = 200000;
  rep(i, M) {
    if ((a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i)) <= mini) {
      mini = (a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i));
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (mini > a.at(0) + b.at(0))
    mini = a.at(0) + b.at(0);
  cout << mini << endl;
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vec a(A);
  vec b(B);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  vec x(M), y(M), c(M);
  for (int i = 0; i < M; i++)
    cin >> x[i] >> y[i] >> c[i];
  int ans = 200000;
  for (int i = 0; i < M; i++) {
    int wa = a[x[i] - 1] + b[y[i] - 1] - c[i];
    ans = min(ans, wa);
  }
  for (int i = 0; i < A; i++) {
    for (int j = 0; j < B; j++) {
      int wa = a[i] + b[j];
      ans = min(ans, wa);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vec a(A);
  vec b(B);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  vec x(M), y(M), c(M);
  for (int i = 0; i < M; i++)
    cin >> x[i] >> y[i] >> c[i];
  int ans = 200000;
  for (int i = 0; i < M; i++) {
    int wa = a[x[i] - 1] + b[y[i] - 1] - c[i];
    ans = min(ans, wa);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int waa = a[0] + b[0];
  ans = min(waa, ans);
  cout << ans << endl;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
int r;
int a[10005], b[10005], c[10005], d[10005], e[10005];
int main() {
  int n, i, j, t, k, l, o, m, q, w;
  cin >> m >> t >> k;
  for (i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= t; i++) {
    scanf("%d", &b[i]);
  }
  for (i = 1; i <= k; i++) {
    scanf("%d%d%d", &c[i], &d[i], &e[i]);
    if (i == 1)
      r = a[c[1]] + b[d[1]] - e[1];
    r = min(r, a[c[i]] + b[d[i]] - e[i]);
  }
  sort(a + 1, a + 1 + m);
  sort(b + 1, b + 1 + t);
  r = min(a[1] + b[1], r);
  cout << r;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
int r;
int a[100005], b[100005], c[100005], d[100005], e[100005];
int main() {
  int n, i, j, t, k, l, o, m, q, w;
  cin >> m >> t >> k;
  for (i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= t; i++) {
    scanf("%d", &b[i]);
  }
  for (i = 1; i <= k; i++) {
    scanf("%d%d%d", &c[i], &d[i], &e[i]);
    if (i == 1)
      r = a[c[1]] + b[d[1]] - e[1];
    r = min(r, a[c[i]] + b[d[i]] - e[i]);
  }
  sort(a + 1, a + 1 + m);
  sort(b + 1, b + 1 + t);
  r = min(a[1] + b[1], r);
  cout << r;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> valueA(A);
  vector<int> valueB(B);
  vector<int> setx;
  vector<int> sety;
  vector<int> waribiki;
  for (int a = 0; a < A; ++a) {
    cin >> valueA.at(a);
  }
  for (int b = 0; b < B; ++b) {
    cin >> valueB.at(b);
  }

  for (int m = 0; m < M; m++) {
    cin >> setx.at(m) >> sety.at(m) >> waribiki.at(m);
  }

  int minA;
  if (valueA.size() == 1) {
    minA = valueA.at(0);
  } else {
    minA = *min_element(valueA.begin(), valueA.end());
  }

  int minB;
  if (valueB.size() == 1) {
    minB = valueB.at(0);
  } else {
    minB = *min_element(valueB.begin(), valueB.end());
  }
  long minvalue = minA + minB;

  for (int m = 0; m < M; ++m) {
    long value =
        valueA.at(setx.at(m) - 1) + valueB.at(sety.at(m) - 1) - waribiki.at(m);
    if (minvalue > value) {
      minvalue = value;
    }
  }
  cout << minvalue << endl;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> valueA(A);
  vector<int> valueB(B);
  vector<int> setx(M);
  vector<int> sety(M);
  vector<int> waribiki(M);
  for (int a = 0; a < A; ++a) {
    cin >> valueA.at(a);
  }
  for (int b = 0; b < B; ++b) {
    cin >> valueB.at(b);
  }

  for (int m = 0; m < M; m++) {
    cin >> setx.at(m) >> sety.at(m) >> waribiki.at(m);
  }

  int minA;
  if (valueA.size() == 1) {
    minA = valueA.at(0);
  } else {
    minA = *min_element(valueA.begin(), valueA.end());
  }

  int minB;
  if (valueB.size() == 1) {
    minB = valueB.at(0);
  } else {
    minB = *min_element(valueB.begin(), valueB.end());
  }
  long minvalue = minA + minB;

  for (int m = 0; m < M; ++m) {
    long value =
        valueA.at(setx.at(m) - 1) + valueB.at(sety.at(m) - 1) - waribiki.at(m);
    if (minvalue > value) {
      minvalue = value;
    }
  }
  cout << minvalue << endl;
}
Problem p02749 (C++)

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

typedef long long ll;

int n;
vector<int> G[200010];

int col[100010];
void dfs(int v, int p, int c) {
  col[v] = c;
  for (int u : G[v]) {
    if (u == p)
      continue;
    dfs(u, v, c ^ 1);
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(1, 0, 0);
  int cnt[2] = {};
  for (int i = 1; i <= n; i++) {
    cnt[col[i]]++;
  }
  int a, b, c;
  a = b = c = n / 3;
  if (n % 3 >= 1)
    a++;
  if (n % 3 >= 2)
    b++;

  static int ret[200010];
  static bool used[200010];
  for (int i = 0; i < 200010; i++) {
    used[i] = false;
  }
  if (cnt[0] <= c || cnt[1] <= c) {
    int t = 0;
    if (cnt[0] > c)
      t = 1;
    int CNT = 0;
    for (int i = 1; i <= n; i++) {
      if (col[i] == t) {
        CNT++;
        ret[i] = CNT * 3;
        used[ret[i]] = true;
      }
    }
    CNT = 1;
    for (int i = 1; i <= n; i++) {
      if (col[i] != t) {
        while (used[CNT])
          CNT++;
        ret[i] = CNT;
        used[ret[i]] = true;
      }
    }
  } else {
    cnt[0] = cnt[1] = 0;
    int k = 3;
    for (int i = 1; i <= n; i++) {
      if (3 * cnt[col[i]] + 1 + col[i] <= n) {
        ret[i] = 3 * cnt[col[i]] + 1 + col[i];
      } else {
        while (used[k])
          k += 3;
        ret[i] = k;
      }
      cnt[col[i]]++;
      used[ret[i]] = true;
    }
  }

  for (int i = 1; i <= n; i++) {
    printf("%d%c", ret[i], (i == n) ? '\n' : ' ');
  }
}


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

typedef long long ll;

int n;
vector<int> G[200010];

int col[200010];
void dfs(int v, int p, int c) {
  col[v] = c;
  for (int u : G[v]) {
    if (u == p)
      continue;
    dfs(u, v, c ^ 1);
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(1, 0, 0);
  int cnt[2] = {};
  for (int i = 1; i <= n; i++) {
    cnt[col[i]]++;
  }
  int a, b, c;
  a = b = c = n / 3;
  if (n % 3 >= 1)
    a++;
  if (n % 3 >= 2)
    b++;

  static int ret[200010];
  static bool used[200010];
  for (int i = 0; i < 200010; i++) {
    used[i] = false;
  }
  if (cnt[0] <= c || cnt[1] <= c) {
    int t = 0;
    if (cnt[0] > c)
      t = 1;
    int CNT = 0;
    for (int i = 1; i <= n; i++) {
      if (col[i] == t) {
        CNT++;
        ret[i] = CNT * 3;
        used[ret[i]] = true;
      }
    }
    CNT = 1;
    for (int i = 1; i <= n; i++) {
      if (col[i] != t) {
        while (used[CNT])
          CNT++;
        ret[i] = CNT;
        used[ret[i]] = true;
      }
    }
  } else {
    cnt[0] = cnt[1] = 0;
    int k = 3;
    for (int i = 1; i <= n; i++) {
      if (3 * cnt[col[i]] + 1 + col[i] <= n) {
        ret[i] = 3 * cnt[col[i]] + 1 + col[i];
      } else {
        while (used[k])
          k += 3;
        ret[i] = k;
      }
      cnt[col[i]]++;
      used[ret[i]] = true;
    }
  }

  for (int i = 1; i <= n; i++) {
    printf("%d%c", ret[i], (i == n) ? '\n' : ' ');
  }
}
Problem p02749 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
int ans[N];
vector<int> G[N], col[2], mod[3];
void dfs(int x, int c, int fa) {
  col[c].push_back(x);
  for (auto y : G[x])
    if (y != fa)
      dfs(y, c ^ 1, x);
}
void sol(int i, int j) {
  while (!col[i].empty() && !mod[j].empty()) {
    ans[col[i].back()] = mod[j].back();
    col[i].pop_back(), mod[j].pop_back();
  }
}
int main() {
  int n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    G[x].pb(y), G[y].pb(x);
  }
  for (int i = 1; i <= n; i++)
    mod[i % 3].pb(i);
  dfs(1, 0, 0);
  sol(col[0].size() < col[1].size(), 1), sol(col[0].size() < col[1].size(), 2);
  sol(0, 0), sol(1, 0);
  for (int i = 1; i <= n; i++)
    printf("%d ", ans[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
int ans[N];
vector<int> G[N], col[2], mod[3];
void dfs(int x, int c, int fa) {
  col[c].push_back(x);
  for (auto y : G[x])
    if (y != fa)
      dfs(y, c ^ 1, x);
}
void sol(int i, int j) {
  while (!col[i].empty() && !mod[j].empty()) {
    ans[col[i].back()] = mod[j].back();
    col[i].pop_back(), mod[j].pop_back();
  }
}
int main() {
  int n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    G[x].pb(y), G[y].pb(x);
  }
  for (int i = 1; i <= n; i++)
    mod[i % 3].pb(i);
  dfs(1, 0, 0);
  sol(col[0].size() < col[1].size(), 1), sol(col[0].size() < col[1].size(), 2);
  sol(0, 0), sol(1, 0);
  for (int i = 1; i <= n; i++)
    printf("%d ", ans[i]);
  return 0;
}
Problem p02749 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
T = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)


colors = [-1] * N
stack = [(0, 0)]
while stack:
    n, color = stack.pop()
    colors[n] = color
    for to in T[n]:
        if colors[to] != -1:
            continue
        stack.append((to, color ^ 1))


# あまり１、あまり２、あまり０になるように並び替え
X = [[] for _ in range(3)]
for n in range(1, N + 1):
    X[n % 3].append(n)
X.append(X[0])
del X[0]


ans = []
x12, x3 = X[0] + X[1], X[2]
if colors.count(0) <= N // 3:
    for color in colors:
        if color == 0:
            ans.append(x3.pop())
        elif x12:
            ans.append(x12.pop())
        else:
            ans.append(x3.pop())

elif colors.count(1) <= N // 3:
    for color in colors:
        if color == 1:
            ans.append(x3.pop())
        elif x12:
            ans.append(x12.pop())
        else:
            ans.append(x3.pop())

else:
    for color in colors:
        if X[color]:
            ans.append(X[color ^ 1].pop())
        else:
            ans.append(X[2].pop())

print(" ".join(map(str, ans)))


Fixed submission:
N = int(input())
T = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    T[a].append(b)
    T[b].append(a)


colors = [-1] * N
stack = [(0, 0)]
while stack:
    n, color = stack.pop()
    colors[n] = color
    for to in T[n]:
        if colors[to] != -1:
            continue
        stack.append((to, color ^ 1))


# あまり１、あまり２、あまり０になるように並び替え
X = [[] for _ in range(3)]
for n in range(1, N + 1):
    X[n % 3].append(n)
X.append(X[0])
del X[0]


ans = []
x12, x3 = X[0] + X[1], X[2]
if colors.count(0) <= N // 3:
    for color in colors:
        if color == 0:
            ans.append(x3.pop())
        elif x12:
            ans.append(x12.pop())
        else:
            ans.append(x3.pop())

elif colors.count(1) <= N // 3:
    for color in colors:
        if color == 1:
            ans.append(x3.pop())
        elif x12:
            ans.append(x12.pop())
        else:
            ans.append(x3.pop())

else:
    for color in colors:
        if X[color]:
            ans.append(X[color].pop())
        else:
            ans.append(X[2].pop())

print(" ".join(map(str, ans)))
Problem p02749 (C++)

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

const int _ = 1e5 + 7;
struct Edge {
  int end, upEd;
} Ed[_ << 1];
int head[_], cntEd, col[2], N;
void addEd(int a, int b) {
  Ed[++cntEd] = (Edge){b, head[a]};
  head[a] = cntEd;
}

void dfs(int x, int p, int c) {
  ++col[c];
  for (int i = head[x]; i; i = Ed[i].upEd)
    if (Ed[i].end != p)
      dfs(Ed[i].end, x, c ^ 1);
}

vector<int> pot[3];
int arr[_];
void dfs1(int x, int p, int c, int id) {
  if (id == 2) {
    int i = pot[c + 1].size() ? c + 1 : 0;
    arr[x] = pot[i].back();
    pot[i].pop_back();
  } else if (!(id ^ c)) {
    arr[x] = pot[0].back();
    pot[0].pop_back();
  } else {
    int p = pot[1].empty() ? (pot[2].empty() ? 0 : 2) : 1;
    arr[x] = pot[p].back();
    pot[p].pop_back();
  }
  for (int i = head[x]; i; i = Ed[i].upEd)
    if (Ed[i].end != p)
      dfs1(Ed[i].end, x, c ^ 1, id);
}

signed main() {
  cin >> N;
  for (int i = 1; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    addEd(x, y);
    addEd(y, x);
  }
  for (int i = 1; i <= N; ++i)
    pot[i % 3].push_back(i);
  dfs(1, 0, 0);
  dfs1(1, 0, 0, col[0] < pot[1].size() ? 0 : (col[1] < pot[2].size() ? 1 : 2));
  for (int i = 1; i <= N; ++i)
    cout << arr[i] << ' ';
  return 0;
}


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

const int _ = 2e5 + 7;
struct Edge {
  int end, upEd;
} Ed[_ << 1];
int head[_], cntEd, col[2], N;
void addEd(int a, int b) {
  Ed[++cntEd] = (Edge){b, head[a]};
  head[a] = cntEd;
}

void dfs(int x, int p, int c) {
  ++col[c];
  for (int i = head[x]; i; i = Ed[i].upEd)
    if (Ed[i].end != p)
      dfs(Ed[i].end, x, c ^ 1);
}

vector<int> pot[3];
int arr[_];
void dfs1(int x, int p, int c, int id) {
  if (id == 2) {
    int i = pot[c + 1].size() ? c + 1 : 0;
    arr[x] = pot[i].back();
    pot[i].pop_back();
  } else if (!(id ^ c)) {
    arr[x] = pot[0].back();
    pot[0].pop_back();
  } else {
    int p = pot[1].empty() ? (pot[2].empty() ? 0 : 2) : 1;
    arr[x] = pot[p].back();
    pot[p].pop_back();
  }
  for (int i = head[x]; i; i = Ed[i].upEd)
    if (Ed[i].end != p)
      dfs1(Ed[i].end, x, c ^ 1, id);
}

signed main() {
  cin >> N;
  for (int i = 1; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    addEd(x, y);
    addEd(y, x);
  }
  for (int i = 1; i <= N; ++i)
    pot[i % 3].push_back(i);
  dfs(1, 0, 0);
  dfs1(1, 0, 0, col[0] < pot[1].size() ? 0 : (col[1] < pot[2].size() ? 1 : 2));
  for (int i = 1; i <= N; ++i)
    cout << arr[i] << ' ';
  return 0;
}
Problem p02749 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 200002
using namespace std;
vector<int> v[N], vv[2], nr[3];
int c[N], l[N];
void dfs(int i) {
  vv[l[i] % 2].push_back(i);
  for (auto it : v[i])
    if (!l[it])
      l[it] = l[i] + 1, dfs(it);
}
void ad(int i, int j) {
  c[vv[i].back()] = nr[j].back();
  vv[i].pop_back();
  nr[j].pop_back();
}
int main() {
  int n, i, j, k;
  cin >> n;
  for (k = 1; k < n; k++) {
    cin >> i >> j;
    v[i].push_back(j);
    v[j].push_back(i);
    nr[k % 3].push_back(k);
  }
  nr[n % 3].push_back(n);
  l[1] = 1;
  dfs(1);
  if (vv[0].size() <= n / 3) {
    while (vv[0].size())
      ad(0, 0);
    while (vv[1].size())
      ad(1, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2));
  } else if (vv[1].size() <= 3) {
    while (vv[1].size())
      ad(1, 0);
    while (vv[0].size())
      ad(0, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2));
  } else {
    while (vv[0].size())
      ad(0, nr[1].size() ? 1 : 0);
    while (vv[1].size())
      ad(1, nr[0].size() ? 0 : 2);
  }
  for (i = 1; i <= n; i++)
    cout << c[i] << " ";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 200002
using namespace std;
vector<int> v[N], vv[2], nr[3];
int c[N], l[N];
void dfs(int i) {
  vv[l[i] % 2].push_back(i);
  for (auto it : v[i])
    if (!l[it])
      l[it] = l[i] + 1, dfs(it);
}
void ad(int i, int j) {
  c[vv[i].back()] = nr[j].back();
  vv[i].pop_back();
  nr[j].pop_back();
}
int main() {
  int n, i, j, k;
  cin >> n;
  for (k = 1; k < n; k++) {
    cin >> i >> j;
    v[i].push_back(j);
    v[j].push_back(i);
    nr[k % 3].push_back(k);
  }
  nr[n % 3].push_back(n);
  l[1] = 1;
  dfs(1);
  if (vv[0].size() <= n / 3) {
    while (vv[0].size())
      ad(0, 0);
    while (vv[1].size())
      ad(1, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2));
  } else if (vv[1].size() <= n / 3) {
    while (vv[1].size())
      ad(1, 0);
    while (vv[0].size())
      ad(0, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2));
  } else {
    while (vv[0].size())
      ad(0, nr[1].size() ? 1 : 0);
    while (vv[1].size())
      ad(1, nr[0].size() ? 0 : 2);
  }
  for (i = 1; i <= n; i++)
    cout << c[i] << " ";
  return 0;
}
Problem p02749 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
vector<int> v[3], g[2], l[200003];
int n, ans[200003];
bool used[200003];
void dfs(int x, bool a, int p) {
  g[a].push_back(x);
  for (int i = 0; i < l[x].size(); i++)
    if (l[x][i] != p)
      dfs(l[x][i], a ^ 1, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    l[x].push_back(y);
    l[y].push_back(x);
  }
  dfs(0, 0, -1);
  for (int i = 1; i <= n; i++)
    v[i % 3].push_back(i);
  if (g[0].size() < g[1].size())
    swap(g[0], g[1]);
  if (g[0].size() <= v[0].size()) {
    for (int i = 0; i < g[0].size(); i++)
      ans[g[0][i]] = v[0][i], used[v[0][i]] = 1;
    for (int i = 1; i <= n; i++)
      if (!used[i])
        ans[g[1].back()] = i, g[1].pop_back();
  } else {
    for (int i = 0; i < v[1].size(); i++)
      ans[g[0].back()] = v[1][i], g[0].pop_back();
    for (int i = 0; i < v[2].size(); i++)
      ans[g[1].back()] = v[2][i], g[1].pop_back();
    for (int i = 0; i < g[0].size(); i++)
      ans[g[0][i]] = v[0].back(), v[0].pop_back();
    for (int i = 0; i < g[1].size(); i++)
      ans[g[1][i]] = v[0].back(), v[0].pop_back();
  }
  for (int i = 0; i < n; i++)
    printf("%d ", ans[i]);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
vector<int> v[3], g[2], l[200003];
int n, ans[200003];
bool used[200003];
void dfs(int x, bool a, int p) {
  g[a].push_back(x);
  for (int i = 0; i < l[x].size(); i++)
    if (l[x][i] != p)
      dfs(l[x][i], a ^ 1, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    l[x].push_back(y);
    l[y].push_back(x);
  }
  dfs(0, 0, -1);
  for (int i = 1; i <= n; i++)
    v[i % 3].push_back(i);
  if (g[1].size() < g[0].size())
    swap(g[0], g[1]);
  if (g[0].size() <= v[0].size()) {
    for (int i = 0; i < g[0].size(); i++)
      ans[g[0][i]] = v[0][i], used[v[0][i]] = 1;
    for (int i = 1; i <= n; i++)
      if (!used[i])
        ans[g[1].back()] = i, g[1].pop_back();
  } else {
    for (int i = 0; i < v[1].size(); i++)
      ans[g[0].back()] = v[1][i], g[0].pop_back();
    for (int i = 0; i < v[2].size(); i++)
      ans[g[1].back()] = v[2][i], g[1].pop_back();
    for (int i = 0; i < g[0].size(); i++)
      ans[g[0][i]] = v[0].back(), v[0].pop_back();
    for (int i = 0; i < g[1].size(); i++)
      ans[g[1][i]] = v[0].back(), v[0].pop_back();
  }
  for (int i = 0; i < n; i++)
    printf("%d ", ans[i]);
}
Problem p02750 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
static const int64_t INF = 100000000000;
int64_t N, T;
int64_t dp[100005][31];
int main() {
  cin >> N >> T;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    A.at(i) = a + 1;
    cin >> B.at(i);
  }
  vector<pair<double, int64_t>> C;
  vector<int64_t> D;
  for (int64_t i = 0; i < N; i++) {
    if (A[i] == 1)
      D.push_back(B[i] + 1);
    else {
      double a = A[i];
      double b = B[i];
      pair<double, int64_t> p(-(a + b) / (b + 1), i);
      C.push_back(p);
    }
  }
  sort(C.begin(), C.end());
  sort(D.begin(), D.end());
  int M = C.size();
  vector<pair<int64_t, int64_t>> P(M);
  for (int i = 0; i < M; i++) {
    int64_t I = C[i].second;
    pair<int64_t, int64_t> p(A[I], B[I]);
    P[i] = p;
  }
  for (int i = 0; i <= M; i++)
    for (int j = 1; j <= 30; j++)
      dp[i][j] = INF;
  for (int i = 1; i <= M; i++)
    for (int j = 1; j <= 30; j++) {
      dp[i][j] = min(dp[i - 1][j],
                     P[i - 1].first * (dp[i - 1][j - 1] + 1) + P[i - 1].second);
    }
  vector<int64_t> d(N - M + 1);
  d[0] = 0;
  for (int i = 1; i <= N - M; i++)
    d[i] = d[i - 1] + D[i - 1];
  int64_t ans = 0;
  for (int i = 0; i <= 30; i++) {
    if (dp[M][i] <= T) {
      auto itr = upper_bound(d.begin(), d.end(), T - dp[M][i]);
      int k = distance(d.begin(), itr);
      if (ans < k + i - 1)
        ans = k + i - 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
static const int64_t INF = 100000000000;
int64_t N, T;
int64_t dp[200005][31];
int main() {
  cin >> N >> T;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    A.at(i) = a + 1;
    cin >> B.at(i);
  }
  vector<pair<double, int64_t>> C;
  vector<int64_t> D;
  for (int64_t i = 0; i < N; i++) {
    if (A[i] == 1)
      D.push_back(B[i] + 1);
    else {
      double a = A[i];
      double b = B[i];
      pair<double, int64_t> p(-(a + b) / (b + 1), i);
      C.push_back(p);
    }
  }
  sort(C.begin(), C.end());
  sort(D.begin(), D.end());
  int M = C.size();
  vector<pair<int64_t, int64_t>> P(M);
  for (int i = 0; i < M; i++) {
    int64_t I = C[i].second;
    pair<int64_t, int64_t> p(A[I], B[I]);
    P[i] = p;
  }
  for (int i = 0; i <= M; i++)
    for (int j = 1; j <= 30; j++)
      dp[i][j] = INF;
  for (int i = 1; i <= M; i++)
    for (int j = 1; j <= 30; j++) {
      dp[i][j] = min(dp[i - 1][j],
                     P[i - 1].first * (dp[i - 1][j - 1] + 1) + P[i - 1].second);
    }
  vector<int64_t> d(N - M + 1);
  d[0] = 0;
  for (int i = 1; i <= N - M; i++)
    d[i] = d[i - 1] + D[i - 1];
  int64_t ans = 0;
  for (int i = 0; i <= 30; i++) {
    if (dp[M][i] <= T) {
      auto itr = upper_bound(d.begin(), d.end(), T - dp[M][i]);
      int k = distance(d.begin(), itr);
      if (ans < k + i - 1)
        ans = k + i - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02750 (C++)

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

using namespace std;

struct Data {
  ll a, b;

  bool operator<(const Data &other) const {
    if (a == other.a)
      return (b < other.b);
    return ((a * (other.b + 1)) > (other.a * (b + 1)));
  }
};

int main() {
  // freopen("a.in", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  ll t;
  cin >> n >> t;
  vector<Data> v(n + 1, {0, 0});
  for (int i = 1; i <= n; i++)
    cin >> v[i].a >> v[i].b;
  sort(v.begin() + 1, v.end());

  int m = n;
  n = 1;
  while (n <= m && v[n].a != 0)
    n++;
  n--;

  int lim = (int)log2(t) + 5;
  vector<vector<ll>> dp(n + 1, vector<ll>(lim + 1, t + 5));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 0;
    for (int j = 1; j <= min(lim, i); j++)
      dp[i][j] =
          min(dp[i - 1][j], (dp[i - 1][j - 1] + 1) * (v[i].a + 1) + v[i].b);
  }

  int ans = 0;
  for (int i = 0; i <= lim; i++) {
    int j = n + 1;
    while (j <= m && dp[n][i] + 1 + v[j].b <= t) {
      dp[n][i] += (1 + v[j].b);
      j++;
    }
    if (dp[n][i] <= t)
      ans = max(ans, i + j - n - 1);
  }
  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

struct Data {
  ll a, b;

  bool operator<(const Data &other) const {
    if (a == other.a)
      return (b < other.b);
    return ((a * (other.b + 1)) > (other.a * (b + 1)));
  }
};

int main() {
  // freopen("a.in", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  ll t;
  cin >> n >> t;
  vector<Data> v(n + 1, {0, 0});
  for (int i = 1; i <= n; i++)
    cin >> v[i].a >> v[i].b;
  sort(v.begin() + 1, v.end());

  int m = n;
  n = 1;
  while (n <= m && v[n].a != 0)
    n++;
  n--;

  int lim = 5;
  if (t > 0)
    lim = (int)log2(t) + 5;
  vector<vector<ll>> dp(n + 1, vector<ll>(lim + 1, t + 5));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 0;
    for (int j = 1; j <= min(lim, i); j++)
      dp[i][j] =
          min(dp[i - 1][j], (dp[i - 1][j - 1] + 1) * (v[i].a + 1) + v[i].b);
  }

  int ans = 0;
  for (int i = 0; i <= lim; i++) {
    int j = n + 1;
    while (j <= m && dp[n][i] + 1 + v[j].b <= t) {
      dp[n][i] += (1 + v[j].b);
      j++;
    }
    if (dp[n][i] <= t)
      ans = max(ans, i + j - n - 1);
  }
  cout << ans;

  return 0;
}
Problem p02750 (C++)

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

using namespace std;

const int maxi = 1e6 + 10;
const long long inf = 1e9 + 10;
int n;
long long t;
pair<long long, long long> a[maxi];
long long dp[41][maxi];

bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  //    if (x.first == 0 && y.first == 0) return x.second < y.second;
  //    if (x.first == 0) return 0;
  //    if (y.first == 0) return 1;
  if (!x.first && y.first)
    return x.second < y.second;
  return y.first * (x.second + 1) < x.first * (y.second + 1);
}
int main() {
  cin >> n >> t;

  for (int i = 1; i <= n; i++)
    scanf("%lld%lld", &a[i].first, &a[i].second);

  sort(a + 1, a + n + 1, cmp);

  for (int i = 0; i <= 40; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = inf;

  dp[0][0] = 0;

  int poz = n + 1;

  for (int i = 1; i <= n; i++) {
    if (!a[i].first) {
      poz = i;
      break;
    }

    for (int j = 0; j <= 40; j++)
      if (!j)
        dp[0][i] = 0;
      else {
        dp[j][i] = min(dp[j][i - 1],
                       (dp[j - 1][i - 1] + 1) * (a[i].first + 1) + a[i].second);
        dp[j][i] = min(dp[j][i], inf);
      }
  }

  int ans = 0;

  for (int k = 0; k <= 40; k++) {
    if (dp[k][poz - 1] > t)
      continue;

    long long val = dp[k][poz - 1];

    int cnt = k;

    for (int i = poz; i <= n; i++)
      if (val + a[i].second + 1 <= t) {
        val += a[i].second + 1;
        cnt++;
      }

    ans = max(cnt, ans);
  }

  printf("%d\n", ans);
}
// 1 3
// 0 3


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

using namespace std;

const int maxi = 1e6 + 10;
const long long inf = 1e9 + 10;
int n;
long long t;
pair<long long, long long> a[maxi];
long long dp[41][maxi];

bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  if (!x.first && !y.first)
    return x.second < y.second;
  return y.first * (x.second + 1) < x.first * (y.second + 1);
}
int main() {
  cin >> n >> t;

  for (int i = 1; i <= n; i++)
    scanf("%lld%lld", &a[i].first, &a[i].second);

  sort(a + 1, a + n + 1, cmp);

  for (int i = 0; i <= 40; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = inf;

  dp[0][0] = 0;

  int poz = n + 1;

  for (int i = 1; i <= n; i++) {
    if (!a[i].first) {
      poz = i;
      break;
    }

    for (int j = 0; j <= 40; j++)
      if (!j)
        dp[0][i] = 0;
      else {
        dp[j][i] = min(dp[j][i - 1],
                       (dp[j - 1][i - 1] + 1) * (a[i].first + 1) + a[i].second);
        dp[j][i] = min(dp[j][i], inf);
      }
  }

  int ans = 0;

  for (int k = 0; k <= 40; k++) {
    if (dp[k][poz - 1] > t)
      continue;

    long long val = dp[k][poz - 1];

    int cnt = k;

    for (int i = poz; i <= n; i++)
      if (val + a[i].second + 1 <= t) {
        val += a[i].second + 1;
        cnt++;
      }

    ans = max(cnt, ans);
  }

  printf("%d\n", ans);
}
// 1 3
// 0 3
Problem p02750 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define F first
#define S second
typedef pair<int, int> P;
const int N = 30 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
bool cmp(P a, P b) { return b.F * (a.S + 1) < a.F * (b.S + 1); }
vector<P> a;
vector<int> b;
int f[N];
signed main() {
  int n = read(), T = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    if (x)
      a.pb(make_pair(x, y));
    else
      b.pb(y + 1);
  }
  sort(a.begin(), a.end(), cmp);
  sort(b.begin(), b.end());
  for (int i = 1; i < b.size(); i++)
    b[i] += b[i - 1];
  for (int i = 1; i <= 30; i++)
    f[i] = T + 1;
  for (int i = 0; i < a.size(); i++)
    for (int j = 30; j; j--)
      f[j] = min(f[j], (f[j - 1] + 1) * (a[i].F + 1) + a[i].S);
  int ans = 0;
  for (int i = 0; i <= 30; i++)
    if (f[i] <= T)
      ans = max(ans,
                i + (b.empty() ? 0
                               : *(upper_bound(b.begin(), b.end(), T - f[i]) -
                                   *b.begin())));

  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define F first
#define S second
typedef pair<int, int> P;
const int N = 30 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
bool cmp(P a, P b) { return b.F * (a.S + 1) < a.F * (b.S + 1); }
vector<P> a;
vector<int> b;
int f[N];
signed main() {
  int n = read(), T = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    if (x)
      a.pb(make_pair(x, y));
    else
      b.pb(y + 1);
  }
  sort(a.begin(), a.end(), cmp);
  sort(b.begin(), b.end());
  for (int i = 1; i < b.size(); i++)
    b[i] += b[i - 1];
  for (int i = 1; i <= 30; i++)
    f[i] = T + 1;
  for (int i = 0; i < a.size(); i++)
    for (int j = 30; j; j--)
      f[j] = min(f[j], (f[j - 1] + 1) * (a[i].F + 1) + a[i].S);
  int ans = 0;
  for (int i = 0; i <= 30; i++)
    if (f[i] <= T)
      ans =
          max(ans, i + (b.empty() ? 0
                                  : upper_bound(b.begin(), b.end(), T - f[i]) -
                                        b.begin()));
  printf("%lld\n", ans);
  return 0;
}
Problem p02751 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template <class t> inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c))
    f |= c == '-', c = getchar();
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f)
    x = -x;
  return x;
}
template <class t, class... A> inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t> inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9)
      write(x / 10);
    putchar('0' + x % 10);
  }
}

const int N = 2005;
int n, m, ans[N][N];

void diq(int a, int b, int c, int d) {
  if (a == c || b == d)
    return;
  int x = a + b >> 1, y = c + d >> 1;
  ans[x][y] = 0;
  diq(a, b, x - 1, y - 1);
  diq(a, y + 1, x - 1, d);
  diq(x + 1, b, c, y - 1);
  diq(x + 1, y + 1, c, d);
}

signed main() {
  read(n, m);
  n = 1 << n;
  m = 1 << m;
  n--;
  m--;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      ans[i][j] = 1;
  diq(1, 1, n, m);
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= m; j++)
      write(ans[i][j]);
}

Fixed submission:
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template <class t> inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c))
    f |= c == '-', c = getchar();
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f)
    x = -x;
  return x;
}
template <class t, class... A> inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t> inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9)
      write(x / 10);
    putchar('0' + x % 10);
  }
}

const int N = 2005;
int n, m, ans[N][N];

void diq(int a, int b, int c, int d) {
  if (a == c || b == d)
    return;
  int x = a + c >> 1, y = b + d >> 1;
  ans[x][y] = 0;
  diq(a, b, x - 1, y - 1);
  diq(a, y + 1, x - 1, d);
  diq(x + 1, b, c, y - 1);
  diq(x + 1, y + 1, c, d);
}

signed main() {
  read(n, m);
  n = 1 << n;
  m = 1 << m;
  n--;
  m--;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      ans[i][j] = 1;
  diq(1, 1, n, m);
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= m; j++)
      write(ans[i][j]);
}
Problem p02753 (C++)

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  freopen(Task ".inp", "r", stdin);
  //  freopen(Task".out", "w", stdout);
  string s;
  cin >> s;
  map<char, int> m;
  for (auto c : s)
    m[c]++;
  if ((int)m.size() == 2)
    cout << "Yes";
  else
    cout << "No";
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //  freopen(Task".inp", "r", stdin);
  //  freopen(Task".out", "w", stdout);
  string s;
  cin >> s;
  map<char, int> m;
  for (auto c : s)
    m[c]++;
  if ((int)m.size() == 2)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02753 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  if (s.at(0) == s.at(1) && s.at(1) == s.at(2))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(1) && s.at(1) == s.at(2))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02753 (C++)

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

int main() {
  string S;
  char a = S.at(0);
  char b = S.at(1);
  char c = S.at(2);

  if (a == b && b == c) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

int main() {
  string S;
  cin >> S;
  char a = S.at(0);
  char b = S.at(1);
  char c = S.at(2);

  if (a == b && b == c) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p02753 (C++)

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

int main() {
  string s;
  cin >> s;
  if (s.at(1) == 'A' && s.at(2) == 'A' && s.at(3) == 'A') {
    cout << "No" << endl;
  } else if (s.at(1) == 'B' && s.at(2) == 'B' && s.at(3) == 'B') {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

int main() {
  string s;
  cin >> s;
  bool k = true;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == 'A') {
      continue;
    } else if (s.at(1) == 'B') {
      break;
    } else if (s.at(i) == 'B') {
      k = false;
      break;
    } else {
    }
  }
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == 'B') {
      continue;
    } else if (s.at(1) == 'A') {
      break;
    } else if (s.at(i) == 'A') {
      k = false;
      break;
    } else {
    }
  }
  if (k == true) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p02753 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define mod 1000000007
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'A') {
      a++;
    } else
      b++;
  }
  if (a == 3 || b == 3)
    cout << "No";
  else
    cout << "Yes";

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define mod 1000000007
int main() {
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "rt", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  fast string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'A') {
      a++;
    } else
      b++;
  }
  if (a == 3 || b == 3)
    cout << "No";
  else
    cout << "Yes";

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
Problem p02753 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S.at(1) == 'B' && S.at(2) == 'B' && S.at(3) == 'B')
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if ((S.at(0) == 'B' && S.at(1) == 'B' && S.at(2) == 'B') ||
      S.at(0) == 'A' && S.at(1) == 'A' && S.at(2) == 'A')
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02753 (C++)

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

using namespace std;

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

  if (S == "AAA" || S == "BBB") {
    cout << "No" << endl;
    return -1;
  }

  cout << "Yes" << endl;
}

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

using namespace std;

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

  if (S == "AAA" || S == "BBB") {
    cout << "No" << endl;
    exit(0);
  }

  cout << "Yes" << endl;
}
Problem p02753 (C++)

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

int main() {
  vector<string> s;
  for (int i = 0; i < 3; i++)
    cin >> s[i];
  if (s[0] == s[1] && s[1] == s[2] && s[2] == s[0])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

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

int main() {
  string s;
  for (int i = 0; i < 3; i++)
    cin >> s[i];
  if (s[0] == s[1] && s[1] == s[2] && s[2] == s[0])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
Problem p02753 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define db2(a, b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a)                                                                 \
  for (auto i : a)                                                             \
    cout << i << " ";                                                          \
  cout << endl
#define adb2(a)                                                                \
  for (auto i : a)                                                             \
    cout << i.first << " " << i.second << endl;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define N 100010
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

  fastIO;
  string s;
  cin >> s;

  if (s == "AAA" || s == "BBB")
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define db2(a, b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a)                                                                 \
  for (auto i : a)                                                             \
    cout << i << " ";                                                          \
  cout << endl
#define adb2(a)                                                                \
  for (auto i : a)                                                             \
    cout << i.first << " " << i.second << endl;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define N 100010
using namespace std;

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

  if (s == "AAA" || s == "BBB")
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02753 (C++)

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

int main() {
  int a, ans;
  string s;
  cin >> s;
  if (s.at(1) == s.at(2) && s.at(2) == s.at(3))
    cout << "No";
  else
    cout << "Yes";

  // cout << ans << "\n";
  return 0;
}


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

int main() {
  int a, ans;
  string s;
  cin >> s;
  if (s.at(1) == s.at(2) && s.at(0) == s.at(1))
    cout << "No";
  else
    cout << "Yes";

  // cout << ans << "\n";
  return 0;
}
Problem p02753 (C++)

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

int main() {
  string S;
  cin >> S;
  if (S.at(1) == S.at(2) && S.at(2) == S.at(3))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

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

int main() {
  string S;
  cin >> S;
  if (S.at(0) == S.at(1) && S.at(1) == S.at(2))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02753 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.at(1) == s.at(2) && s.at(2) == s.at(3) && s.at(1) == s.at(3)) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}