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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 200005;
const int INF = 1001001001;          // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void) {

  IN(N);
  vl A(N);
  REP(i, N + 1) { IN(A[i]); }
  map<ll, ll> B;
  map<ll, ll> C;
  REP(i, N) {
    B[A[i] + i + 1];
    B[A[i] + i + 1]++;
    C[i + 1 - A[i]];
    C[i + 1 - A[i]]++;
  }

  for (pair<ll, ll> p : B) {
    ret += p.second * C[p.first];
  }

  PRINT(ret);
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001;          // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;
vector<string> sl;
ll A, B, C;
vector<char> cl;

void call(char p, char n) {
  cl.pb(p);
  if (p == 'A')
    A++;
  if (p == 'B')
    B++;
  if (p == 'C')
    C++;
  if (n == 'A')
    A--;
  if (n == 'B')
    B--;
  if (n == 'C')
    C--;
}

void eq1(char c1, char c2, ll next_i) {
  string next = sl[next_i];

  if (c1 == 'A' && c2 == 'B') {
    if (next == "AC") {
      call('A', 'B');
    } else {
      call('B', 'A');
    }
  } else if (c1 == 'B' && c2 == 'C') {
    if (next == "AB") {
      call('B', 'C');
    } else {
      call('C', 'B');
    }
  } else if (c1 == 'A' && c2 == 'C') {
    if (next == "BC") {
      call('C', 'A');
    } else {
      call('A', 'C');
    }
  }
}

int main(void) {
  IN(N);
  IN(A);
  IN(B);
  IN(C);
  REP(i, N) {
    IN(s);
    sl.pb(s);
  }
  REP(i, N) {
    s = sl[i];
    if (s == "AB") {
      if (A == 0 && B == 0) {
        PRINT("No");
        return 0;
      }
      if (A == 1 && B == 1) {
        eq1('A', 'B', i + 1);
      } else if (A == 0 || A < B) {
        call('A', 'B');
      } else if (B == 0 || A >= B) {
        call('B', 'A');
      }
    } else if (s == "BC") {
      if (B == 0 && C == 0) {
        PRINT("No");
        return 0;
      }
      if (B == 1 && C == 1) {
        eq1('B', 'C', i + 1);
      } else if (B == 0 || B < C) {
        call('B', 'C');
      } else if (C == 0 || B >= C) {
        call('C', 'B');
      }
    } else if (s == "AC") {
      if (A == 0 && C == 0) {
        PRINT("No");
        return 0;
      }
      if (A == 1 && C == 1) {
        eq1('A', 'C', i + 1);
      } else if (A == 0 || A < C) {
        call('A', 'C');
      } else if (C == 0 || A >= C) {
        call('C', 'A');
      }
    }
  }
  PRINT("Yes");
  REP(i, N) { PRINT(cl[i]); }
}