alexjercan/bugnet huggingface dataset:
Problem p00730 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>

using namespace std;

void swap(int S[], int x[], int y[], int n, int m) {
  int tmp1, tmp2, tmp3;
  tmp1 = S[m];
  tmp2 = y[m];
  tmp3 = x[m];
  S[m] = S[n];
  y[m] = y[n];
  x[m] = x[n];
  S[n] = tmp1;
  y[n] = tmp2;
  x[n] = tmp3;
}

int main(void) {
  int n, w, d, p, s, S[102], x[102], y[102], num, i, j, tmp[2];
  while (1) {
    scanf("%d%d%d", &n, &w, &d);
    if (n == 0 && w == 0 && d == 0)
      break;
    S[0] = w * d;
    x[0] = w, y[0] = d;
    num = 1;
    for (i = 0; i < n; i++) {
      scanf("%d%d", &p, &s);
      tmp[0] = x[p - 1];
      tmp[1] = y[p - 1];
      s %= tmp[0] + tmp[1];
      for (j = 0; tmp[j] < s; j++)
        s -= tmp[j];
      if (j == 0) {
        x[num] = x[p - 1] - s;
        x[num + 1] = s;
        y[num + 1] = y[num] = y[p - 1];
      } else {
        y[num] = y[p - 1] - s;
        y[num + 1] = s;
        x[num + 1] = x[num] = x[p - 1];
      }
      S[num] = x[num] * y[num];
      S[num + 1] = x[num + 1] * y[num + 1];
      if (S[num] > S[num + 1])
        swap(S, x, y, num + 1, num);
      for (j = p - 1; j < num + 1; j++) {
        y[j] = y[j + 1];
        x[j] = x[j + 1];
        S[j] = S[j + 1];
      }
      num++;
    }
    sort(S, S + num);
    for (i = 0; i < num - 1; i++)
      printf("%d ", S[i]);
    printf("%d\\n", S[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>

using namespace std;

void swap(int S[], int x[], int y[], int n, int m) {
  int tmp1, tmp2, tmp3;
  tmp1 = S[m];
  tmp2 = y[m];
  tmp3 = x[m];
  S[m] = S[n];
  y[m] = y[n];
  x[m] = x[n];
  S[n] = tmp1;
  y[n] = tmp2;
  x[n] = tmp3;
}

int main(void) {
  int n, w, d, p, s, S[101], x[101], y[101], num, i, j, tmp[2];
  while (1) {
    scanf("%d%d%d", &n, &w, &d);
    if (n == 0 && w == 0 && d == 0)
      break;
    S[0] = w * d;
    x[0] = w, y[0] = d;
    num = 1;
    for (i = 0; i < n; i++) {
      scanf("%d%d", &p, &s);
      tmp[0] = x[p - 1];
      tmp[1] = y[p - 1];
      for (j = 0; tmp[j] < s; j = (j + 1) % 2)
        s -= tmp[j];
      if (j == 0) {
        x[num] = x[p - 1] - s;
        x[p - 1] = s;
        y[num] = y[p - 1];
      } else {
        y[num] = y[p - 1] - s;
        y[p - 1] = s;
        x[num] = x[p - 1];
      }
      S[num] = x[num] * y[num];
      S[p - 1] = x[p - 1] * y[p - 1];
      if (S[p - 1] > S[num])
        swap(S, x, y, p - 1, num);
      num++;
    }
    sort(S, S + num);
    for (i = 0; i < num - 1; i++)
      printf("%d ", S[i]);
    printf("%d\\n", S[num - 1]);
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
using namespace std;

int main() {
  int N, w, d;
  while (cin >> N >> w >> d && w && d) {

    int p, s, tmp1, tmp2;
    pair<int, int> rect[110], rect1, rect2; // w,d
    int ans[110];
    int pw, pd;
    rect[1] = {w, d};
    REP(i, 2, N + 2) {
      cin >> p >> s;
      pw = rect[p].first;
      pd = rect[p].second;

      s %= pw + pd;

      if (s < pw) {
        rect1 = {pw - s, pd};
        rect2 = {s, pd};
      } else {
        s -= pw;
        rect1 = {pw, pd - s};
        rect2 = {pw, s};
      }
      tmp1 = rect1.first * rect1.second;
      tmp2 = rect2.first * rect2.second;
      if (tmp1 > tmp2) {
        swap(rect1, rect2);
      }
      for (int j = p + 1; j <= i - 1; j++) {
        rect[j - 1] = rect[j];
      }
      rect[i - 1] = rect1;
      rect[i] = rect2;
    }
    REP(i, 1, N + 2) { ans[i - 1] = rect[i].first * rect[i].second; }
    sort(ans, ans + N + 1);
    REP(i, 0, N) { cout << ans[i] << " "; }
    p(ans[N]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
using namespace std;

int main() {
  int N, w, d;
  while (cin >> N >> w >> d && w && d) {
    int p, s, tmpp, tmpi;
    pair<int, int> rect[110]; // w,d
    int ans[110];
    int pw, pd;
    rect[1] = make_pair(w, d);
    REP(i, 2, N + 2) {
      cin >> p >> s;
      pw = rect[p].first;
      pd = rect[p].second;
      s %= pw + pd;

      if (s < pw) {
        rect[i].first = pw - s;
        rect[p].first = s;
        rect[i].second = pd;
      } else {
        s -= pw;
        rect[i].second = pd - s;
        rect[p].second = s;
        rect[i].first = pw;
      }
      tmpp = rect[p].first * rect[p].second;
      tmpi = rect[i].first * rect[i].second;
      if (tmpp > tmpi) {
        swap(rect[p], rect[i]);
      }
    }
    REP(i, 1, N + 2) { ans[i - 1] = rect[i].first * rect[i].second; }
    sort(ans, ans + N + 1);
    REP(i, 0, N + 1) { cout << ans[i] << " "; }
    p("");
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

bool larger(pair<int, int> &a, pair<int, int> &b) {
  return a.first * a.second < b.first * b.second;
}

int main() {
  while (1) {
    int n, w, d;
    cin >> n >> w >> d;
    if (w == 0)
      break;

    vector<pair<int, int>> cakes;
    cakes.push_back(make_pair(w, d));
    for (int i = 0; i < n; i++) {
      int p, s;
      cin >> p >> s;
      p--;
      int x = cakes[p].first, y = cakes[p].second;
      cakes.erase(cakes.begin() + p);
      s %= x + y;
      if (s < x) {
        if (s <= x / 2) {
          cakes.push_back(make_pair(s, y));
          cakes.push_back(make_pair(x - s, y));
        } else {
          cakes.push_back(make_pair(x - s, y));
          cakes.push_back(make_pair(s, y));
        }
      } else {
        s -= x;
        if (s <= y / 2) {
          cakes.push_back(make_pair(x, s));
          cakes.push_back(make_pair(x, y - s));
        } else {
          cakes.push_back(make_pair(x, y - s));
          cakes.push_back(make_pair(x, s));
        }
      }
    }

    sort(cakes.begin(), cakes.end(), larger);
    for (int i = 0; i < n; i++) {
      cout << cakes[i].first * cakes[i].second << " ";
    }
    cout << cakes[n].first * cakes[n].second << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

bool larger(pair<int, int> &a, pair<int, int> &b) {
  return a.first * a.second < b.first * b.second;
}

int main() {
  while (1) {
    int n, w, d;
    cin >> n >> w >> d;
    if (w == 0)
      break;

    vector<pair<int, int>> cakes;
    cakes.push_back(make_pair(w, d));
    for (int i = 0; i < n; i++) {
      int p, s;
      cin >> p >> s;
      p--;
      int x = cakes[p].first, y = cakes[p].second;
      cakes.erase(cakes.begin() + p);
      s %= x + y;
      if (s < x) {
        if (s <= x / 2) {
          cakes.push_back(make_pair(s, y));
          cakes.push_back(make_pair(x - s, y));
        } else {
          cakes.push_back(make_pair(x - s, y));
          cakes.push_back(make_pair(s, d));
        }
      } else {
        s -= x;
        if (s <= y / 2) {
          cakes.push_back(make_pair(x, s));
          cakes.push_back(make_pair(x, y - s));
        } else {
          cakes.push_back(make_pair(x, y - s));
          cakes.push_back(make_pair(x, s));
        }
      }
    }

    sort(cakes.begin(), cakes.end(), larger);
    for (int i = 0; i < n; i++) {
      cout << cakes[i].first * cakes[i].second << " ";
    }
    cout << cakes[n].first * cakes[n].second << endl;
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

class cake {
public:
  int b, w, d;
  cake(int birth, int width, int depth) : b(birth), w(width), d(depth) {}
  bool operator<(const cake &r) const {
    if (b != r.b)
      return b < r.b;
    else
      return w * d < r.w * r.d;
  }
};

bool compare_area(const cake &r, const cake &l) {
  return r.w * r.d < l.w * l.d;
}

int main(void) {
  vector<cake> C;
  int n, w, d, p, s;
  while (cin >> n >> w >> d && w && d) {
    C.clear();
    C.push_back(cake(0, w, d));
    rep(i, n) {
      cin >> p >> s;
      p--;
      sort(C.begin(), C.end());
      s = s % (C[p].w + C[p].d);
      if (s < C[p].w) {
        C.push_back(cake(i + 1, C[p].w - s, C[p].d));
        C[p] = cake(i + 1, s, C[p].d);
      } else {
        s -= C[p].w;
        C.push_back(cake(i + 1, C[p].w, C[p].d - s));
        C[p] = cake(i + 1, C[p].w, s);
      }
    }
    sort(C.begin(), C.end(), compare_area);
    rep(i, n) cout << C[i].w * C[i].d << " ";
    cout << C[n].w * C[n].d << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

class piece {
public:
  int b, w, d;
  piece(int birth, int width, int depth) : b(birth), w(width), d(depth) {}
  bool operator<(const piece &r) const {
    if (b != r.b)
      return b < r.b;
    else
      return b * w < r.b * r.w;
  }
};
bool orderbysize(const piece &l, const piece &r) {
  return l.w * l.d < r.w * r.d;
}

int main(void) {
  int n, w, d, p, s;
  while (cin >> n >> w >> d && w && d) {
    vector<piece> P;
    P.push_back(piece(0, w, d));
    rep(i, n) {
      cin >> p >> s;
      p--;
      s = s % (P[p].w + P[p].d);
      if (s < P[p].w) {
        P.push_back(piece(i + 1, P[p].w - s, P[p].d));
        P[p] = piece(i + 1, s, P[p].d);
      } else {
        s -= P[p].w;
        P.push_back(piece(i + 1, P[p].w, P[p].d - s));
        P[p] = piece(i + 1, P[p].w, s);
      }
      sort(P.begin(), P.end());
    }
    sort(P.begin(), P.end(), orderbysize);
    rep(i, n) cout << P[i].w * P[i].d << " ";
    cout << P[n].w * P[n].d << endl;
  }
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

class Cake {
public:
  int w, d;
  Cake(int ww, int dd) : w(ww), d(dd) {}
  Cake cut(int s) {
    s %= (w + w + d + d);
    int w2, d2;
    if (s < w) {
      w2 = w - s;
      d2 = d;
      w -= w2;
    } else if (s < w + d) {
      w2 = w;
      d2 = s - w;
      d -= d2;
    } else if (s < w + d + w) {
      w2 = s - w - d;
      d2 = d;
      w -= w2;
    } else {
      w2 = w;
      d2 = s - w - d - w;
      d -= d2;
    }
    if (w > w2)
      swap(w, w2);
    if (d > d2)
      swap(d, d2);
    return Cake(w2, d2);
  }
};

class LessArea {
public:
  bool operator()(const Cake &lhs, const Cake &rhs) {
    return lhs.d * lhs.w < rhs.d * rhs.w;
  }
};

int main() {
  // freopen("C", "r", stdin);

  int n, w, d;
  while (scanf("%d %d %d", &n, &w, &d) != EOF) {
    if (n == 0 && w == 0 && d == 0)
      break;
    vector<Cake> c;
    c.push_back(Cake(w, d));

    for (int i = 0; i < n; ++i) {
      int p, s;
      scanf("%d %d", &p, &s);
      --p;
      Cake cc = c[p];
      Cake cc2 = cc.cut(s);
      c.erase(c.begin() + p);
      c.push_back(cc);
      c.push_back(cc2);
    }
    sort(c.begin(), c.end(), LessArea());

    for (int i = 0; i < c.size() - 1; ++i)
      printf("%d ", c[i].w * c[i].d);
    printf("%d\\n", c.back().w * c.back().d);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

class Cake {
public:
  int w, d;
  Cake(int ww, int dd) : w(ww), d(dd) {}
  Cake cut(int s) {
    s %= (w + w + d + d);
    int w2, d2;
    if (0 < s && s < w) {
      w2 = w - s;
      d2 = d;
      w -= w2;
    } else if (s < w + d) {
      w2 = w;
      d2 = s - w;
      d -= d2;
    } else if (s < w + d + w) {
      w2 = s - w - d;
      d2 = d;
      w -= w2;
    } else {
      w2 = w;
      d2 = s - w - d - w;
      d -= d2;
    }
    if (w > w2)
      swap(w, w2);
    if (d > d2)
      swap(d, d2);
    return Cake(w2, d2);
  }
};

class LessArea {
public:
  bool operator()(const Cake &lhs, const Cake &rhs) {
    return lhs.d * lhs.w < rhs.d * rhs.w;
  }
};

int main() {
  int n, w, d;
  while (scanf("%d %d %d", &n, &w, &d) != EOF) {
    if (n == 0 && w == 0 && d == 0)
      break;
    vector<Cake> c;
    c.push_back(Cake(w, d));

    for (int i = 0; i < n; ++i) {
      int p, s;
      scanf("%d %d", &p, &s);
      --p;
      c.push_back(c[p].cut(s));
    }
    sort(c.begin(), c.end(), LessArea());

    for (int i = 0; i < c.size() - 1; ++i)
      cout << c[i].d * c[i].w << " ";
    cout << c.back().w * c.back().d << endl;
  }
  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main(void) {
  while (true) {
    int n, w, d;
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) {
      break;
    }

    int p, s;
    vector<pair<int, int>> cake;
    cake.push_back(make_pair(w, d));
    for (int i = 0; i < n; i++) {
      cin >> p >> s;
      --p;
      s %= (cake[p].first + cake[p].second);
      pair<int, int> a, b;
      if (s < cake[p].first) {
        a = make_pair(s, cake[p].second);
        b = make_pair(cake[p].first - s, cake[p].second);
      } else {
        a = make_pair(cake[p].first, s - cake[p].first);
        b = make_pair(cake[p].first, cake[p].second - (s - cake[p].first));
      }

      cake.erase(cake.begin() + p);
      if (a.first * a.second > b.first * b.second) {
        swap(a, b);
      }
      cake.push_back(a);
      cake.push_back(b);
    }

    vector<int> cakesize;
    for (size_t i = 0; i < cake.size(); i++) {
      cakesize.push_back(cake[i].first * cake[i].second);
    }
    sort(cakesize.begin(), cakesize.end());
    for (size_t i = 0; i < cakesize.size(); i++) {
      if (i != 0) {
        cout << " ";
      }
      cout << cakesize[i];
    }
    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main(void) {
  while (true) {
    int n, w, d;
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) {
      break;
    }

    int p, s;
    vector<pair<int, int>> cake;
    cake.push_back(make_pair(w, d));
    for (int i = 0; i < n; i++) {
      cin >> p >> s;
      --p;
      s %= (cake[p].first + cake[p].second);
      pair<int, int> a, b;
      if (s < cake[p].first) {
        a = make_pair(s, cake[p].second);
        b = make_pair(cake[p].first - s, cake[p].second);
      } else {
        a = make_pair(cake[p].first, s - cake[p].first);
        b = make_pair(cake[p].first, cake[p].second - (s - cake[p].first));
      }
      if (a.first * a.second > b.first * b.second) {
        swap(a, b);
      }

      cake[p] = a;
      cake.push_back(b);
    }

    vector<int> cakesize;
    for (size_t i = 0; i < cake.size(); i++) {
      cakesize.push_back(cake[i].first * cake[i].second);
    }
    sort(cakesize.begin(), cakesize.end());
    for (size_t i = 0; i < cakesize.size(); i++) {
      if (i != 0) {
        cout << " ";
      }
      cout << cakesize[i];
    }
    cout << endl;
  }

  return 0;
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

struct Cake {
  int w;
  int d;
  int cnt;
  Cake(int w, int d, int cnt) : w(w), d(d), cnt(cnt) {}
  bool operator<(const Cake &a) const {
    return (cnt == a.cnt ? w * d < a.w * a.d : cnt < a.cnt);
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (1) {
    int n, w, d;
    cin >> n >> w >> d;
    if (!n && !w && !d)
      break;
    vector<Cake> cake;
    cake.pb(Cake(w, d, 0));
    REP(i, n) {
      int p, s;
      cin >> p >> s;
      p--;
      Cake now = cake[p];
      cake[p].cnt = INF;
      now.cnt = i;
      Cake next = now;
      s %= (now.w + now.d);
      if (s <= now.w) {
        now.w = s;
        next.w = next.w - s;
      } else {
        now.d = s - now.w;
        next.d = next.w + next.d - s;
      }
      cake.pb(now);
      cake.pb(next);
      sort(all(cake));
    }
    vector<int> ans;
    REP(i, cake.size()) if (cake[i].cnt != INF) ans.pb(cake[i].d * cake[i].w);
    sort(all(ans));
    REP(i, n + 1) cout << ans[i] << " \\n"[i == n];
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (1) {
    int n, w, d;
    cin >> n >> w >> d;
    if (!n && !w && !d)
      break;
    vector<P> erea(n + 1);
    erea[0] = P(w, d);
    REP(i, n) {
      int p, s;
      cin >> p >> s;
      int cur_w = erea[p - 1].first, cur_d = erea[p - 1].second;
      s %= cur_w + cur_d;
      if (s <= cur_w) {
        erea[p - 1] = P(min(s, cur_w - s), cur_d);
        erea[i + 1] = P(max(s, cur_w - s), cur_d);
      } else {
        erea[p - 1] = P(cur_w, min(s - cur_w, cur_w + cur_d - s));
        erea[i + 1] = P(cur_w, max(s - cur_w, cur_w + cur_d - s));
      }
    }
    vector<int> ans(n + 1);
    REP(i, n + 1) ans[i] = erea[i].first * erea[i].second;
    sort(all(ans));
    REP(i, n + 1) cerr << ans[i] << " \\n"[i == n];
  }
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct DATA {
  int w;
  int d;
};

DATA MakeOneData(int, int);
void Swap(int &, int &);
bool Compare(const DATA &, const DATA &);

int main() {
  int i, n, w, d, p, s, t;
  vector<DATA> data;

  while (1) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0)
      break;
    data.push_back(MakeOneData(w, d));

    for (i = 0; i < n; ++i) {
      cin >> p >> s;
      --p;
      w = data[p].w;
      d = data[p].d;
      s %= (w + d);
      data.erase(data.begin() + p);

      if (s < w) {
        t = w - s;
        if (s > t)
          Swap(s, t);
        data.push_back(MakeOneData(s, d));
        data.push_back(MakeOneData(t, d));
      } else {
        s -= w;
        t = d - s;
        if (s > t)
          Swap(s, t);
        data.push_back(MakeOneData(w, s));
        data.push_back(MakeOneData(w, t));
      }
    }
    sort(data.begin(), data.end(), Compare);

    for (i = 0; i < data.size() - 1; ++i)
      cout << (data[i].d * data[i].w) << " ";
    cout << (data[data.size() - 1].d * data[data.size() - 1].w) << endl;

    data.clear();
  }
  return 0;
}

DATA MakeOneData(int w, int d) {
  DATA data;
  data.w = w;
  data.d = d;
  return data;
}

void Swap(int &a, int &b) {
  int c;
  c = a;
  a = b;
  b = c;
}

bool Compare(const DATA &x, const DATA &y) {
  return ((x.d * x.w) < (y.d * y.w));
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct DATA {
  int w;
  int d;
};

DATA MakeOneData(int, int);
void Swap(int &, int &);
bool Compare(const DATA &, const DATA &);

int main() {
  int i, n, w, d, p, s, t;
  vector<DATA> data;
  vector<DATA>::iterator iter;

  while (1) {
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0)
      break;
    data.push_back(MakeOneData(w, d));

    for (i = 0; i < n; ++i) {
      cin >> p >> s;
      --p;
      w = data[p].w;
      d = data[p].d;
      s %= (w + d);
      iter = data.erase(data.begin() + p);

      if (s < w) {
        t = w - s;
        if (s < t)
          Swap(s, t);
        iter = data.insert(iter, MakeOneData(s, d));
        iter = data.insert(iter, MakeOneData(t, d));
      } else {
        s -= w;
        t = d - s;
        if (s < t)
          Swap(s, t);
        iter = data.insert(iter, MakeOneData(w, s));
        iter = data.insert(iter, MakeOneData(w, t));
      }
    }
    sort(data.begin(), data.end(), Compare);

    for (i = 0; i < data.size() - 1; ++i)
      cout << (data[i].d * data[i].w) << " ";
    cout << (data[data.size() - 1].d * data[data.size() - 1].w) << endl;

    data.clear();
  }
  return 0;
}

DATA MakeOneData(int w, int d) {
  DATA data;
  data.w = w;
  data.d = d;
  return data;
}

void Swap(int &a, int &b) {
  int c;
  c = a;
  a = b;
  b = c;
}

bool Compare(const DATA &x, const DATA &y) {
  return ((x.d * x.w) < (y.d * y.w));
}
Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
using pii = pair<int, int>;
using vi = vector<int>;

signed main() {
  int n, w, h;
  while (cin >> n >> w >> h, n or w or h) {
    vi p(n), s(n);
    rep(i, 0, n) { cin >> p[i] >> s[i]; }
    vector<pii> rects;
    rects.emplace_back(w, h);
    rep(i, 0, n) {
      pii x = rects[p[i] - 1];
      int y = x.first, z = x.second;
      int l = (x.first + x.second) * 2;
      s[i] %= l;
      pii a, b;
      if (s[i] < y) {
        a = pii(s[i], z);
        b = pii(y - s[i], z);
      } else if (s[i] < y + z) {
        pii A(y, s[i] - y), B(y, z - (s[i] - y));
        a = A;
        b = B;
      } else if (s[i] < 2 * y + z) {
        pii A(s[i] - y - z, z), B(y - (s[i] - y - z), z);
        a = A;
        b = B;
      } else {
        pii A(y, s[i] - 2 * y - z), B(y, z - (s[i] - 2 * y - z));
        a = A;
        b = B;
      }

      if (a.first * a.second > b.first * b.second) {
        swap(a, b);
      }
      rects.erase(rects.begin() + p[i] - 1);
      rects.emplace_back(a);
      rects.emplace_back(b);
    }

    sort(rects.begin(), rects.end(),
         [](pii a, pii b) { return a.first * a.second < b.first * b.second; });

    rep(i, 0, rects.size()) {
      cout << rects[i].first * rects[i].second
           << (i == rects.size() - 1 ? '\\n' : ' ');
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
using pii = pair<int, int>;
using vi = vector<int>;

signed main() {
  int n, w, h;
  while (cin >> n >> w >> h, n or w or h) {
    vi p(n), s(n);
    rep(i, 0, n) { cin >> p[i] >> s[i]; }
    vector<pii> rects;
    rects.emplace_back(w, h);
    rep(i, 0, n) {
      pii x = rects[p[i] - 1];
      int y = x.first, z = x.second;
      int l = (x.first + x.second) * 2;
      s[i] %= l;
      pii a, b;
      if (s[i] < x.first) {
        a = pii(s[i], z);
        b = pii(y - s[i], z);
      } else if (s[i] < y + z) {
        pii A(y, s[i] - y), B(y, z - (s[i] - y));
        a = A;
        b = B;
      } else if (s[i] < 2 * y + z) {
        pii A(s[i] - y - z, z), B(y - (s[i] - y - z), z);
        a = A;
        b = B;
      } else {
        pii A(y, s[i] - 2 * y - z), B(y, z - (s[i] - 2 * y - z));
        a = A;
        b = B;
      }

      if (a.first * a.second > b.first * b.second) {
        swap(a, b);
      }
      rects[p[i] - 1] = a;
      rects.emplace_back(b);
    }

    sort(rects.begin(), rects.end(),
         [](pii a, pii b) { return a.first * a.second < b.first * b.second; });

    rep(i, 0, rects.size()) {
      cout << rects[i].first * rects[i].second
           << (i == rects.size() - 1 ? '\\n' : ' ');
    }
  }
}