#include<iostream>
#include<queue>
using namespace std;
const int N=2e5+10;
#define int long long
inline int fread(){
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9'){
if(ch=='-'){
m=-1;
}
ch=getchar();
}
while(ch>='0' and ch<='9'){
n=(n<<3)+(n<<1)+ch-48;
ch=getchar();
}
return n*m;
}
int n,sum,a[N];
bool flag[N];
struct node{
int m,x,y;
}z,p,q;
queue<node>q1,q2;
signed main(){
n=fread();
for(int i=1;i<=n;i++){
a[i]=fread();
}
a[n+1]=!a[n];
for(int i=2,j=1;i<n+2;i++){
if(a[i]!=a[i-1]){
q1.push((node){j,i-1,a[i-1]});
j=i;
}
}
sum=n;
while(sum){
while(q1.size()){
z=q1.front();
q1.pop();
while(flag[z.m] and z.m<=z.x){
z.m++;
}
if(z.m>z.x){
continue;
}
printf("%d ",z.m);
sum--;
flag[z.m]=true;
if(z.x==z.m){
continue;
}
z.m++;
q2.push(z);
}
puts("");
while(q2.size()){
q=q2.front(),q2.pop();
while(q2.size()){
p=q2.front();
if(p.y==q.y){
q.x=p.x,q2.pop();
}else{
break;
}
}
q1.push(q);
}
}
return 0;
}
/**************************************************************
Problem: 2404
User: admin
Language: C++
Result: Wrong Answer
****************************************************************/