#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[200100],t,cnt;
int nex[200100],to[200100];
struct kuai{
int sta,fin;
}k[200100];
bool vis[200100];
queue<int>p1,p2;
signed main(){
scanf("%lld",&n);
t=n;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
if(i==1||a[i]!=a[i-1]){
if(i>1){
cnt++;
k[cnt]={k[cnt-1].fin+1,i-1};
}
p1.push(i);
}
nex[i]=i+1;
}
cnt++;
k[cnt]={k[cnt-1].fin+1,n};
for(int i=1;i<=cnt;i++){
for(int j=k[i].sta;j<=k[i].fin;j++){
to[j]=i;
}
}
while(!p1.empty()){
while(!p1.empty()){
printf("%lld ",p1.front());
vis[p1.front()]=1;
p2.push(nex[p1.front()]);
p1.pop();
}
int tt=-1;
while(!p2.empty()){
while(!p2.empty()&&vis[p2.front()])p2.pop();
if(p2.empty())break;
if(p2.front()==0||p2.front()>t){
p2.pop();
continue;
}
if(tt==-1){
tt=to[p2.front()];
p1.push(p2.front());
}else if(a[p2.front()]==a[k[tt].fin]){
nex[k[tt].fin]=p2.front();
k[tt].fin=k[to[p2.front()]].fin;
tt=to[p2.front()];
}else{
tt=to[p2.front()];
p1.push(p2.front());
}
p2.pop();
}
puts("");
}
return 0;
}