#include<cstdio>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int N=2e5+5;
struct node{
bool flag;
queue<int>data;
};
list<node>l;
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
bool temp;
scanf("%d",&temp);
if(l.empty()){
node t;
t.flag=temp;
t.data.push(i);
l.push_back(t);
}else if(temp!=l.back().flag){
node t;
t.flag=temp;
t.data.push(i);
l.push_back(t);
}else{
auto x=--l.end();
x->data.push(i);
}
}
while(!l.empty()){
vector<int>ans;
for(auto x=l.begin();x!=l.end();x++){
ans.push_back(x->data.front());
x->data.pop();
if(x->data.empty())
l.erase(x);
}
for(auto x=++l.begin();x!=l.end();x++){
auto y=x;y--;
if(x->flag==y->flag){
while(!y->data.empty()){
x->data.push(y->data.front());
y->data.pop();
}
l.erase(y);
}
}
for(int e:ans)
printf("%d ",e);
putchar('\n');
}
return 0;
}