# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define IOS ios_base :: sync_with_stdio(0)
int s[1 << 20];
int v[1 << 20];
pair < int , int > t[1 << 22];
void build(int p,int u,int node)
{
if (p == u) t[node] = {v[p],p};
else
{
int m = (p + u) / 2;
build(p,m,node << 1);
build(m+1,u,node << 1 | 1);
t[node] = max(t[node << 1],t[node << 1 | 1]);
}
}
void Del(int p,int u,int v,int node)
{
if (p == u) t[node] = {0,p};
else
{
int m = (p + u) / 2;
if (v <= m) Del(p,m,v,node << 1);
else Del(m+1,u,v,node << 1 | 1);
t[node] = max(t[node << 1],t[node << 1 | 1]);
}
}
pair < int , int > query(int p,int u,int l,int r,int node)
{
if (l > r) return {0,0};
if (l <= p && u <= r) return t[node];
int m = (p + u) / 2;
pair < int , int > ans = {0,0};
if (l <= m) ans = max(ans,query(p,m,l,r,node << 1));
if (m+1<=r) ans = max(ans,query(m+1,u,l,r,node << 1 | 1));
return ans;
}
int was[1 << 20];
int n;
vector < int > Sort;
void dfs(int node)
{
Del(1,n,node,1);
was[node] = 1;
if (v[node] != n + 1 && !was[v[node]]) dfs(v[node]);
while (1)
{
auto it = query(1,n,1,s[node] - 1,1);
if (it.x > node) dfs(it.y);
else break;
}
Sort.push_back(node);
}
int ans[1 << 20];
int main(void)
{
scanf("%d\n",&n);
for (int i = 1;i <= n;++i) v[i] = n + 1;
for (int i = 1;i <= n;++i) scanf("%d",&s[i]);
for (int i = 1;i <= n;++i)
if (s[i] != -1)
v[s[i]] = i;
for (int i = 1;i <= n;++i)
if (s[i] == -1)
s[i] = n + 1;
build(1,n,1);
for (int i = 1;i <= n;++i)
if (!was[i])
dfs(i);
int cnt = 0;
for (auto it : Sort)
ans[it] = ++cnt;
for (int i = 1;i <= n;++i)
printf("%d%c",ans[i]," \n"[i == n]);
return 0;
}
IyBpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojIGRlZmluZS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gaW50ID4gYW5zID0gezAsMH07CiAgICBpZiAobCA8PSBtKSBhbnMgPSBtYXgoYW5zLHF1ZXJ5KHAsbSxsLHIsbm9kZSA8PCAxKSk7CiAgICBpZiAobSsxPD1yKSBhbnMgPSBtYXgoYW5zLHF1ZXJ5KG0rMSx1LGwscixub2RlIDw8IDEgfCAxKSk7CiAgICByZXR1cm4gYW5zOwp9CmludCB3YXNbMSA8PCAyMF07CmludCBuOwp2ZWN0b3IgPCBpbnQgPiBTb3J0Owp2b2lkIGRmcyhpbnQgbm9kZSkKewogICAgRGVsKDEsbixub2RlLDEpOwogICAgd2FzW25vZGVdID0gMTsKICAgIGlmICh2W25vZGVdICE9IG4gKyAxICYmICF3YXNbdltub2RlXV0pIGRmcyh2W25vZGVdKTsKICAgIHdoaWxlICgxKQogICAgewogICAgICAgIGF1dG8gaXQgPSBxdWVyeSgxLG4sMSxzW25vZGVdIC0gMSwxKTsKICAgICAgICBpZiAoaXQueCA+IG5vZGUpIGRmcyhpdC55KTsKICAgICAgICBlbHNlIGJyZWFrOwogICAgfQogICAgU29ydC5wdXNoX2JhY2sobm9kZSk7Cn0KaW50IGFuc1sxIDw8IDIwXTsKaW50IG1haW4odm9pZCkKewogICAgc2NhbmYoIiVkXG4iLCZuKTsKICAgIGZvciAoaW50IGkgPSAxO2kgPD0gbjsrK2kpIHZbaV0gPSBuICsgMTsKICAgIGZvciAoaW50IGkgPSAxO2kgPD0gbjsrK2kpIHNjYW5mKCIlZCIsJnNbaV0pOwogICAgZm9yIChpbnQgaSA9IDE7aSA8PSBuOysraSkKICAgICAgICBpZiAoc1tpXSAhPSAtMSkKICAgICAgICAgICAgdltzW2ldXSA9IGk7CiAgICBmb3IgKGludCBpID0gMTtpIDw9IG47KytpKQogICAgICAgIGlmIChzW2ldID09IC0xKQogICAgICAgICAgICBzW2ldID0gbiArIDE7CiAgICBidWlsZCgxLG4sMSk7CiAgICBmb3IgKGludCBpID0gMTtpIDw9IG47KytpKQogICAgICAgIGlmICghd2FzW2ldKQogICAgICAgICAgICBkZnMoaSk7CiAgICBpbnQgY250ID0gMDsKICAgIGZvciAoYXV0byBpdCA6IFNvcnQpCiAgICAgICAgYW5zW2l0XSA9ICsrY250OwogICAgZm9yIChpbnQgaSA9IDE7aSA8PSBuOysraSkKICAgICAgICBwcmludGYoIiVkJWMiLGFuc1tpXSwiIFxuIltpID09IG5dKTsKICAgIHJldHVybiAwOwp9Cg==