Language: C++

#include<iostream>
#include<cassert>
#include<ctime>
#include<climits>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include<list>
#include<stack>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define F first
#define S second
#define all(n) n.begin(),n.end()
#define pb push_back
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define INF (1<<27)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef pair<int,P> IP;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
int n,w,d;

bool cmp(const IP &p,const IP &q){
  if(p.F != q.F)return p.F < q.F;
  return p.S.S < q.S.S;
}

void qrint(IP i){
  cout << "i = " << i.F << " " << i.S.F << " " << i.S.S << endl;

}

int main(){

  while(true){
    cin >> n >> w >> d;
    cerr <<"input = " << n << " " << w << " " << d << endl;
    if(n+w+d == 0)break;
    //vector<IP> vec;
    //vec.pb(IP(w*d,P(w,d)));
    vector<P> vec;
    vec.pb(P(w,d)); 

    rep(i,n){
      int p,s;
      cin >> p >> s;
      cerr << p << " " << s << endl; 
      p--;
      // cout << "now! vec state is " << endl;
      //rep(i,vec.size()){
	//	cout << vec[i].F << " " << vec[i].S.F << " " << vec[i].S.S << endl;
	//}     
      //cout<< "------" << endl;
      //IP pre = vec[p];
      P pre = vec[p];
      cree << "pre = " << pre.F << " " << pre.S << endl;
      //vector<IP>::iterator it = vec.begin();
      vector<P>::iterator it = vec.begin();
      while(it != vec.end())
	{
	  if((*it) == pre)
	    {
	      break;
	    }
	  it++;
	}
      vec.erase(it);
     
      //int fla = pre.S.F;
      int last = -1;
      //s = s%(pre.S.F*2+pre.S.S*2);
      s = s%(pre.F*2+pre.S*2);
      cerr << "s =" << s << ", mod = " << pre.F*2+pre.S*2 << endl;
      assert(s <= (pre.F*2+pre.S*2));
      if(s<= pre.F)
	{
	  last = 2;
	}
      else if(s <= pre.F+pre.S)
	{
	  last = 1;
	  s -= pre.F; 
	}
      else if(s <= pre.F*2+pre.S)
	{
	  last = 2;
	  s  = pre.F*2+pre.S-s;
	}
	else if(s <= pre.F*2+pre.S*2)
	  {
	    last = 1;
	    s = pre.F*2+pre.S*2-s;
	  }
	else 
	  {
	    cerr << "s = "<< s << endl;
	    assert(false);
	  }
      assert(last != -1);
     
      if(last == 2)
	{
	  int sum = s*(pre.S);
	  //IP lef = IP(sum,P(s,pre.S.S)); 
	  //IP rig = IP(pre.F-sum,P(pre.S.F-s,pre.S.S));
	  P lef = P(s,pre.S); 
	  P rig = P(pre.F-s,pre.S);
	  // cout << "lef " << endl;
	  //qrint(lef);
	  //cout << "rig " << endl;
	  //qrint(rig);
	  if(lef.F*lef.S < rig.F*rig.S)
	    {
	      vec.pb(lef);
	      vec.pb(rig);
	    }
	  else
	    {
	      vec.pb(rig);
	      vec.pb(lef);
	    }
	}
      else if(last == 1)
	{
	  //else if(s <= pre.S.F+pre.S.S){
	  int sum = pre.F*(pre.S-s);
	  //IP tp = IP(pre.F-sum,P(pre.S.F,s));
	  //IP bm = IP(sum,P(pre.S.F,pre.S.S-s));
	  P tp = P(pre.F,s);
	  P bm = P(pre.F,pre.S-s);
	  //cout << "tp " << endl;
	  //qrint(tp);
	  //cout << "bm " << endl;
	  //qrint(bm);
	  //cout <<"sum =" << sum << endl;
	  if(tp.F*tp.S < bm.F*bm.S)
	    {
	      vec.pb(tp);
	      vec.pb(bm);
	    }
	  else
	    {
	      vec.pb(bm);
	      vec.pb(tp);
	    }
	}    
    }
    vector<int> vec2;
    rep(i,vec.size()){
      vec2.pb(vec[i].F*vec[i].S);
    }
    sort(all(vec2));
    rep(i,vec2.size()){
      cout << vec2[i];
      if(i != vec2.size()-1)cout << " ";
      else cout << endl;
    }


  }
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:7: error: 'cree' was not declared in this scope; did you mean 'free'?
   74 |       cree << "pre = " << pre.F << " " << pre.S << endl;
      |       ^~~~
      |       free