#include <iostream>
#include <list>
using namespace std;
int n, c, m = 2;
list<list<int>> l; // 模拟多行水果结构
list<int> k; // 每一行水果编号
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &c);
if (m != c)
{
l.push_back(k);
m = c;
k.clear();
}
k.push_back(i);
}
l.push_back(k);
while (l.size())
{
auto i = l.begin();
while (i != l.end())
{
if (i->size() == 0 && (i == l.begin() || i == prev(l.end())))
{
i = l.erase(i);
}
else if (i->size() == 0)
{
auto pri = prev(i);
auto nxi = next(i);
pri->splice(pri->end(), *nxi);
i = l.erase(i);
i = l.erase(i);
}
else
{
printf("%d ", i->front());
i->pop_front();
i++;
}
if (i == l.end())
break;
}
printf("\n");
}
/*for(auto i=l.begin();i!=l.end();i++){
for(auto j=i->begin();j!=i->end();j++){
cout<<*j<<" ";
}
cout<<endl;
}*/
return 0;
}