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

#define _CRT_SECURE_NO_WARNINGS 1
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF ((int)(1 << 25))
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, n) REP(i, n)
#define FORI(i, k, n) for (int i = k; i < (int)n; i++)
#define TORAD 2.0 * M_PI / 360.0
#define INT(x)                                                                 \\
  int x;                                                                       \\
  cin >> x;
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
#define DEBUG(x) cout << #x << ":" << x << endl;
#define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
template <class T> void debug(T a) {
  for (auto i : a)
    cout << i << endl;
}

int main() {
  while (1) {
    int n, x, y;
    cin >> n >> x >> y;
    if (n + x + y == 0)
      break;
    vector<pii> a(1, pii(0, 0));
    a.push_back(pii(y, x));
    FOR(i, n) {
      int p, s;
      cin >> p >> s;
      pii now = a[p];
      a.erase(a.begin() + p);
      s %= (now.first + now.second) * 2;
      pii A, B;
      A = B = now;
      if (s <= now.second) {
        A.second = s;
        B.second = now.second - s;

      } else if (s <= now.first + now.second) {
        A.first = s - now.second;
        B.first = now.first - A.first;
      } else if (s <= now.first + 2 * now.second) {
        B.second = s - now.first - now.second;
        A.second = now.second - B.second;
      } else {
        B.first = s - now.second * 2 - now.first;
        A.first = now.first - B.first;
      }
      if (A.first * A.second >= B.first * B.second) {
        a.push_back(B);
        a.push_back(A);
      } else {
        a.push_back(A);
        a.push_back(B);
      }
    }
    vector<int> ans;
    FORI(i, 1, a.size()) {
      int area = a[i].first * a[i].second;
      ans.push_back(area);
    }
    sort(ALL(ans));
    FOR(i, ans.size()) {
      if (i)
        cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORI(i, k, n) for (int i = k; i < (int)n; i++)
#define ALL(x) (x).begin(), (x).end()
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  while (1) {
    int n, x, y;
    cin >> n >> x >> y;
    if (n + x + y == 0)
      break;
    vector<pii> a(1, pii(0, 0));
    a.push_back(pii(y, x));
    FOR(i, n) {
      int p, s;
      cin >> p >> s;
      pii now = a[p];
      a.erase(a.begin() + p);
      s %= (now.first + now.second) * 2;
      pii A, B;
      A = B = now;
      if (s <= now.second) {
        A.second = s;
        B.second = now.second - s;

      } else if (s <= now.first + now.second) {
        A.first = s - now.second;
        B.first = now.first - A.first;
      } else if (s <= 2 * now.first + now.second) {
        B.second = s - now.first - now.second;
        A.second = now.second - B.second;
      } else {
        B.first = s - now.second * 2 - now.first;
        A.first = now.first - B.first;
      }
      if (A.first * A.second >= B.first * B.second) {
        a.push_back(B);
        a.push_back(A);
      } else {
        a.push_back(A);
        a.push_back(B);
      }
    }
    vector<int> ans;
    FORI(i, 1, a.size()) {
      int area = a[i].first * a[i].second;
      ans.push_back(area);
    }
    sort(ALL(ans));
    FOR(i, ans.size()) {
      if (i)
        cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
}