alexjercan/bugnet huggingface dataset:
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define DEBUG(x) cout << #x << ": " << (x) << '\\n'
#define DEBUG_VEC(v)                                                           \\
  cout << #v << ":";                                                           \\
  REP(i, v.size()) cout << ' ' << v[i];                                        \\
  cout << '\\n'
#define ALL(a) (a).begin(), (a).end()

template <typename T> inline void CHMAX(T &a, const T b) {
  if (a < b)
    a = b;
}
template <typename T> inline void CHMIN(T &a, const T b) {
  if (a > b)
    a = b;
}

constexpr ll MOD = 1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

const double EPS = 1e-9;
#define EQ0(x) (abs((x)) < EPS)
#define EQ(a, b) (abs((a) - (b)) < EPS)

int cnt[425252];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll a[252521], b[252521];
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    b[i] = i - a[i];
    if (0 <= b[i] && b[i] <= n * 2) {
      ++cnt[b[i]];
    }
  }
  ll ans = 0;
  REP(i, n) {
    if (a[i] < n) {
      ans += cnt[a[i] + i];
    }
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define DEBUG(x) cout << #x << ": " << (x) << '\\n'
#define DEBUG_VEC(v)                                                           \\
  cout << #v << ":";                                                           \\
  REP(i, v.size()) cout << ' ' << v[i];                                        \\
  cout << '\\n'
#define ALL(a) (a).begin(), (a).end()

template <typename T> inline void CHMAX(T &a, const T b) {
  if (a < b)
    a = b;
}
template <typename T> inline void CHMIN(T &a, const T b) {
  if (a > b)
    a = b;
}

constexpr ll MOD = 1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

const double EPS = 1e-9;
#define EQ0(x) (abs((x)) < EPS)
#define EQ(a, b) (abs((a) - (b)) < EPS)

int cnt[425252];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll a[252521], b[252521];
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    b[i] = i - a[i];
    if (0 <= b[i] && b[i] <= n * 2) {
      ++cnt[b[i]];
    }
  }
  ll ans = 0;
  REP(i, n) { ans += cnt[a[i] + i]; }
  cout << ans << '\\n';
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  map<long long, int> A_pair;
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
    A_pair[i + A.at(i)]++;
  }
  long long count = 0;
  for (long long j = 0; j < N; j++) {
    auto po = A_pair[j - A.at(j)];
    count += po;
  }
  cout << count;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  multimap<int, int> A_pair_1;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A_pair_1.emplace(i + A.at(i), i);
  }
  int count = 0;
  for (int j = 0; j < N; j++) {
    if (j - A.at(j) >= 0) {
      auto po = A_pair_1.count(j - A.at(j));
      count += po;
    }
  }
  cout << count;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long nAns = 0;
  int N;
  cin >> N;
  map<int, int> B; // j -A[j]
  map<int, int> C; // i +A[i]
  for (int n = 0; n < N; ++n) {
    int m = 0;
    cin >> m;
    nAns += B[n + m] + C[n - m];
    ++B[n - m];
    ++C[n + m];
  }
  cout << nAns << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int n = 0; n < N; ++n) {
    cin >> A[n];
  }
  int nAns = 0;
  for (int n = 0; n < N; ++n) {
    for (int m = n + 1; m < N; ++m) {
      if ((m - n) == (A[m] + A[n])) {
        ++nAns;
      }
    }
  }
  cout << nAns << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  const int MAXN = 2e5;
  int n, h[MAXN];
  cin >> n;
  map<int, int> cnt;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i - 1];
    ++cnt[i - h[i - 1]];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    --cnt[i - h[i - 1]];
    ans += cnt[h[i - 1] + i];
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  const int MAXN = 1e5;
  int n, h[MAXN];
  cin >> n;
  map<int, int> cnt;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i - 1];
    ++cnt[i - h[i - 1]];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    --cnt[i - h[i - 1]];
    ans += cnt[h[i - 1] + i];
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  vector<vector<int>> S(300000);
  rep(i, N) {
    int x = i - A[i];
    if (x < 0)
      continue;
    if (x >= 300000)
      continue;
    S[x].push_back(i);
  }
  rep(i, 300000) sort(S[i].begin(), S[i].end());
  long long ans = 0;
  rep(i, N) {
    int x = i + A[i];
    if (x < 0)
      continue;
    if (x > 300000)
      continue;
    int left = -1;
    int right = (int)S[x].size();
    while (right - left > 1) {
      int mid = (right + left) / 2;
      if (S[x][mid] <= i)
        left = mid;
      else
        right = mid;
    }
    ans += (int)S[x].size() - right;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  vector<vector<int>> S(300000);
  rep(i, N) {
    int x = i - A[i];
    if (x < 0)
      continue;
    if (x >= 300000)
      continue;
    S[x].push_back(i);
  }
  rep(i, 300000) sort(S[i].begin(), S[i].end());
  long long ans = 0;
  rep(i, N) {
    int x = i + A[i];
    int left = -1;
    int right = (int)S[x].size();
    while (right - left > 1) {
      int mid = (right + left) / 2;
      if (S[x][mid] <= i)
        left = mid;
      else
        right = mid;
    }
    ans += (int)S[x].size() - right;
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
/*
int main(){
  int n; scanf("%d",&n);
  long long a[2 * 100000];
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      if(j - i == a[i] + a[j])ans++;
    }

  }
  printf("%lld\\n", ans);
}
*/

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &&i : a) {
    cin >> i;
  }
  vector<int> L(n);
  vector<int> R(n);
  for (int i = 0; i < n; i++) {
    L.at(i) = i + a.at(i);
    R.at(i) = i - a.at(i);
  }
  long long count = 0;
  map<int, int> mp;
  for (auto &&i : L) {
    if (mp.count(i)) {
      mp[i]++;
    } else {
      mp[i] = 1;
    }
  }
  for (auto &&i : R) {
    count += mp[i];
  }

  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/*
int main(){
  int n; scanf("%d",&n);
  long long a[2 * 100000];
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      if(j - i == a[i] + a[j])ans++;
    }

  }
  printf("%lld\\n", ans);
}
*/

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &&i : a) {
    cin >> i;
  }
  vector<int> L(n);
  vector<int> R(n);
  for (int i = 0; i < n; i++) {
    L.at(i) = i + a.at(i);
    R.at(i) = i - a.at(i);
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (L.at(i) == R.at(j))
        count++;
    }
  }
  cout << count << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int vf[200001], a[200000];
int main() {
  int n, i;
  cin >> n;
  long long rez = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (i >= a[i])
      rez += (long long)vf[i - a[i]];
    if (i + a[i] <= n)
      vf[i + a[i]]++;
  }
  cout << rez;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int v[200000];
int main() {
  int n, i, j;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> v[i];
  int ans = 0;
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++)
      if (j - i == v[i] + v[j])
        ans++;
  cout << ans;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>

int main() {
  int64_t N;
  std::map<int64_t, int64_t> test_map;
  std::cin >> N;
  int64_t count = 0;

  for (int64_t i = 0; i < N; i++) {
    int64_t height;
    std::cin >> height;
    // i - j = height[i] + height[j]
    // i - height[i] = j + height[j]
    count += test_map[i - height];
    test_map[i + height]++;
  }
  std::cout << count << std::endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  int N;
  std::vector<int> height_vec;
  std::cin >> N;
  int A_max = 1;
  int A_min = 1000000000;
  height_vec.resize(N);
  int count = 0;

  for (int i = 0; i < N; i++) {
    int height;
    std::cin >> height;
    height_vec[i] = height;
    if (A_max < height) {
      A_max = height;
    }
    if (A_min > height) {
      A_min = height;
    }
    if (height + A_min > i) {
      continue;
    }
    int j_min = std::max(0, i - (height + A_max));
    int j_max = i - (height + A_min);
    for (int j = j_min; j <= j_max; j++) {
      if ((i - j) == (height + height_vec[j])) {
        count++;
      }
    }
  }
  std::cout << count << std::endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  vector<ll> r(n);
  map<int, int> mp;
  ll ans = 0;
  rep(i, n) {
    int a;
    cin >> a;
    ans += mp[i - a];
    mp[i + a]++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) { cin >> a.at(i); }
  int cnt = 0;
  for (int x = 0; x < n; x++) {
    for (int i = x + 1; i < n; i++) {
      if ((i - x) == (a.at(i) + a.at(x))) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, A, B, C;
  cin >> n >> A >> B >> C;
  map<char, int> mp;
  mp['A'] = A;
  mp['B'] = B;
  mp['C'] = C;
  vector<char> ans(n);
  vector<string> sn(n);
  rep(i, n) cin >> sn[i];
  rep(i, n) {
    string s = sn[i];
    char s0 = s[0];
    char s1 = s[1];

    if (mp[s0] == 0 && mp[s1] == 0) {
      cout << "No" << endl;
      return 0;
      ;
    } else if (mp[s0] == 0) {
      mp[s0]++;
      mp[s1]--;
      ans[i] = s0;
    } else if (mp[s1] == 0) {
      mp[s1]++;
      mp[s0]--;
      ans[i] = s1;
    } else if (i == n - 1) {
      ans[i] = s0;
    } else if (sn[i + 1][0] == s0 || sn[i + 1][1] == s0) {
      mp[s0]++;
      mp[s1]--;
      ans[i] = s0;
    } else {
      mp[s0]--;
      mp[s1]++;
      ans[i] = s1;
    }
  }
  cout << "Yes" << endl;
  rep(i, n) cout << ans[i] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
int n, a, b, c;
bool flag;
void check(map<char, int> mp) {
  if (mp['A'] < 0 || mp['B'] < 0 || mp['C'] < 0) {
    // cout << "No" << endl;
    flag = true;
    return;
  }
}

int main() {
  cin >> n >> a >> b >> c;
  map<char, int> mp;
  vector<char> ans(n);
  mp['A'] = a;
  mp['B'] = b;
  mp['C'] = c;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  if (a + b + c == 0) {
    cout << "No" << endl;
    return 0;
  }
  string next;
  rep(i, n) {
    string t = s[i];
    next = s[i + 1];
    if (t == next) { // 完全に一致
      if (mp[t[0]] > mp[t[1]]) {
        mp[t[0]]--;
        mp[t[1]]++;
        ans[i] = t[1];
        check(mp);
      } else {
        mp[t[0]]++;
        mp[t[1]]--;
        ans[i] = t[0];
        check(mp);
      }
    } else if (t[0] == next[0]) { // A被り
      mp[t[0]]++;
      mp[t[1]]--;
      ans[i] = t[0];
      check(mp);
    } else if (t[1] == next[1]) { // C被り
      mp[t[1]]++;
      mp[t[0]]--;
      ans[i] = t[1];
      check(mp);
    } else { // B被り
      if (t[0] == 'B') {
        mp[t[0]]++;
        mp[t[1]]--;
        ans[i] = t[0];
        check(mp);
      } else {
        mp[t[0]]--;
        mp[t[1]]++;
        ans[i] = t[1];
        check(mp);
      }
    }
  }
  if (flag)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    rep(i, n) cout << ans[i] << endl;
  }
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S(N);
  for (auto &e : S)
    cin >> e;

  string ans = "", tmp = "";
  auto dfs = [&](auto &&dfs, int i, int a, int b, int c) -> bool {
    if (!ans.empty())
      return true;
    if (a < 0 or b < 0 or c < 0)
      return false;
    if (i == N) {
      ans = tmp;
      return true;
    }
    bool res = false;
    if (S[i] == "AB") {
      tmp += 'A';
      res |= dfs(dfs, i + 1, a + 1, b - 1, c);
      tmp[i] = 'B';
      res |= dfs(dfs, i + 1, a - 1, b + 1, c);
      tmp.pop_back();
    } else if (S[i] == "BC") {
      tmp += 'B';
      res |= dfs(dfs, i + 1, a, b + 1, c - 1);
      tmp[i] = 'C';
      res |= dfs(dfs, i + 1, a, b - 1, c + 1);
      tmp.pop_back();
    } else if (S[i] == "AC") {
      tmp += 'A';
      res |= dfs(dfs, i + 1, a + 1, b, c - 1);
      tmp[i] = 'C';
      res |= dfs(dfs, i + 1, a - 1, b, c + 1);
      tmp.pop_back();
    }
    return res;
  };

  if (dfs(dfs, 0, A, B, C)) {
    cout << "Yes" << '\\n';
    for (auto &e : ans)
      cout << e << '\\n';
  } else {
    cout << "No" << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S(N);
  for (auto &e : S)
    cin >> e;

  string ans = "", tmp = "";
  auto dfs = [&](auto &&dfs, int i, int a, int b, int c) -> bool {
    if (a < 0 or b < 0 or c < 0)
      return false;
    if (i == N) {
      ans = tmp;
      return true;
    }
    bool res = false;
    if (S[i] == "AB") {
      tmp += 'A';
      res |= dfs(dfs, i + 1, a + 1, b - 1, c);
      tmp[i] = 'B';
      res |= dfs(dfs, i + 1, a - 1, b + 1, c);
      tmp.pop_back();
    } else if (S[i] == "BC") {
      tmp += 'B';
      res |= dfs(dfs, i + 1, a, b + 1, c - 1);
      tmp[i] = 'C';
      res |= dfs(dfs, i + 1, a, b - 1, c + 1);
      tmp.pop_back();
    } else if (S[i] == "AC") {
      tmp += 'A';
      res |= dfs(dfs, i + 1, a + 1, b, c - 1);
      tmp[i] = 'C';
      res |= dfs(dfs, i + 1, a - 1, b, c + 1);
      tmp.pop_back();
    }
    return res;
  };

  if (dfs(dfs, 0, A, B, C)) {
    cout << "Yes" << '\\n';
    for (auto &e : ans)
      cout << e << '\\n';
  } else {
    cout << "No" << '\\n';
  }
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
// lint mod = 998244353;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void app() {
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];

  vector<string> sv(n);
  rep(i, n) { cin >> sv[i]; }

  string ans;
  rep(i, n) {
    string s = sv[i];
    int c = s[0] - 'A';
    int d = s[1] - 'A';

    if (a[c] < a[d]) {
      ans += 'A' + c;
      a[c]++;
      a[d]--;
    } else if (a[c] > a[d]) {
      ans += 'A' + d;
      a[d]++;
      a[c]--;
    } else if (i == n - 1 || sv[i] == sv[i + 1]) {
      ans += 'A' + c;
      a[c]++;
      a[d]--;
    } else {
      string sn = sv[i + 1];
      int e = sn[0] - 'A';
      int f = sn[1] - 'A';
      if (c == e || c == f) {
        ans += 'A' + c;
        a[c]++;
        a[d]--;
      } else {
        ans += 'A' + d;
        a[d]++;
        a[c]--;
      }
    }

    if (a[0] < 0 || a[1] < 0 || a[2] < 0) {
      cout << "No" << endl;
      return;
    }
  }

  cout << "Yes" << endl;
  rep(i, n) { cout << ans[i] << endl; }
}

int main() {
  app();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
// lint mod = 998244353;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void app() {
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];

  vector<string> sv(n);
  rep(i, n) { cin >> sv[i]; }

  string ans;
  rep(i, n) {
    string s = sv[i];
    int c = s[0] - 'A';
    int d = s[1] - 'A';

    if (a[c] < a[d]) {
      ans += 'A' + c;
      a[c]++;
      a[d]--;
    } else if (a[c] > a[d]) {
      ans += 'A' + d;
      a[d]++;
      a[c]--;
    } else if (i == n - 1 || s[i] == s[i + 1]) {
      ans += 'A' + c;
      a[c]++;
      a[d]--;
    } else {
      string sn = sv[i + 1];
      int e = sn[0] - 'A';
      int f = sn[1] - 'A';
      if (c == e || c == f) {
        ans += 'A' + c;
        a[c]++;
        a[d]--;
      } else {
        ans += 'A' + d;
        a[d]++;
        a[c]--;
      }
    }

    if (a[0] < 0 || a[1] < 0 || a[2] < 0) {
      cout << "No" << endl;
      return;
    }
  }

  cout << "Yes" << endl;
  rep(i, n) { cout << ans[i] << endl; }
}

int main() {
  app();
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(3);
  rep(i, 3) cin >> d[i];
  vector<P> q;
  rep(i, n) {
    string s;
    cin >> s;
    int a = 0, b = 1;
    if (s == "AB")
      a = 0, b = 1;
    if (s == "AC")
      a = 0, b = 2;
    if (s == "BC")
      a = 1, b = 2;
    q.emplace_back(a, b);
  }
  string ans;
  auto add = [&](int a, int b) {
    d[a]++;
    d[b]--;
    ans += 'A' + a;
  };
  q.emplace_back(0, 1);
  rep(i, n) {
    int a = q[i].first;
    int b = q[i].second;
    if (!d[a] && !d[b]) {
      cout << "No" << endl;
      return 0;
    }
    if (!d[a]) {
      add(a, b);
    } else if (!d[b]) {
      add(b, a);
    } else {
      int na = q[i + 1].first;
      int nb = q[i + 1].second;
      if (a == na || a == nb) {
        add(a, b);
      } else {
        add(b, a);
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, n) { cout << ans[i] << endl; }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(3);
  rep(i, 3) cin >> d[i];
  vector<P> q;
  rep(i, n) {
    string s;
    cin >> s;
    int a = 0, b = 1;
    if (s == "AB")
      a = 0, b = 1;
    if (s == "AC")
      a = 0, b = 2;
    if (s == "BC")
      a = 1, b = 2;
    q.emplace_back(a, b);
  }
  string ans;
  auto add = [&](int a, int b) {
    d[a]++;
    d[b]--;
    ans += "A" + a;
  };
  q.emplace_back(0, 1);
  rep(i, n) {
    int a = q[i].first;
    int b = q[i].second;
    if (!d[a] && !d[b]) {
      cout << "Np" << endl;
      return 0;
    }
    if (!d[a]) {
      add(a, b);
    } else {
      int na = q[i + 1].first;
      int nb = q[i + 1].second;
      if (a == na || a == nb) {
        add(a, b);
      } else {
        add(b, a);
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, n) { cout << ans[i] << endl; }
  return 0;
}