#include <iostream>

#include <cstdio>
#include <vector>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;
     static bool cmp(const pair<int,int> &a, const pair<int,int> &b)
    {
        return a.first < b.first;
    }
int main() 
{
        int arr_[] = {2225, 1729 ,1835, 951, 1143, 515, 1525, 743, 1025, 1611, 1827, 2203, 1116, 1514, 723};
        int dep_[]  = {2231, 2003, 2149, 2252, 2352, 2153, 1625, 1049, 1337, 1639, 2151, 2330, 1633, 1611 ,2009};
        // Your code here
        
        
        stack<int> s;
        int n = 15;
        vector<int> arr;
        vector<int> dep;
        for(int i=0;i<n;i++)
        {
            arr.push_back(arr_[i]);
            dep.push_back(dep_[i]);
        }
        vector< pair<int,int> > v;
        
        for(int i=0;i<n;i++)
        {
            v.push_back({arr[i], dep[i]});
        }
        sort(v.begin(),v.end(),cmp);
        
        
       /* for(int i=0;i<n;i++)
        {
            printf("%5d,", v[i].first);
        }
        printf("\n");
        for(int i=0;i<n;i++)
        {
            printf("%5d,",v[i].second);
            
        }
        printf("\n\n");
        
        */
      //  stack<int> s;
        s.push(v[0].second);
        int mx =1;
        for(int i=1;i<n;i++)
        {
   
            while(!s.empty() && s.top() <= v[i].first)
            {
                 
                s.pop();
            }   
            stack<int> tmp;
            while(!s.empty() && v[i].second > s.top())
            {
                tmp.push(s.top());
                s.pop();
                
            }

            s.push(v[i].second);
            
            while(!tmp.empty())
            {
                s.push(tmp.top());
                tmp.pop();
            }
            mx = max(mx, (int)(s.size()));
            
            
            stack<int> z = s;
            while(!z.empty())
            {
                printf("%d,",z.top());
                z.pop();
            }
            printf("\n\n");
           // s.push(v[i].second);
        }
        return 0;
}