#include<bits/stdc++.h>
using namespace std;
int n,fruit[200005];
struct node{
int st,ed,edval;
};
queue <node> q,fruits;
bool vis[200005];
void merge(){
while(!q.empty()){
node now1=q.front();
q.pop();
while(!q.empty()){
node now2=q.front();
if(now1.edval==now2.edval){
now1.ed=now2.ed;
q.pop();
}else{
break;
}
}
fruits.push(now1);
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>fruit[i];
}
int st=1,cnt=n;
for(int i=2;i<=n;i++){
if(fruit[i]!=fruit[i-1]){
fruits.push(node{st,i-1,fruit[i-1]});
st=i;
}else if(i==n){
fruits.push(node{st,n,fruit[n]});
}
}
while(cnt){
while(!fruits.empty()){
node now=fruits.front();
fruits.pop();
while(vis[now.st] && now.st<=now.ed){
now.st++;
}
if(now.st>now.ed){
cout<<now.st<<" ";
vis[now.st]=1;
cnt--;
if(now.st!=now.ed){
now.st++;
q.push(now);
}
}
}
cout<<endl;
merge();
}
return 0;
}