#include<bits/stdc++.h>
using namespace std;
int n;
int a[200009];
bool used[200009];
struct node{
int col,l,r;
};
queue<node>q1,q2;
int pos=1;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
freopen("fruit3.in","r",stdin);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
a[n+1]=10;
for(int i=2;i<=n+1;i++){
if(a[i]!=a[i-1]){
q1.push({a[i-1],pos,i-1});
pos=i;
}
}
int cnt=0,k=0;
while(cnt<n){
if(k==0){
while(!q1.empty()){
node u=q1.front();q1.pop();
int aim_r=u.r;
while(q1.front().col==u.col){
aim_r=q1.front().r;
q1.pop();
}
while(used[u.l]&&u.l<=aim_r) u.l++;
cout<<u.l<<" ",used[u.l]=1,cnt++;
node v={u.col,u.l+1,aim_r};
if(u.l+1<=aim_r){
q2.push(v);
}
}
}
if(k==1){
while(!q2.empty()){
node u=q2.front();q2.pop();
int aim_r=u.r;
while(q2.front().col==u.col){
aim_r=q2.front().r;
q2.pop();
}
while(used[u.l]&&u.l<=aim_r) u.l++;
cout<<u.l<<" ",used[u.l]=1,cnt++;
node v={u.col,u.l+1,aim_r};
if(u.l+1<=aim_r){
q1.push(v);
}
}
}
k^=1;
cout<<endl;
}
return 0;
}