Problem:
Problem C:
Cut the Cake
Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest
pâtissiers
in the world.
Those who are invited to his birthday party are
gourmets
from around the world.
They are eager to see and eat his extremely creative cakes.
Now a large box-shaped cake is being carried into the party.
It is not beautifully decorated and looks rather simple, but it must be delicious beyond anyone's imagination.
Let us cut it into pieces with a knife and serve them to the guests attending the party.
The cake looks rectangular, viewing from above (Figure C-1).
As exemplified in Figure C-2, the cake will iteratively be cut into pieces, where on each cut exactly a single piece is cut into two smaller pieces.
Each cut surface must be orthogonal to the bottom face and must be orthogonal or parallel to a side face.
So, every piece shall be rectangular looking from above and every side face vertical.
Figure C-1: The top view of the cake
Figure C-2: Cutting the cake into pieces
Piece sizes in Figure C-2 vary significantly and it may look unfair, but you don't have to worry.
Those guests who would like to eat as many sorts of cakes as possible often prefer smaller pieces.
Of course, some prefer larger ones.
Your mission of this problem is to write a computer program that simulates the cutting process of the cake and reports the size of each piece.
Input
The input is a sequence of datasets, each of which is of the following format.
n
w
d
p
1
s
1
...
p
n
s
n
The first line starts with an integer
n
that is between 0 and 100 inclusive.
It is the number of cuts to be performed.
The following
w
and
d
in the same line are integers between 1 and 100 inclusive.
They denote the width and depth of the cake, respectively.
Assume in the sequel that the cake is placed so that
w
and
d
are the lengths in the east-west and north-south directions, respectively.
Each of the following
n
lines specifies a single cut, cutting one and only one piece into two.
p
i
is an integer between 1 and
i
inclusive and is the identification number of the piece that is the target of the
i
-th cut.
Note that, just before the
i
-th cut, there exist exactly
i
pieces.
Each piece in this stage has a unique identification number that is one of 1, 2, ...,
i
and is defined as follows:
The earlier a piece was born, the smaller its identification number is.
Of the two pieces born at a time by the same cut, the piece with the smaller area (looking from above) has the smaller identification number.
If their areas are the same, you may define as you like the order between them, since your choice in this case has no influence on the final answer.
Note that identification numbers are adjusted after each cut.
s
i
is an integer between 1 and 1000 inclusive and specifies the starting point of the
i
-th cut.
From the northwest corner of the piece whose identification number is
p
i
, you can reach the starting point by traveling
s
i
in the clockwise direction around the piece.  
You may as
...(truncated)

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>; using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ll INF = 1LL << 60;
const ld PI = acos(-1);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec);
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr);
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const pair<T, U> &pa);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa);
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp);
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp);
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl);
 
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <class... T> std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; }
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl
#define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr)
#else
#define dbg(x) ((void)0)
#define dbgif(cond, x) ((void)0)
#endif
void solve();
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
//見切り発車で実装しては行けない．頭の中でコードが完全に出来上がるまで書き始めるな．
void solve(){
  while(true){
    int n,w,d;cin>>n>>w>>d;
    if(n==0&&w==0&&d==0)return;
    map<ll,tuple<ll,ll,ll,ll>> mp;
    mp[0] = {0,d,0,w};
    auto calc = [&](const tuple<ll,ll,ll,ll> &s)->ll{
      ll X = get<1>(s)-get<0>(s);
      ll Y = get<3>(s)-get<2>(s);
      return X * Y;
    };
    rep(k,n){
      ll p,s;cin>>p>>s;
      p--;
      auto [x1,x2,y1,y2] = mp[p];
      mp.erase(p);
      const ll H = x2 - x1;
      const ll W = y2 - y1;
      const ll sz = mp.size();
      s%=(H+W)*2;
      tuple<ll,ll,ll,ll> a,b;
      if(0<=s&&s<=W){
        //[y1,s),[s,y2)
        a = make_tuple(x1,x2,y1,y1+s);
        b = make_tuple(x1,x2,y1+s,y2);
      }else if(W<=s&&s<=W+H){
        s-=W;
        a = make_tuple(x1,x1+s,y1,y2);
        b = make_tuple(x1+s,x2,y1,y2);
      }else if(W+H<=s&&s<=W+H+W){
        s-=W+H;
        s = W-s;
        a = make_tuple(x1,x2,y1,y1+s);
        b = make_tuple(x1,x2,y1+s,y2);
      }else if(W+H+W<=s&&s<=W+H+W+H){
        s-=W+H+W;
        s=H-s;
        a = make_tuple(x1,x1+s,y1,y2);
        b = make_tuple(x1+s,x2,y1,y2);
      }

      if(calc(b)<calc(a))swap(a,b);
      mp[sz+10000] = a;
      mp[sz+20000] = b;
      ll c = 0;
      map<ll,tuple<ll,ll,ll,ll>> nmp;
      for(auto [x,y]:mp){
        nmp[c++] = y;
      }
      swap(nmp,mp);
    }
    vl ans;
    for(auto [a,b]:mp)ans.push_back(calc(b));
    sort(all(ans));
    rep(i,ans.size()){
      cout<<ans[i];
      if(i+1==(int)ans.size())cout<<endl;
      else cout<<" ";
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3312
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>; using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ll INF = 1LL << 60;
const ld PI = acos(-1);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec);
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr);
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const pair<T, U> &pa);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa);
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp);
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp);
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl);
 
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <class... T> std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; }
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl
#define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr)
#else
#define dbg(x) ((void)0)
#define dbgif(cond, x) ((void)0)
#endif
void solve();
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
//見切り発車で実装しては行けない．頭の中でコードが完全に出来上がるまで書き始めるな．
void solve(){
  while(true){
    int n,w,d;cin>>n>>w>>d;
    if(n==0&&w==0&&d==0)return;
    map<ll,tuple<ll,ll,ll,ll>> mp;
    mp[0] = {0,d,0,w};
    auto calc = [&](const tuple<ll,ll,ll,ll> &s)->ll{
      ll X = get<1>(s)-get<0>(s);
      ll Y = get<3>(s)-get<2>(s);
      return X * Y;
    };
    rep(k,n){
      ll p,s;cin>>p>>s;
      p--;
      auto [x1,x2,y1,y2] = mp[p];
      mp.erase(p);
      const ll H = x2 - x1;
      const ll W = y2 - y1;
      const ll sz = mp.size();
      s%=(H+W)*2;
      tuple<ll,ll,ll,ll> a,b;
      if(0<=s&&s<=W){
        //[y1,s),[s,y2)
        a = make_tuple(x1,x2,y1,y1+s);
        b = make_tuple(x1,x2,y1+s,y2);
      }else if(W<=s&&s<=W+H){
        s-=W;
        a = make_tuple(x1,x1+s,y1,y2);
        b = make_tuple(x1+s,x2,y1,y2);
      }else if(W+H<=s&&s<=W+H+W){
        s-=W+H;
        s = W-s;
        a = make_tuple(x1,x2,y1,y1+s);
        b = make_tuple(x1,x2,y1+s,y2);
      }else if(W+H+W<=s&&s<=W+H+W+H){
        s-=W+H+W;
        s=H-s;
        a = make_tuple(x1,x1+s,y1,y2);
        b = make_tuple(x1+s,x2,y1,y2);
      }

      if(calc(b)<calc(a))swap(a,b);
      mp[sz+10000] = a;
      mp[sz+20000] = b;
      ll c = 0;
      map<ll,tuple<ll,ll,ll,ll>> nmp;
      for(auto [x,y]:mp){
        if(y==make_tuple(0,0,0,0))continue;
        nmp[c++] = y;
      }
      swap(nmp,mp);
    }
    vl ans;
    for(auto [a,b]:mp)ans.push_back(calc(b));
    sort(all(ans));
    rep(i,ans.size()){
      cout<<ans[i];
      if(i+1==(int)ans.size())cout<<endl;
      else cout<<" ";
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3480
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>; using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ll INF = 1LL << 60;
const ld PI = acos(-1);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec);
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr);
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const pair<T, U> &pa);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa);
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp);
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp);
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl);
 
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <class... T> std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; }
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl
#define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr)
#else
#define dbg(x) ((void)0)
#define dbgif(cond, x) ((void)0)
#endif
void solve();
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
//見切り発車で実装しては行けない．頭の中でコードが完全に出来上がるまで書き始めるな．
void solve(){
  while(true){
    int n,w,d;cin>>n>>w>>d;
    if(n==0&&w==0&&d==0)return;
    map<ll,tuple<ll,ll,ll,ll>> mp;
    mp[0] = {0,d,0,w};
    auto calc = [&](const tuple<ll,ll,ll,ll> &s)->ll{
      ll X = get<1>(s)-get<0>(s);
      ll Y = get<3>(s)-get<2>(s);
      return X * Y;
    };
    rep(k,n){
      ll p,s;cin>>p>>s;
      p--;
      dbg(p);
      auto [x1,x2,y1,y2] = mp[p];
      assert(mp.size()==k+1);
      assert(mp[p]!=make_tuple(0,0,0,0));
      dbg(mp[p]);
      mp.erase(p);
      const ll H = x2 - x1;
      const ll W = y2 - y1;
      const ll sz = mp.size();
      s%=(H+W)*2;
      dbg(s);
      dbg(H);
      dbg(W);
      tuple<ll,ll,ll,ll> a,b;
      if(0<=s&&s<=W){
        //[y1,s),[s,y2)
        dbg(s);
        a = make_tuple(x1,x2,y1,y1+s);
        b = make_tuple(x1,x2,y1+s,y2);
      }else if(W<=s&&s<=W+H){
        s-=W;
        dbg(s);
        dbg(x1);
        dbg(x1+s);
        assert(0<=x1+s&&x1+s<=x2);
        a = make_tuple(x1,x1+s,y1,y2);
        b = make_tuple(x1+s,x2,y1,y2);
      }else if(W+H<=s&&s<=W+H+W){
        s-=W+H;
        s = W-s;
        dbg(s);
        a = make_tuple(x1,x2,y1,y1+s);
        b = make_tuple(x1,x2,y1+s,y2);
      }else if(W+H+W<=s&&s<=W+H+W+H){
        s-=W+H+W;
        s=H-s;
        dbg(s);
        dbg(x1);
        dbg(x1+s);
        a = make_tuple(x1,x1+s,y1,y2);
        b = make_tuple(x1+s,x2,y1,y2);
      }

      if(calc(b)<calc(a))swap(a,b);
      dbg(a);
      dbg(b);
      dbg(mp);
      mp[sz+10000] = a;
      mp[sz+20000] = b;
      ll c = 0;
      map<ll,tuple<ll,ll,ll,ll>> nmp;
      for(auto [x,y]:mp){
        dbg(y);
        if(y==make_tuple(0,0,0,0))continue;
        nmp[c++] = y;
      }
      dbg(nmp);
      swap(nmp,mp);
    }
    vl ans;
    for(auto [a,b]:mp)ans.push_back(calc(b)),dbg(b);
    sort(all(ans));
    rep(i,ans.size()){
      cout<<ans[i];
      if(i+1==(int)ans.size())cout<<endl;
      else cout<<" ";
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3488
final_rank: 3