Problem p02692 (C++) — buggy submission, verdict: Runtime Error

// https://atcoder.jp/contests/abc166/tasks/abc166_f
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define pb push_back
#define loop(i, start, n) for (ll i = start; i < n; i++)
#define rloop(i, n, start) for (ll i = n; i >= start; i--)
#define mod 1000000007
#define endl "\\n"
#define INF 1e15
#define NEG_INF -1e15
#define pll pair<ll, ll>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
// template <typename T> using ordered_set =  tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>; using namespace __gnu_pbds;

int main() {
  IOS;
  ll n, a, b, c;
  cin >> n >> a >> b >> c;
  ll sum = a + b + c;
  string str[n + 2];
  str[n + 1] = "AB";
  loop(i, 1, n + 1) cin >> str[i];

  ll ok = 1;
  vector<char> vect;
  // assert(sum == 1);
  loop(i, 1, n + 1) {

    if (str[i] == "AB" && (str[i + 1] == "AC" || str[i + 1] == "AB")) {
      if (b - 1 >= 0 && (a != sum - 1 || b >= sum - 1))
        a++, b--, vect.pb('A');
      else
        a--, b++, vect.pb('B');
    }

    if (str[i] == "AB" && str[i + 1] == "BC")
      if (a - 1 >= 0 && (b != sum - 1 || a >= sum - 1))
        a--, b++, vect.pb('B');
      else
        a++, b--, vect.pb('A');

    if (str[i] == "BC" && (str[i + 1] == "AB" || str[i + 1] == "BC")) {
      if (c - 1 >= 0 && (b != sum - 1 || c >= sum - 1))
        c--, b++, vect.pb('B');
      else
        c++, b--, vect.pb('C');
    }

    if (str[i] == "BC" && str[i + 1] == "AC") {
      if (b - 1 >= 0 && (c != sum - 1 || b >= sum - 1))
        c++, b--, vect.pb('C');
      else
        c--, b++, vect.pb('B');
    }

    if (str[i] == "AC" && (str[i + 1] == "AC" || str[i + 1] == "AB")) {
      if (c - 1 >= 0 && (a != sum - 1 || c >= sum - 1))
        a++, c--, vect.pb('A');
      else
        a--, c++, vect.pb('C');
    }

    if (str[i] == "AC" && str[i + 1] == "BC") {
      if (a - 1 >= 0 && (c != sum - 1 || a >= sum - 1))
        a--, c++, vect.pb('C');
      else
        a++, c--, vect.pb('A');
    }

    debug(a, b, c);
    if (a < 0 || b < 0 || c < 0) {
      ok = 0;
      break;
    }
  }

  if (!ok)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (auto &node : vect)
      cout << node << endl;
  }
}

Error: -6
a0933220-3ebf-41d2-9cf3-968e92391534.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02692/C++/s073888913.cpp:61: int main(): Assertion `sum == 1' failed.


Fixed submission:

// https://atcoder.jp/contests/abc166/tasks/abc166_f
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define pb push_back
#define loop(i, start, n) for (ll i = start; i < n; i++)
#define rloop(i, n, start) for (ll i = n; i >= start; i--)
#define mod 1000000007
#define endl "\\n"
#define INF 1e15
#define NEG_INF -1e15
#define pll pair<ll, ll>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
// template <typename T> using ordered_set =  tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>; using namespace __gnu_pbds;

int main() {
  IOS;
  ll n, a, b, c;
  cin >> n >> a >> b >> c;
  ll sum = a + b + c;
  string str[n + 2];
  str[n + 1] = "AB";
  loop(i, 1, n + 1) cin >> str[i];

  ll ok = 1;
  vector<char> vect;
  assert(sum == 1);
  loop(i, 1, n + 1) {

    if (str[i] == "AB" && (str[i + 1] == "AC" || str[i] == "AB")) {
      if (b - 1 >= 0 && (a != sum - 1 || b == sum - 1))
        a++, b--, vect.pb('A');
      else
        a--, b++, vect.pb('B');
    }

    if (str[i] == "AB" && str[i + 1] == "BC")
      if (a - 1 >= 0 && (b != sum - 1 || a == sum - 1))
        a--, b++, vect.pb('B');
      else
        a++, b--, vect.pb('A');

    if (str[i] == "BC" && (str[i] == "AB" || str[i] == "BC")) {
      if (c - 1 >= 0 && (b != sum - 1 || c == sum - 1))
        c--, b++, vect.pb('B');
      else
        c++, b--, vect.pb('C');
    }

    if (str[i] == "BC" && str[i] == "AC") {
      if (b - 1 >= 0 && (c != sum - 1 || b == sum - 1))
        c++, b--, vect.pb('C');
      else
        c--, b++, vect.pb('B');
    }

    if (str[i] == "AC" && (str[i] == "AC" || str[i] == "AB")) {
      if (c - 1 >= 0 && (a != sum - 1 || c == sum - 1))
        a++, c--, vect.pb('A');
      else
        a--, c++, vect.pb('C');
    }

    if (str[i] == "AC" && str[i] == "BC") {
      if (a - 1 >= 0 && (c != sum - 1 || a == sum - 1))
        a--, c++, vect.pb('C');
      else
        a++, c--, vect.pb('A');
    }

    if (a < 0 || b < 0 || c < 0) {
      ok = 0;
      break;
    }
  }

  if (!ok)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (auto &node : vect)
      cout << node << endl;
  }
}