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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
struct edge {
  int to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) {
  return (x >= 0 && y >= 0 && x < h && y < w);
}
int place(int x, int y, int w) { return w * x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vector<P> v;
int main() {
  int n, w, d;
  while (cin >> n >> w >> d, w) {
    v.clear();
    v.push_back(P(w, d));
    REP(i, n) {
      int p, s;
      cin >> p >> s;
      p--;
      int x = v[p].first, y = v[p].second;
      s %= 2 * (x + y);
      if (s < x) {
        P a(s, y), b(x - s, y);
        if (a > b)
          swap(a, b);
        v.erase(v.begin() + p);
        v.push_back(a);
        v.push_back(b);
      } else if (s < x + y) {
        s = s - x;
        P a(x, s), b(x, y - s);
        if (a > b)
          swap(a, b);
        v.erase(v.begin() + p);
        v.push_back(a);
        v.push_back(b);
      } else if (s < 2 * x + y) {
        s = s - x - y;
        P a(s, y), b(x - s, y);
        if (a > b)
          swap(a, b);
        v.erase(v.begin() + p);
        v.push_back(a);
        v.push_back(b);
      } else {
        s = s - 2 * x - y;
        P a(x, s), b(x, y - s);
        if (a > b)
          swap(a, b);
        v.erase(v.begin() + p);
        v.push_back(a);
        v.push_back(b);
      }
    }
    vi ans;
    REP(i, v.size()) { ans.push_back(v[i].first * v[i].second); }
    sort(ALL(ans));
    REP(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? "\\n" : " ");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
struct edge {
  int to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) {
  return (x >= 0 && y >= 0 && x < h && y < w);
}
int place(int x, int y, int w) { return w * x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vector<P> v;
int main() {
  int n, w, d;
  while (cin >> n >> w >> d, w) {
    v.clear();
    v.push_back(P(w, d));
    REP(i, n) {
      int p, s;
      cin >> p >> s;
      p--;
      int x = v[p].first, y = v[p].second;
      s %= 2 * (x + y);
      if (s < x) {
        P a(s, y), b(x - s, y);
        if (a > b)
          swap(a, b);
        v[p] = a;
        v.push_back(b);
      } else if (s < x + y) {
        s = s - x;
        P a(x, s), b(x, y - s);
        if (a > b)
          swap(a, b);
        v[p] = a;
        v.push_back(b);
      } else if (s < 2 * x + y) {
        s = s - x - y;
        P a(s, y), b(x - s, y);
        if (a > b)
          swap(a, b);
        v[p] = a;
        v.push_back(b);
      } else {
        s = s - 2 * x - y;
        P a(x, s), b(x, y - s);
        if (a > b)
          swap(a, b);
        v[p] = a;
        v.push_back(b);
      }
    }
    vi ans;
    REP(i, v.size()) { ans.push_back(v[i].first * v[i].second); }
    sort(ALL(ans));
    REP(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? "\\n" : " ");
  }
  return 0;
}