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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\\n"

template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
  int len = d.size();
  rep(i, len) {
    s << d[i];
    if (i < len - 1)
      s << " ";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
  int len = d.size();
  rep(i, len) { s << d[i] << endl; }
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
  s << "{" << endl;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << " " << (*itr).first << " : " << (*itr).second << endl;
  }
  s << "}" << endl;
  return s;
}

const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<ll> g = {a, b, c};
  sort(begin(g), end(g));
  vector<string> s(n);
  rep(i, n) { cin >> s[i]; }
  auto no = []() {
    cout << "No" << endl;
    return 0;
  };
  vector<char> ans(n);
  bool flag = true;
  if (g[0] == 0 && g[1] == 0) {
    if (g[2] == 0) {
      no();
      return 0;
    }
    if (a == 0 && b == 0 && s[0] == "AB") {
      no();
      return 0;
    }
    if (b == 0 && c == 0 && s[0] == "BC") {
      no();
      return 0;
    }
    if (a == 0 && c == 0 && s[0] == "AC") {
      no();
      return 0;
    }
    if (g[2] == 1) {
      rep(i, n) {
        if (s[i] == "AB") {
          if (a == 0 && b == 0) {
            no();
            return 0;
          } else {
            if (a > b) {
              ans[i] = 'B';
              a--;
              b++;
            } else {
              ans[i] = 'A';
              a++;
              b--;
            }
          }
        }
        if (s[i] == "BC") {
          if (c == 0 && b == 0) {
            no();
            return 0;
          } else {
            if (c > b) {
              ans[i] = 'B';
              c--;
              b++;
            } else {
              ans[i] = 'C';
              c++;
              b--;
            }
          }
        }
        if (s[i] == "AC") {
          if (a == 0 && c == 0) {
            no();
            return 0;
          } else {
            if (a > c) {
              ans[i] = 'C';
              a--;
              c++;
            } else {
              ans[i] = 'A';
              a++;
              c--;
            }
          }
        }
      }
      cout << "Yes" << endl;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  rep(i, n) {
    if (s[i] == "AB") {
      if (a == 0 && b == 0) {
        cout << "No" << endl;
        return 0;
      }
      if (a == 1 && b == 1) {
        if (i + 1 < n && s[i + 1] == "BC") {
          cout << 'B' << endl;
          b++;
          a--;
          continue;
        }
        if (i + 1 < n && s[i + 1] == "AC") {
          cout << 'A' << endl;
          a++;
          b--;
          continue;
        }
      }
      if (a > b) {
        cout << 'B' << endl;
        a--, b++;
      } else {
        cout << 'A' << endl;
        a++, b--;
      }
    }
    if (s[i] == "BC") {
      if (b == 0 && c == 0) {
        cout << "No" << endl;
        return 0;
      }
      if (c == 1 && b == 1) {
        if (i + 1 < n && s[i + 1] == "AC") {
          cout << 'C' << endl;
          c++;
          b--;
          continue;
        }
        if (i + 1 < n && s[i + 1] == "AB") {
          cout << 'B' << endl;
          b++;
          c--;
          continue;
        }
      }
      if (b > c) {
        cout << 'C' << endl;
        b--, c++;
      } else {
        cout << 'B' << endl;
        b++, c--;
      }
    }
    if (s[i] == "AC") {
      if (a == 0 && c == 0) {
        cout << "No" << endl;
        return 0;
      }
      if (a == 1 && c == 1) {
        if (i + 1 < n && s[i + 1] == "BC") {
          cout << 'C' << endl;
          c++;
          a--;
          continue;
        }
        if (i + 1 < n && s[i + 1] == "AB") {
          cout << 'A' << endl;
          a++;
          c--;
          continue;
        }
      }
      if (a > c) {
        cout << 'C' << endl;
        a--, c++;
      } else {
        cout << 'A' << endl;
        a++, c--;
      }
    }
  }
}


Error: -6
3a5b1432-b1ad-4f82-90d2-61c6501c66f8.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02692/C++/s703162029.cpp:44: int main(): Assertion `g[0]==0 && g[1]==0' failed.


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\\n"

template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
  int len = d.size();
  rep(i, len) {
    s << d[i];
    if (i < len - 1)
      s << " ";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
  int len = d.size();
  rep(i, len) { s << d[i] << endl; }
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
  s << "{" << endl;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << " " << (*itr).first << " : " << (*itr).second << endl;
  }
  s << "}" << endl;
  return s;
}

const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<ll> g = {a, b, c};
  sort(begin(g), end(g));
  vector<string> s(n);
  rep(i, n) { cin >> s[i]; }
  auto no = []() {
    cout << "No" << endl;
    return 0;
  };
  vector<char> ans(n);
  bool flag = true;
  assert(g[0] == 0 && g[1] == 0);
  if (g[0] == 0 && g[1] == 0) {
    if (g[2] == 0) {
      no();
      return 0;
    }
    if (a == 0 && b == 0 && s[0] == "AB") {
      no();
      return 0;
    }
    if (b == 0 && c == 0 && s[0] == "BC") {
      no();
      return 0;
    }
    if (a == 0 && c == 0 && s[0] == "AC") {
      no();
      return 0;
    }
    rep(i, n) {
      if (s[i] == "AB") {
        if (a == 0 && b == 0) {
          no();
          return 0;
        } else {
          if (a > b) {
            ans[i] = 'B';
            a--;
            b++;
          } else {
            ans[i] = 'A';
            a++;
            b--;
          }
        }
      }
      if (s[i] == "BC") {
        if (c == 0 && b == 0) {
          no();
          return 0;
        } else {
          if (c > b) {
            ans[i] = 'B';
            c--;
            b++;
          } else {
            ans[i] = 'C';
            c++;
            b--;
          }
        }
      }
      if (s[i] == "AC") {
        if (a == 0 && c == 0) {
          no();
          return 0;
        } else {
          if (a > c) {
            ans[i] = 'C';
            a--;
            c++;
          } else {
            ans[i] = 'A';
            a++;
            c--;
          }
        }
      }
    }
    cout << "Yes" << endl;
    cout << ans << endl;
    return 0;
  }
  cout << "Yes" << endl;
  rep(i, n) {
    if (s[i] == "AB") {
      if (a == 0 && b == 0) {
        cout << "No" << endl;
        return 0;
      }
      if (a > b) {
        cout << 'B' << endl;
        a--, b++;
      } else {
        cout << 'A' << endl;
        a++, b--;
      }
    }
    if (s[i] == "BC") {
      if (b == 0 && c == 0) {
        cout << "No" << endl;
        return 0;
      }
      if (b > c) {
        cout << 'C' << endl;
        b--, c++;
      } else {
        cout << 'B' << endl;
        b++, c--;
      }
    }
    if (s[i] == "AC") {
      if (a == 0 && c == 0) {
        cout << "No" << endl;
        return 0;
      }
      if (a > c) {
        cout << 'C' << endl;
        a--, c++;
      } else {
        cout << 'A' << endl;
        a++, c--;
      }
    }
  }
}