Language: C++

//tyama_C_fast.cpp
//much faster!

//PerlÅà¯é¯Ç½ªâçÈ¢B

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define hi(x) (x).first
#define lo(x) (x).second

struct comp{
    bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
};

inline void solve(int n, int w, int d){
	vector<unsigned> v;
	v.push_back(make_pair(w,d));
	while(n--){
		int p, s, state=0;
		scanf("%d %d", &p, &s);
		p--;
		s%=(hi(v.at(p))+lo(v.at(p)));
		
		unsigned x=hi(v.at(p)), y=lo(v.at(p)), _x=0, _y=0;
		while(s--){
			switch(state){
				case 0:{
					_x++;
					if(_x==x)state=1;
					break;
				}
				case 1:{
					_y++;
					/* impossible
					if(_y==y)state=2;
					break;
				}
				case 2:{
					_x--;
					if(_x==0)state=3;
					break;
				}
				case 3:{
					_y--;
					if(_y==0)state=0;
					*/
					break;
				}
			}
		}
		unsigned x1, x2, y1, y2;
		switch(state){
			case 0: /*case 2:*/{
				x1=_x;x2=x-_x;
				y1=y2=y;
				break;
			}
			case 1: /*case 3:*/{
				x1=x2=x;
				y1=_y;y2=y-_y;
				break;
			}
		}
		
		v.erase(v.begin()+p);
		if(x1*y1>x2*y2){
			v.push_back(make_pair(x2,y2));
			v.push_back(make_pair(x1,y1));
		}else{
			v.push_back(make_pair(x1,y1));
			v.push_back(make_pair(x2,y2));
		}
	}
	
	sort(v.begin(), v.end());
	while(v.size()){
		printf("%d", hi(v.at(0))*lo(v.at(0)));
		v.erase(v.begin());
		if(v.size())printf(" "); //±ÌÓÍPerl¾Æjoinªg¦é¨B
	}
	printf("\n");
}

int main(){
	int n,w,d;
	while(1){
		scanf("%d %d %d",&n,&w,&d);
		if(!n&&!w&&!d)return 0;
		solve(n, w, d);
	}
}

Compiler output:
a.cc: In member function 'bool comp::operator()(unsigned int, unsigned int)':
a.cc:11:19: error: request for member 'first' in 'a', which is of non-class type 'const unsigned int'
   11 | #define hi(x) (x).first
      |                   ^~~~~
a.cc:15:64: note: in expansion of macro 'hi'
   15 |     bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
      |                                                                ^~
a.cc:12:19: error: request for member 'second' in 'a', which is of non-class type 'const unsigned int'
   12 | #define lo(x) (x).second
      |                   ^~~~~~
a.cc:15:70: note: in expansion of macro 'lo'
   15 |     bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
      |                                                                      ^~
a.cc:11:19: error: request for member 'first' in 'b', which is of non-class type 'const unsigned int'
   11 | #define hi(x) (x).first
      |                   ^~~~~
a.cc:15:78: note: in expansion of macro 'hi'
   15 |     bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
      |                                                                              ^~
a.cc:12:19: error: request for member 'second' in 'b', which is of non-class type 'const unsigned int'
   12 | #define lo(x) (x).second
      |                   ^~~~~~
a.cc:15:84: note: in expansion of macro 'lo'
   15 |     bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
      |                                                                                    ^~
a.cc: In function 'void solve(int, int, int)':
a.cc:20:20: error: no matching function for call to 'std::vector<unsigned int>::push_back(std::pair<int, int>)'
   20 |         v.push_back(make_pair(w,d));
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const std::vector<unsigned int>::value_type&' {aka 'const unsigned int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<unsigned int>::value_type&&' {aka 'unsigned int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:11:19: error: request for member 'first' in 'v.std::vector<unsigned int>::at(((std::vector<unsigned int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<unsigned int>, unsigned int>::value_type' {aka 'unsigned int'}
   11 | #define hi(x) (x).first
      |                   ^~~~~
a.cc:25:21: note: in expansion of macro 'hi'
   25 |                 s%=(hi(v.at(p))+lo(v.at(p)));
      |                     ^~
a.cc:12:19: error: request for member 'second' in 'v.std::vector<unsigned int>::at(((std::vector<unsigned int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<unsigned int>, unsigned int>::value_type' {aka 'unsigned int'}
   12 | #define lo(x) (x).second
      |                   ^~~~~~
a.cc:25:33: note: in expansion of macro 'lo'
   25 |                 s%=(hi(v.at(p))+lo(v.at(p)));
      |                                 ^~
a.cc:11:19: error: request for member 'first' in 'v.std::vector<unsigned int>::at(((std::vector<unsigned int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<unsigned int>, unsigned int>::value_type' {aka 'unsigned int'}
   11 | #define hi(x) (x).first
      |                   ^~~~~
a.cc:27:28: note: in expansion of macro 'hi'
   27 |                 unsigned x=hi(v.at(p)), y=lo(v.at(p)), _x=0, _y=0;
      |                            ^~
a.cc:31:41: error: '_x' was not declared in this scope; did you mean 'x'?
   31 |                                         _x++;
      |                                         ^~
      |                                         x
a.cc:36:41: error: '_y' was not declared in this scope
   36 |                                         _y++;
      |                                         ^~
a.cc:57:36: error: '_x' was not declared in this scope; did you mean 'x'?
   57 |                                 x1=_x;x2=x-_x;
      |                                    ^~
      |                                    x
a.cc:58:39: error: 'y' was not declared in this scope; did you mean 'y2'?
   58 |                                 y1=y2=y;
      |                                       ^
      |                                       y2
a.cc:63:36: error: '_y' was not declared in this scope
   63 |                                 y1=_y;y2=y-_y;
      |                                    ^~
a.cc:63:42: error: 'y' was not declared in this scope; did you mean 'y2'?
   63 |                                 y1=_y;y2=y-_y;
      |                                          ^
      |                                          y2
a.cc:70:36: error: no matching function for call to 'std::vector<unsigned int>::push_back(std::pair<unsigned int, unsigned int>)'
   70 |                         v.push_back(make_pair(x2,y2));
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::pair<unsigned int, unsigned int>' to 'const std::vector<unsigned int>::value_type&' {aka 'const unsigned int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::pair<unsigned int, unsigned int>' to 'std::vector<unsigned int>::value_type&&' {aka 'unsigned int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:71:36: error: no matching function for call to 'std::vector<unsigned int>::push_back(std::pair<unsigned int, unsigned int>)'
   71 |                         v.push_back(make_pair(x1,y1));
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::pair<unsigned int, unsigned int>' to 'const std::vector<unsigned int>::value_type&' {aka 'const unsigned int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::pair<unsigned int, unsigned int>' to 'std::vector<unsigned int>::value_type&&' {aka 'unsigned int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:73:36: error: no matching function for call to 'std::vector<unsigned int>::push_back(std::pair<unsigned int, unsigned int>)'
   73 |                         v.push_back(make_pair(x1,y1));
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::pair<unsigned int, unsigned int>' to 'const std::vector<unsigned int>::value_type&' {aka 'const unsigned int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; value_type = unsigned int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::pair<unsigned int, unsigned int>' to 'std::vector<unsigned int>::value_type&&' {aka 'unsigned int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:74:36: error: no matching function for call to 'std::vector<unsigned int>::push_back(std::pair<unsigned int, unsigned int>)'
   74 |                         v.push_back(make_pair(x2,y2));
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c+