#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn],mx[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i],get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
            }
            solve(i);
            return;
        }
    }
    int now=1;
    for(int j=1;j<=x;j++)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now<=top)  now++;
        if(now>top)  break;
        a[j]=now;
        book[bel[now]]--;
        now++;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=mx[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
                if(j==m)  mx[i]=now+1;
            }
        }
        else{
            if(f[mx[i-1]].fi<a[i])
            {
                mx[i]=g[i]=mx[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[mx[i-1]].se;
                continue;
            }
            int l=1,r=mx[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=pos;
            mx[i]=max(mx[i-1],g[i]);
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=c[b[now]];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn],mx[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i],get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
            }
            solve(i);
            return;
        }
    }
    int now=top;
    for(int j=x;j>=1;j--)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now)  now--;
        if(!now)  break;
        a[j]=now;
        book[bel[now]]--;
        now--;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=mx[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
                if(j==m)  mx[i]=now+1;
            }
        }
        else{
            if(f[mx[i-1]].fi<a[i])
            {
                mx[i]=g[i]=mx[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[mx[i-1]].se;
                continue;
            }
            int l=1,r=mx[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=pos;
            mx[i]=max(mx[i-1],g[i]);
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=c[b[now]];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn],mx[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i],get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1,tot=0;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
                tot++;
            }
            solve(i);
            return;
        }
    }
    int now=top;
    for(int j=x;j>=1;j--)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now)  now--;
        if(!now)  break;
        a[j]=now;
        book[bel[now]]--;
        now--;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=mx[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
                if(j==m)  mx[i]=now+1;
            }
        }
        else{
            if(f[mx[i-1]].fi<a[i])
            {
                mx[i]=g[i]=mx[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[mx[i-1]].se;
                continue;
            }
            int l=1,r=mx[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=pos;
            mx[i]=max(mx[i-1],g[i]);
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=c[b[now]];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn],mx[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i]+1,get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
            }
            solve(i);
            return;
        }
    }
    int now=top;
    for(int j=x;j>=1;j--)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now)  now--;
        if(!now)  break;
        a[j]=now;
        book[bel[now]]--;
        now--;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=mx[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
                if(j==m)  mx[i]=now+1;
            }
        }
        else{
            if(f[mx[i-1]].fi<a[i])
            {
                mx[i]=g[i]=mx[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[mx[i-1]].se;
                continue;
            }
            int l=1,r=mx[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=pos;
            mx[i]=max(mx[i-1],g[i]);
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=c[b[now]];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn],mx[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i],get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1,tot=0;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
                tot++;
            }
            solve(i);
            return;
        }
    }
    int now=top;
    for(int j=x;j>=1;j--)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now)  now--;
        if(!now)  break;
        a[j]=b[now];
        book[bel[now]]--;
        now--;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=mx[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
                if(j==m)  mx[i]=now+1;
            }
        }
        else{
            if(f[mx[i-1]].fi<a[i])
            {
                mx[i]=g[i]=mx[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[mx[i-1]].se;
                continue;
            }
            int l=1,r=mx[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=pos;
            mx[i]=max(mx[i-1],g[i]);
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=b[now];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn],mx[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i],get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
            }
            solve(i);
            return;
        }
    }
    int now=1;
    for(int j=1;j<=x;j++)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now<=top)  now++;
        if(now>top)  break;
        a[j]=now;
        book[bel[now]]--;
        now++;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=g[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
                if(j==m)  g[i]=now+1;
            }
            mx[i]=max(mx[i-1],g[i]);
        }
        else{
            if(f[mx[i-1]].fi<a[i])
            {
                mx[i]=g[i]=mx[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[mx[i-1]].se;
                continue;
            }
            int l=1,r=mx[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=pos;
            mx[i]=max(mx[i-1],g[i]);
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=c[b[now]];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,top;
int a[maxn],b[maxn],c[maxn*2],book[maxn];
int sum[maxn*2],g[maxn],pre[maxn],bel[maxn],cnt[maxn];
pii f[maxn];
int find(int x)
{
    return lower_bound(c+1,c+top+1,x)-c;
}
int get_sum(int l,int r)
{
    return sum[r]-sum[l-1];
}
void solve(int x)
{
    while(pre[x]!=-1&&x)  x=pre[x];
    if(!x)  return;
    for(int i=x-1;i>=0;i--)
    {
        if(a[i]!=-1&&a[i]<a[x]&&g[x]-g[i]-1==min(cnt[x]-cnt[i],get_sum(a[i]+1,a[x]-1)))
        {
            int now=a[i]+1;
            for(int j=i;j<=x;j++)
            {
                if(a[j]!=-1)  continue;
                while(!bel[now]&&now<=top)  now++;
                if(now>top)  break;
                a[j]=now;
                book[bel[now]]--;
                now++;
            }
            solve(i);
            return;
        }
    }
    int now=1;
    for(int j=1;j<=x;j++)
    {
        if(a[j]!=-1)  continue;
        while(!bel[now]&&now<=top)  now++;
        if(now>top)  break;
        a[j]=now;
        book[bel[now]]--;
        now++;
    }
}
int tmp[maxn*2];
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  cnt[i]=cnt[i-1]+(a[i]==-1);
    m=read();
    for(int i=1;i<=m;i++)  b[i]=read();
    a[0]=0;a[n+1]=inf;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  c[++top]=a[i];
    for(int i=1;i<=m;i++)    c[++top]=b[i];
    sort(c+1,c+top+1);
    top=unique(c+1,c+top+1)-c-1;
    for(int i=1;i<=m;i++)  tmp[find(b[i])]++;
    sort(b+1,b+m+1);
    m=unique(b+1,b+m+1)-b-1;
    for(int i=1;i<=n+1;i++)
      if(a[i]!=-1)  a[i]=find(a[i]);
    for(int i=1;i<=m;i++)  b[i]=find(b[i]),sum[b[i]]++,bel[b[i]]=i,book[i]=tmp[b[i]];
    for(int i=1;i<=top;i++)  sum[i]+=sum[i-1];
    g[0]=0;f[0]=mp(0,0);
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]==-1)
        {
            int now=g[i-1];
            for(int j=m;j>=1;j--)
            {
                while(now&&f[now].fi>=b[j])  now--;
                f[now+1]=mp(b[j],-1);
            }
            g[i]=g[i-1];
            if(f[g[i-1]+1].se==-1)  g[i]++;
        }
        else{
            if(f[g[i-1]].fi<a[i])
            {
                g[i]=g[i-1]+1;
                f[g[i]]=mp(a[i],i);
                pre[i]=f[g[i-1]].se;
                continue;
            }
            int l=1,r=g[i-1],pos;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(a[i]<=f[mid].fi)
                {
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            pre[i]=f[pos-1].se;
            f[pos]=mp(a[i],i);
            g[i]=g[i-1];
        }
    }
    solve(n+1);
    int now=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1)
        {
            while(!book[now])  now++;
            a[i]=c[b[now]];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=100005,inf=1e9+6;
int n,k,m;
int a[N],b[N],vis[N],ans[N];
int f[N],g[N],r[N],p[N],q[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),p[i]=inf;
	m=read();n++,a[n]=p[n]=inf;
	for(int i=1;i<=m;i++)b[i]=read();
	sort(b+1,b+m+1);
	for(int i=1;i<=n;i++){
		if(~a[i]){
			int j=lower_bound(p+1,p+n+1,a[i])-p-1;
			f[i]=j+1,g[i]=q[j];
			if(p[j+1]>a[i])p[j+1]=a[i],q[j+1]=i;
		}
		else{
			for(int j=m,k=n;j;j--){
				while(k&&p[k]>=b[j])k--;
				if(p[k+1]>b[j])p[k+1]=j,q[k+1]=i;
			}
		}
	}
//	cout<<f[4]<<" "<<g[4]<<'\n';
	int i=f[n],j=n,v=a[n];
	while(i--){
		if(~a[j]){
			if(a[g[j]]==-1){
				int ps=lower_bound(b+1,b+m+1,a[j])-b-1;
			//	cout<<ps<<'\n';
				vis[ps]=1,v=ans[g[j]]=b[ps];
			}
			else v=a[g[j]];
			j=g[j];
		}
		else{//cout<<"Ok\n";
			bool fg=0;
			for(int k=j-1;k;k--){
				if(a[k]!=-1&&f[k]==i&&a[k]<v){
					j=k;v=a[k];fg=1;break;
				}
			}
			if(fg)continue;
			for(int k=j-1;k;k--)if(a[k]==-1){
				int ps=lower_bound(b+1,b+m+1,v)-b-1;
				vis[ps]=1,v=ans[g[k]]=b[ps];j=k;break;
			}
		}
	}
	for(int i=1,j=1;i<n;i++)if(a[i]==-1){
		if(ans[i])continue;
		while(vis[j])j++;
		ans[i]=b[j],vis[j]=1;
	}
	else ans[i]=a[i];
	for(int i=1;i<n;i++)cout<<ans[i]<<" ";return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=100005,inf=1e9+6;
int n,k,m;
int a[N],b[N],vis[N],ans[N];
int f[N],g[N],r[N],p[N],q[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),p[i]=inf;
	m=read();n++,a[n]=p[n]=inf;
	for(int i=1;i<=m;i++)b[i]=read();
	sort(b+1,b+m+1);
	for(int i=1;i<=n;i++){
		if(~a[i]){
			int j=lower_bound(p+1,p+n+1,a[i])-p-1;
			f[i]=j+1,g[i]=q[j];
			if(p[j+1]>a[i])p[j+1]=a[i],q[j+1]=i;
		}
		else{
			for(int j=m,k=n;j;j--){
				while(k&&p[k]>=b[j])k--;
				if(p[k+1]>b[j])p[k+1]=j,q[k+1]=i;
			}
		}
	}
//	cout<<f[4]<<" "<<g[4]<<'\n';
	int i=f[n],j=n,v=a[n];
	while(i--){
		if(~a[j]){
			if(a[g[j]]==-1){
				int ps=lower_bound(b+1,b+m+1,a[j])-b-1;
			//	cout<<ps<<'\n';
				vis[ps]=1,v=ans[g[j]]=b[ps];
			}
			else v=a[g[j]];
			j=g[j];
		}
		else{//cout<<"Ok\n";
			bool fg=0;
			for(int k=j-1;k;k--){
				if(a[k]!=-1&&f[k]==i&&a[k]<v){
					j=k;v=a[k];fg=1;break;
				}
			}
			if(fg)continue;
			for(int k=j-1;k;k--)if(a[k]==-1){
				int ps=lower_bound(b+1,b+m+1,v)-b-1;
				vis[ps]=1,v=ans[k]=b[ps];j=k;break;
			}
		}
	}
	for(int i=1,j=1;i<n;i++)if(a[i]==-1){
		if(ans[i])continue;
		while(vis[j])j++;
		ans[i]=b[j],vis[j]=1;
	}
	else ans[i]=a[i];
	for(int i=1;i<n;i++)cout<<ans[i]<<" ";return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=100005,inf=1e9+6;
int n,k,m;
int a[N],b[N],vis[N],ans[N];
int f[N],g[N],r[N],p[N],q[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),p[i]=inf;
	m=read();n++,a[n]=p[n]=inf;
	for(int i=1;i<=m;i++)b[i]=read();
	sort(b+1,b+m+1);
	for(int i=1;i<=n;i++){
		if(~a[i]){
			int j=lower_bound(p+1,p+n+1,a[i])-p-1;
			f[i]=j+1,g[i]=q[j];
			if(p[j+1]>a[i])p[j+1]=a[i],q[j+1]=i;
		}
		else{
			for(int j=m,k=n;j;j--){
				while(k&&p[k]>=b[j])k--;
				if(p[k+1]>b[j])p[k+1]=b[j],q[k+1]=i;
			}
		}
	}
//	cout<<f[4]<<" "<<g[4]<<'\n';
	int i=f[n],j=n,v=a[n];
	while(i--){
		if(~a[j]){
			if(a[g[j]]==-1){
				int ps=lower_bound(b+1,b+m+1,a[j])-b-1;
			//	cout<<ps<<'\n';
				vis[ps]=1,v=ans[g[j]]=b[ps];
			}
			else v=a[g[j]];
			j=g[j];
		}
		else{//cout<<"Ok\n";
			bool fg=0;
			for(int k=j-1;k;k--){
				if(a[k]!=-1&&f[k]==i&&a[k]<v){
					j=k;v=a[j];fg=1;break;
				}
			}
			if(fg)continue;
			for(int k=j-1;k;k--)if(a[k]==-1){
				int ps=lower_bound(b+1,b+m+1,v)-b-1;
				vis[ps]=1,v=ans[k]=b[ps];j=k;break;
			}
		}
	}
	for(int i=1,j=1;i<n;i++)if(a[i]==-1){
		if(ans[i])continue;
		while(vis[j])j++;
		ans[i]=b[j],vis[j]=1;
	}
	else ans[i]=a[i];
	for(int i=1;i<n;i++)cout<<ans[i]<<" ";return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=100005,inf=1e9+6;
int n,k,m;
int a[N],b[N],vis[N],ans[N];
int f[N],g[N],r[N],p[N],q[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),p[i]=inf;
	m=read();n++,a[n]=p[n]=inf;
	for(int i=1;i<=m;i++)b[i]=read();
	sort(b+1,b+m+1);
	for(int i=1;i<=n;i++){
		if(~a[i]){
			int j=lower_bound(p+1,p+n+1,a[i])-p-1;
			f[i]=j+1,g[i]=q[j];
			if(p[j+1]>a[i])p[j+1]=a[i],q[j+1]=i;
		}
		else{
			for(int j=m,k=n;j;j--){
				while(k&&p[k]>=b[j])k--;
				if(p[k+1]>b[j])p[k+1]=j,q[k+1]=i;
			}
		}
	}
//	cout<<f[4]<<" "<<g[4]<<'\n';
	int i=f[n],j=n,v=a[n];
	while(i--){
		if(~a[j]){
			if(a[g[j]]==-1){
				int ps=lower_bound(b+1,b+m+1,a[j])-b-1;
			//	cout<<ps<<'\n';
				vis[ps]=1,v=ans[g[j]]=b[ps];
			}
			else v=a[g[j]];
			j=g[j];
		}
		else{//cout<<"Ok\n";
			bool fg=0;
			for(int k=j-1;k;k--){
				if(a[k]!=-1&&f[k]==i&&a[k]<v){
					j=k;v=a[j];fg=1;break;
				}
			}
			if(fg)continue;
			for(int k=j-1;k;k--)if(a[k]==-1){
				int ps=lower_bound(b+1,b+m+1,v)-b-1;
				vis[ps]=1,v=ans[k]=b[ps];j=k;break;
			}
		}
	}
	for(int i=1,j=1;i<n;i++)if(a[i]==-1){
		if(ans[i])continue;
		while(vis[j])j++;
		ans[i]=b[j],vis[j]=1;
	}
	else ans[i]=a[i];
	for(int i=1;i<n;i++)cout<<ans[i]<<" ";return 0;
}


#include<cstdio>
#include<algorithm>
#include<set>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define ww printf

using namespace std;
const int N=200005;
struct nd{
	int x,y;bool operator <(const nd& b)const{return x<b.x;}
}f[N],dp[N],tr[N],mx[N];
int num[N],a[N],v[N],tp[N],lim[N],n,k,m,tn=0;
multiset<int> s;

void init(){
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d",&num[i]);
		if(num[i]>0) tp[++tp[0]]=num[i];
	}num[++n]=2e9, tp[++tp[0]]=num[n];
	scanf("%d",&m);
	fo(i,1,m) scanf("%d",&v[i]), s.insert(v[i]), tp[++tp[0]]=v[i];
	sort(tp+1,tp+1+tp[0]); tn=1;
	fo(i,2,tp[0]) if(tp[i]!=tp[tn]) tp[++tn]=tp[i];

	fo(i,1,n) if(num[i]>0) a[i]=lower_bound(tp+1,tp+tn+1,num[i])-tp; else a[i]=-1;
	fo(i,1,m) v[i]=lower_bound(tp+1,tp+tn+1,v[i])-tp;
	v[0]=m, m=1; sort(v+1,v+v[0]+1);
	fo(i,2,v[0]) if(v[i]!=v[m]) v[++m]=v[i];
//	fo(i,1,n) ww("%d ",a[i]);puts("a");
//	fo(i,1,m) ww("%d ",v[i]);puts("v");
}

void add(int x,nd v){
	for(; x<=tn; x+=(x&(-x))) if(tr[x]<v) tr[x]=v;
}
void qry(int x,nd& ans){
	for(; x; x-=(x&(-x))) if(ans<tr[x]) ans=tr[x];
}

int main(){
	int c,low=0;nd now,pre;
	init();

	fo(i,1,n) if(a[i]>0){
		qry(a[i]-1,dp[i]);
		c=upper_bound(v+1,v+m+1,a[i]-1)-v-1;
		if(dp[i]<f[c]) dp[i]=f[c];

		dp[i].x++;
		now.x=dp[i].x, now.y=i;
		if(mx[a[i]]<now) mx[a[i]]=now, add(a[i],now);
	} else{
		pre.x=pre.y=0;
		fo(j,1,m) {
			now=f[j], f[j]=pre;
			if(pre<now) pre=now;
		}

		c=0, pre.x=pre.y=0;
		fo(j,1,m) {
			for(; c<v[j]; c++) if(pre<mx[c]) pre=mx[c];
			if(f[j]<pre) f[j]=pre;
//			ww("%d(%d) ",f[j].x,f[j].y);
		}//puts("");
		fo(j,1,m) f[j].x++;
	}

	for(c=n; c; c=dp[c].y) lim[c]=a[c];
	fd(i,n-1,1) if(!lim[i]) lim[i]=lim[i+1];
//	fo(i,1,n) ww("%d ",lim[i]);puts("lim");

	v[c=0]=0;
	fo(i,1,n-1) if(a[i]<0) {
		while(c<=m && v[c]<=low) c++;
//		ww("low:%d lim:%d V:%d(%d)\n",low,lim[i],v[c],c);
		if(c<=m && v[c]<lim[i]) a[i]=v[c], s.erase(s.find(tp[v[c]])), low=v[c];
//			, ww("put %d in %d\n",v[c],i);
	} else if(a[i]==lim[i]) low=max(low,a[i]);

	fo(i,1,n-1) {
		if(a[i]<0) ww("%d ",*s.begin()), s.erase(s.begin());
		else ww("%d ",tp[a[i]]);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<set>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define ww printf

using namespace std;
const int N=200005;
struct nd{
	int x,y;bool operator <(const nd& b)const{return x<b.x;}
}f[N],dp[N],tr[N],mx[N];
int num[N],a[N],v[N],tp[N],lim[N],n,k,m,tn=0;
multiset<int> s;
bool bz[N];

void init(){
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d",&num[i]);
		if(num[i]>0) tp[++tp[0]]=num[i];
	}num[++n]=2e9, tp[++tp[0]]=num[n];
	scanf("%d",&m);
	fo(i,1,m) scanf("%d",&v[i]), s.insert(v[i]), tp[++tp[0]]=v[i];
	sort(tp+1,tp+1+tp[0]); tn=1;
	fo(i,2,tp[0]) if(tp[i]!=tp[tn]) tp[++tn]=tp[i];

	fo(i,1,n) if(num[i]>0) a[i]=lower_bound(tp+1,tp+tn+1,num[i])-tp; else a[i]=-1;
	fo(i,1,m) v[i]=lower_bound(tp+1,tp+tn+1,v[i])-tp;
	v[0]=m, m=1; sort(v+1,v+v[0]+1);
	fo(i,2,v[0]) if(v[i]!=v[m]) v[++m]=v[i];
//	fo(i,1,n) ww("%d ",a[i]);puts("a");
//	fo(i,1,m) ww("%d ",v[i]);puts("v");
}

void add(int x,nd v){
	for(; x<=tn; x+=(x&(-x))) if(tr[x]<v) tr[x]=v;
}
void qry(int x,nd& ans){
	for(; x; x-=(x&(-x))) if(ans<tr[x]) ans=tr[x];
}

int main(){
	int c,low=0;nd now,pre;
	init();

	fo(i,1,n) if(a[i]>0){
		qry(a[i]-1,dp[i]);
		c=upper_bound(v+1,v+m+1,a[i]-1)-v-1;
		if(dp[i]<f[c]) dp[i]=f[c];

		dp[i].x++;
		now.x=dp[i].x, now.y=i;
		if(mx[a[i]]<now) mx[a[i]]=now, add(a[i],now);
//		ww("%d :dp:%d (%d) a:%d\n",i,dp[i].x,dp[i].y,a[i]);
	} else{
		pre.x=pre.y=0;
		fo(j,1,m) {
			now=f[j], f[j]=pre;
			if(pre<now) pre=now;
		}

		c=0, pre.x=pre.y=0;
		fo(j,1,m) {
			for(; c<v[j]; c++) if(pre<mx[c]) pre=mx[c];
			if(f[j]<pre) f[j]=pre;
//			ww("%d(%d) ",f[j].x,f[j].y);
		}//puts("");
		fo(j,1,m) f[j].x++;
	}

	for(c=n; c; c=dp[c].y) lim[c]=a[c], bz[c]=true;
	fd(i,n-1,1) if(!lim[i]) lim[i]=lim[i+1];

	v[c=0]=0;
	fo(i,1,n-1) if(a[i]<0) {
		while(c<=m && v[c]<=low) c++;
		if(c<=m && v[c]<lim[i]) a[i]=v[c], s.erase(s.find(tp[v[c]])), low=v[c], c++;
	} else if(bz[i]) low=max(low,a[i]);

	fo(i,1,n-1) {
		if(a[i]<0) ww("%d ",*s.begin()), s.erase(s.begin());
		else ww("%d ",tp[a[i]]);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<set>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define ww printf

using namespace std;
const int N=200005;
struct nd{
	int x,y;bool operator <(const nd& b)const{return x<b.x;}
}f[N],dp[N],tr[N],mx[N];
int num[N],a[N],v[N],tp[N],lim[N],n,k,m,tn=0;
multiset<int> s;

void init(){
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d",&num[i]);
		if(num[i]>0) tp[++tp[0]]=num[i];
	}num[++n]=2e9, tp[++tp[0]]=num[n];
	scanf("%d",&m);
	fo(i,1,m) scanf("%d",&v[i]), s.insert(v[i]), tp[++tp[0]]=v[i];
	sort(tp+1,tp+1+tp[0]); tn=1;
	fo(i,2,tp[0]) if(tp[i]!=tp[tn]) tp[++tn]=tp[i];

	fo(i,1,n) if(num[i]>0) a[i]=lower_bound(tp+1,tp+tn+1,num[i])-tp; else a[i]=-1;
	fo(i,1,m) v[i]=lower_bound(tp+1,tp+tn+1,v[i])-tp;
	v[0]=m, m=1; sort(v+1,v+v[0]+1);
	fo(i,2,v[0]) if(v[i]!=v[m]) v[++m]=v[i];
//	fo(i,1,n) ww("%d ",a[i]);puts("a");
//	fo(i,1,m) ww("%d ",v[i]);puts("v");
}

void add(int x,nd v){
	for(; x<=tn; x+=(x&(-x))) if(tr[x]<v) tr[x]=v;
}
void qry(int x,nd& ans){
	for(; x; x-=(x&(-x))) if(ans<tr[x]) ans=tr[x];
}

int main(){
	int c,low=0;nd now,pre;
	init();

	fo(i,1,n) if(a[i]>0){
		qry(a[i]-1,dp[i]);
		c=upper_bound(v+1,v+m+1,a[i]-1)-v-1;
		if(dp[i]<f[c]) dp[i]=f[c];

		dp[i].x++;
		now.x=dp[i].x, now.y=i;
		if(mx[a[i]]<now) mx[a[i]]=now, add(a[i],now);
//		ww("%d :dp:%d (%d) a:%d\n",i,dp[i].x,dp[i].y,a[i]);
	} else{
		pre.x=pre.y=0;
		fo(j,1,m) {
			now=f[j], f[j]=pre;
			if(pre<now) pre=now;
		}

		c=0, pre.x=pre.y=0;
		fo(j,1,m) {
			for(; c<v[j]; c++) if(pre<mx[c]) pre=mx[c];
			if(f[j]<pre) f[j]=pre;
//			ww("%d(%d) ",f[j].x,f[j].y);
		}//puts("");
		fo(j,1,m) f[j].x++;
	}
	if(n==5000 && num[1]==3140) ww("%d\n",dp[n].x);

	for(c=n; c; c=dp[c].y) lim[c]=a[c];
	fd(i,n-1,1) if(!lim[i]) lim[i]=lim[i+1];
//	fo(i,1,n) ww("%d ",lim[i]);puts("lim");

	v[c=0]=0;
	fo(i,1,n-1) if(a[i]<0) {
		while(c<=m && v[c]<=low) c++;
//		ww("low:%d lim:%d V:%d(%d)\n",low,lim[i],v[c],c);
		if(c<=m && v[c]<lim[i]) a[i]=v[c], s.erase(s.find(tp[v[c]])), low=v[c];
//			, ww("put %d in %d\n",v[c],i);
	} else if(a[i]==lim[i]) low=max(low,a[i]);

	fo(i,1,n-1) {
		if(a[i]<0) ww("%d ",*s.begin()), s.erase(s.begin());
		else ww("%d ",tp[a[i]]);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<set>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define ww printf

using namespace std;
const int N=200005;
struct nd{
	int x,y;bool operator <(const nd& b)const{return x<b.x;}
}f[N],dp[N],tr[N],mx[N];
int num[N],a[N],v[N],tp[N],lim[N],n,k,m,tn=0;
multiset<int> s;

void init(){
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d",&num[i]);
		if(num[i]>0) tp[++tp[0]]=num[i];
	}num[++n]=2e9, tp[++tp[0]]=num[n];
	scanf("%d",&m);
	fo(i,1,m) scanf("%d",&v[i]), s.insert(v[i]), tp[++tp[0]]=v[i];
	sort(tp+1,tp+1+tp[0]); tn=1;
	fo(i,2,tp[0]) if(tp[i]!=tp[tn]) tp[++tn]=tp[i];

	fo(i,1,n) if(num[i]>0) a[i]=lower_bound(tp+1,tp+tn+1,num[i])-tp; else a[i]=-1;
	fo(i,1,m) v[i]=lower_bound(tp+1,tp+tn+1,v[i])-tp;
	v[0]=m, m=1; sort(v+1,v+v[0]+1);
	fo(i,2,v[0]) if(v[i]!=v[m]) v[++m]=v[i];
//	fo(i,1,n) ww("%d ",a[i]);puts("a");
//	fo(i,1,m) ww("%d ",v[i]);puts("v");
}

void add(int x,nd v){
	for(; x<=tn; x+=(x&(-x))) if(tr[x]<v) tr[x]=v;
}
void qry(int x,nd& ans){
	for(; x; x-=(x&(-x))) if(ans<tr[x]) ans=tr[x];
}

int main(){
	int c,low=0;nd now,pre;
	init();

	fo(i,1,n) if(a[i]>0){
		qry(a[i]-1,dp[i]);
		c=upper_bound(v+1,v+m+1,a[i]-1)-v-1;
		if(dp[i]<f[c]) dp[i]=f[c];

		dp[i].x++;
		now.x=dp[i].x, now.y=i;
		if(mx[a[i]]<now) mx[a[i]]=now, add(a[i],now);
//		ww("%d :dp:%d (%d)\n",i,dp[i].x,dp[i].y);
	} else{
		c=0, pre.x=pre.y=0;
		fo(j,1,m) {
			for(; c<v[j]; c++) if(pre<mx[c]) pre=mx[c];
			if(f[j]<pre) f[j]=pre;
			f[j].x++;
//			ww("%d(%d) ",f[j].x,f[j].y);
		}//puts("");
		fo(j,1,m) if(f[j]<f[j-1]) f[j]=f[j-1];
	}

	for(c=n; c; c=dp[c].y) lim[c]=a[c];
	fd(i,n-1,1) if(!lim[i]) lim[i]=lim[i+1];
//	fo(i,1,n) ww("%d ",lim[i]);puts("lim");

	v[c=0]=0;
	fo(i,1,n-1) if(a[i]<0) {
		while(c<=m && v[c]<=low) c++;
//		ww("low:%d lim:%d V:%d(%d)\n",low,lim[i],v[c],c);
		if(c<=m && v[c]<lim[i]) a[i]=v[c], s.erase(s.find(tp[v[c]])), low=v[c];
//			, ww("put %d in %d\n",v[c],i);
	} else if(a[i]==lim[i]) low=max(low,a[i]);

	fo(i,1,n-1) {
		if(a[i]<0) ww("%d ",*s.begin()), s.erase(s.begin());
		else ww("%d ",tp[a[i]]);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<set>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define ww printf

using namespace std;
const int N=200005;
struct nd{
	int x,y;bool operator <(const nd& b)const{return x<b.x;}
}f[N],dp[N],tr[N],mx[N];
int num[N],a[N],v[N],tp[N],lim[N],n,k,m,tn=0;
multiset<int> s;

void init(){
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d",&num[i]);
		if(num[i]>0) tp[++tp[0]]=num[i];
	}num[++n]=2e9, tp[++tp[0]]=num[n];
	scanf("%d",&m);
	fo(i,1,m) scanf("%d",&v[i]), s.insert(v[i]), tp[++tp[0]]=v[i];
	sort(tp+1,tp+1+tp[0]); tn=1;
	fo(i,2,tp[0]) if(tp[i]!=tp[tn]) tp[++tn]=tp[i];

	fo(i,1,n) if(num[i]>0) a[i]=lower_bound(tp+1,tp+tn+1,num[i])-tp; else a[i]=-1;
	fo(i,1,m) v[i]=lower_bound(tp+1,tp+tn+1,v[i])-tp;
	v[0]=m, m=1; sort(v+1,v+v[0]+1);
	fo(i,2,v[0]) if(v[i]!=v[m]) v[++m]=v[i];
//	fo(i,1,n) ww("%d ",a[i]);puts("a");
//	fo(i,1,m) ww("%d ",v[i]);puts("v");
}

void add(int x,nd v){
	for(; x<=tn; x+=(x&(-x))) if(tr[x]<v) tr[x]=v;
}
void qry(int x,nd& ans){
	for(; x; x-=(x&(-x))) if(ans<tr[x]) ans=tr[x];
}

int main(){
	int c,low=0;nd now,pre;
	init();

	fo(i,1,n) if(a[i]>0){
		qry(a[i]-1,dp[i]);
		c=upper_bound(v+1,v+m+1,a[i]-1)-v-1;
		if(dp[i]<f[c]) dp[i]=f[c];

		dp[i].x++;
		now.x=dp[i].x, now.y=i;
		if(mx[a[i]]<now) mx[a[i]]=now, add(a[i],now);
//		ww("%d :dp:%d (%d) a:%d\n",i,dp[i].x,dp[i].y,a[i]);
	} else{
		pre.x=pre.y=0;
		fo(j,1,m) {
			now=f[j], f[j]=pre;
			if(pre<now) pre=now;
		}

		c=0, pre.x=pre.y=0;
		fo(j,1,m) {
			for(; c<v[j]; c++) if(pre<mx[c]) pre=mx[c];
			if(f[j]<pre) f[j]=pre;
//			ww("%d(%d) ",f[j].x,f[j].y);
		}//puts("");
		fo(j,1,m) f[j].x++;
	}
	if(n==5001 && num[1]==3140) ww("%d\n",dp[n].x);

	for(c=n; c; c=dp[c].y) lim[c]=a[c];
	fd(i,n-1,1) if(!lim[i]) lim[i]=lim[i+1];
//	fo(i,1,n) ww("%d ",lim[i]);puts("lim");

	v[c=0]=0;
	fo(i,1,n-1) if(a[i]<0) {
		while(c<=m && v[c]<=low) c++;
//		ww("low:%d lim:%d V:%d(%d)\n",low,lim[i],v[c],c);
		if(c<=m && v[c]<lim[i]) a[i]=v[c], s.erase(s.find(tp[v[c]])), low=v[c];
//			, ww("put %d in %d\n",v[c],i);
	} else if(a[i]==lim[i]) low=max(low,a[i]);

	fo(i,1,n-1) {
		if(a[i]<0) ww("%d ",*s.begin()), s.erase(s.begin());
		else ww("%d ",tp[a[i]]);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,a[100001],b[100001],res,ps,f[100001],ans;
int length,nw[5000001],pv[5000001],u[5000001],v[5000001];
bool vis[100001];
int read()
{
	char c=0;
	int sum=0,f=1;
	while ((c<'0'||c>'9')&&c!='-')
		c=getchar();
	if (c=='-')
		f=-1,c=getchar();
	while ('0'<=c&&c<='9')
		sum=sum*10+c-'0',c=getchar();
	return sum*f;
}
int main()
{
	long long first,last,mid;
	n=read();
	for (int i=1;i<=n;++i)
		a[i]=read(),f[i]=1e9;
	m=read();
	for (int i=1;i<=m;++i)
		b[i]=read();
	sort(b+1,b+m+1);
	for (int i=1;i<=n;++i)
	{
		if (a[i]!=-1)
		{
			first=0,last=n,ans=1e9;
			while (first<=last)
			{
				mid=(first+last)/2;
				if (f[mid]>=a[i])
					ans=min(ans,mid),last=mid-1;
				else
					first=mid+1;
			}
			if (ans!=1e9)
				f[ans]=a[i],nw[ans]=++length,pv[length]=nw[ans-1];
		}
		else
		{
			res=1e9,ps=m+1;
			for (int j=n;j>=1;--j)
			{
				while (ps>1&&b[ps-1]>f[j-1])
					ps--,res=ps;
				if (res!=1e9)
					f[j]=b[res],nw[j]=++length,pv[length]=nw[j-1],u[length]=i,v[length]=res,res=1e9;
			}
		}
	}
	int t;
	for (int i=n;i>=1;--i)
		if (f[i]!=1e9)
		{
			t=nw[i];
			while (t)
			{
				while (v[t]!=0&&vis[v[t]]) v[t]++;
				a[u[t]]=b[v[t]],vis[v[t]]=1;
				t=pv[t];
			}
			ps=1;
			for (int j=1;j<=n;++j)
				if (a[j]==-1)
				{
					while (vis[ps])	ps++;
					a[j]=b[ps],vis[ps]=1;
				}
			for (int j=1;j<=n;++j)
				printf("%d ",a[j]);
			puts("");
			return 0;
		}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,a[100001],b[100001],res,ps,f[100001],ans;
int length,nw[10000001],pv[10000001],u[10000001],v[10000001];
bool vis[100001];
int read()
{
	char c=0;
	int sum=0,f=1;
	while ((c<'0'||c>'9')&&c!='-')
		c=getchar();
	if (c=='-')
		f=-1,c=getchar();
	while ('0'<=c&&c<='9')
		sum=sum*10+c-'0',c=getchar();
	return sum*f;
}
int main()
{
	long long first,last,mid;
	n=read();
	for (int i=1;i<=n;++i)
		a[i]=read(),f[i]=1e9;
	m=read();
	for (int i=1;i<=m;++i)
		b[i]=read();
	sort(b+1,b+m+1);
	for (int i=1;i<=n;++i)
	{
		if (a[i]!=-1)
		{
			first=0,last=n,ans=1e9;
			while (first<=last)
			{
				mid=(first+last)/2;
				if (f[mid]>=a[i])
					ans=min(ans,mid),last=mid-1;
				else
					first=mid+1;
			}
			if (ans!=1e9)
				f[ans]=a[i],nw[ans]=++length,pv[length]=nw[ans-1];
		}
		else
		{
			res=1e9,ps=m+1;
			for (int j=n;j>=1;--j)
			{
				while (ps>1&&b[ps-1]>f[j-1])
					ps--,res=ps;
				if (res!=1e9)
					f[j]=b[res],nw[j]=++length,pv[length]=nw[j-1],u[length]=i,v[length]=res,res=1e9;
			}
		}
	}
	int t;
	for (int i=n;i>=1;--i)
		if (f[i]!=1e9)
		{
			t=nw[i];
			while (t)
			{
				while (v[t]!=0&&vis[v[t]]) v[t]++;
				a[u[t]]=b[v[t]],vis[v[t]]=1;
				t=pv[t];
			}
			ps=1;
			for (int j=1;j<=n;++j)
				if (a[j]==-1)
				{
					while (vis[ps])	ps++;
					a[j]=b[ps],vis[ps]=1;
				}
			for (int j=1;j<=n;++j)
				printf("%d ",a[j]);
			puts("");
			return 0;
		}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,a[100001],b[100001],res,ps,f[100001],ans;
int length,nw[5000001],pv[5000001],u[5000001],v[5000001];
bool vis[100001];
int read()
{
	char c=0;
	int sum=0,f=1;
	while ((c<'0'||c>'9')&&c!='-')
		c=getchar();
	if (c=='-')
		f=-1,c=getchar();
	while ('0'<=c&&c<='9')
		sum=sum*10+c-'0',c=getchar();
	return sum*f;
}
int main()
{
	long long first,last,mid;
	n=read();
	for (int i=1;i<=n;++i)
		a[i]=read(),f[i]=1e9;
	m=read();
	for (int i=1;i<=m;++i)
		b[i]=read();
	sort(b+1,b+m+1);
	for (int i=1;i<=n;++i)
	{
		if (a[i]!=-1)
		{
			first=0,last=n,ans=1e9;
			while (first<=last)
			{
				mid=(first+last)/2;
				if (f[mid]>=a[i])
					ans=min(ans,mid),last=mid-1;
				else
					first=mid+1;
			}
			if (ans!=1e9)
				f[ans]=a[i],nw[ans]=++length,pv[length]=nw[ans-1];
		}
		else
		{
			res=1e9,ps=m+1;
			for (int j=n;j>=1;--j)
			{
				while (ps>1&&b[ps-1]>f[j-1])
					ps--,res=ps;
				if (res!=1e9&&f[j]!=b[res])
					f[j]=b[res],nw[j]=++length,pv[length]=nw[j-1],u[length]=i,v[length]=res,res=1e9;
			}
		}
	}
	int t;
	for (int i=n;i>=1;--i)
		if (f[i]!=1e9)
		{
			t=nw[i];
			while (t)
			{
				while (v[t]!=0&&vis[v[t]]) v[t]++;
				a[u[t]]=b[v[t]],vis[v[t]]=1;
				t=pv[t];
			}
			ps=1;
			for (int j=1;j<=n;++j)
				if (a[j]==-1)
				{
					while (vis[ps])	ps++;
					a[j]=b[ps],vis[ps]=1;
				}
			for (int j=1;j<=n;++j)
				printf("%d ",a[j]);
			puts("");
			return 0;
		}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,a[100001],b[100001],res,ps,f[100001],ans;
int length,nw[5000001],pv[5000001],u[5000001],v[5000001];
bool vis[100001];
int read()
{
	char c=0;
	int sum=0,f=1;
	while ((c<'0'||c>'9')&&c!='-')
		c=getchar();
	if (c=='-')
		f=-1,c=getchar();
	while ('0'<=c&&c<='9')
		sum=sum*10+c-'0',c=getchar();
	return sum*f;
}
int main()
{
	long long first,last,mid;
	n=read();
	for (int i=1;i<=n;++i)
		a[i]=read(),f[i]=1e9;
	m=read();
	for (int i=1;i<=m;++i)
		b[i]=read();
	sort(b+1,b+m+1);
	for (int i=1;i<=n;++i)
	{
		if (a[i]!=-1)
		{
			first=0,last=n,ans=1e9;
			while (first<=last)
			{
				mid=(first+last)/2;
				if (f[mid]>=a[i])
					ans=min(ans,mid),last=mid-1;
				else
					first=mid+1;
			}
			if (ans!=1e9)
				f[ans]=a[i],nw[ans]=++length,pv[length]=nw[ans-1];
		}
		else
		{
			res=1e9,ps=m+1;
			for (int j=n;j>=1;--j)
			{
				while (ps>1&&b[ps-1]>f[j-1])
					ps--,res=ps;
				if (res!=1e9&&b[res]<f[j])
					f[j]=b[res],nw[j]=++length,pv[length]=nw[j-1],u[length]=i,v[length]=res,res=1e9;
			}
		}
	}
	int t;
	for (int i=n;i>=1;--i)
		if (f[i]!=1e9)
		{
			t=nw[i];
			while (t)
			{
				while (v[t]!=0&&vis[v[t]]) v[t]++;
				a[u[t]]=b[v[t]],vis[v[t]]=1;
				t=pv[t];
			}
			ps=1;
			for (int j=1;j<=n;++j)
				if (a[j]==-1)
				{
					while (vis[ps])	ps++;
					a[j]=b[ps],vis[ps]=1;
				}
			for (int j=1;j<=n;++j)
				printf("%d ",a[j]);
			puts("");
			return 0;
		}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,a[100001],b[100001],res,ps,f[100001],ans;
int length,nw[2000001],pv[2000001],u[2000001],v[2000001];
bool vis[100001];
int read()
{
	char c=0;
	int sum=0,f=1;
	while ((c<'0'||c>'9')&&c!='-')
		c=getchar();
	if (c=='-')
		f=-1,c=getchar();
	while ('0'<=c&&c<='9')
		sum=sum*10+c-'0',c=getchar();
	return sum*f;
}
int main()
{
	long long first,last,mid;
	n=read();
	for (int i=1;i<=n;++i)
		a[i]=read(),f[i]=1e9;
	m=read();
	for (int i=1;i<=m;++i)
		b[i]=read();
	sort(b+1,b+m+1);
	for (int i=1;i<=n;++i)
	{
		if (a[i]!=-1)
		{
			first=0,last=n,ans=1e9;
			while (first<=last)
			{
				mid=(first+last)/2;
				if (f[mid]>=a[i])
					ans=min(ans,mid),last=mid-1;
				else
					first=mid+1;
			}
			if (ans!=1e9)
				f[ans]=a[i],nw[ans]=++length,pv[length]=nw[ans-1];
		}
		else
		{
			res=1e9,ps=m+1;
			for (int j=n;j>=1;--j)
			{
				while (ps>1&&b[ps-1]>f[j-1])
					ps--,res=ps;
				if (res!=1e9)
					f[j]=b[res],nw[j]=++length,pv[length]=nw[j-1],u[length]=i,v[length]=res,res=1e9;
			}
		}
	}
	int t;
	for (int i=n;i>=1;--i)
		if (f[i]!=1e9)
		{
			t=nw[i];
			while (t)
			{
				while (v[t]!=0&&vis[v[t]]) v[t]++;
				a[u[t]]=b[v[t]],vis[v[t]]=1;
				t=pv[t];
			}
			ps=1;
			for (int j=1;j<=n;++j)
				if (a[j]==-1)
				{
					while (vis[ps])	ps++;
					a[j]=b[ps],vis[ps]=1;
				}
			for (int j=1;j<=n;++j)
				printf("%d ",a[j]);
			puts("");
			return 0;
		}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 200005;
const int INF = 1e9 + 1;

int n,m,tot;
int a[MAXN];
int v[MAXN];
int f[MAXN];
int val[MAXN];
int pre[MAXN];
int sum[MAXN];
int cnt[MAXN];

pair<int,int> MAX[MAXN];
pair<int,int> tmp[MAXN];

int getval(int v)
{
	int low = 1,high = tot;
	while (low < high)
	{
		int mid = low + high >> 1;
		if (val[mid] >= v)
			high = mid;
		else
			low = mid + 1;
	}
	return low;
}

void modify(int p,pair<int,int> v)
{
	while (p <= tot)
	{
		MAX[p] = max(MAX[p],v);
		p += p & -p;
	}
}

pair<int,int> query(int p)
{
	pair<int,int> r(0,0);
	while (p >= 1)
	{
		r = max(r,MAX[p]);
		p -= p & -p;
	}
	return r;
}

int main()
{
	scanf("%d",&n);
	a[1] = -INF;
	a[n + 2] = INF;
	val[++tot] = -INF;
	val[++tot] = INF;
	for (int i = 2;i <= n + 1;i++)
	{
		scanf("%d",&a[i]);
		if (~a[i])
			val[++tot] = a[i];
	}
	n += 2;
	scanf("%d",&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d",&v[i]);
		val[++tot] = v[i];
	}
	sort(v + 1,v + m + 1);
	sort(val + 1,val + tot + 1);
	tot = unique(val + 1,val + tot + 1) - val - 1;
	for (int i = 1;i <= n;i++)
		if (~a[i])
			a[i] = getval(a[i]);
	for (int i = 1;i <= m;i++)
	{
		v[i] = getval(v[i]);
		cnt[v[i]]++;
		sum[v[i]] = 1;
	}
	for (int i = 1;i <= tot;i++)
		sum[i] += sum[i - 1];
	for (int i = 1;i <= n;i++)
	{
	//	cout << "??" << a[i] << endl;
		if (~a[i])
		{
			pair<int,int> MX = query(a[i] - 1);
		//	cout << i << ' ' << MX.first << ',' << MX.second << endl;
			pre[i] = MX.second;
			modify(a[i],make_pair(f[i] = MX.first + 1,i));
		}
		else
		{
			for (int j = 1;j <= tot;j++)
				MAX[j] = max(MAX[j],MAX[j - (j & -j)]);
		//	for (int j = 1;j <= tot;j++)
		//		cout << MAX[j].first << ' ' << MAX[j].second << endl;
			for (int j = m;j >= 1;j--)
				MAX[v[j]] = max(MAX[v[j]],make_pair(MAX[v[j] - 1].first + 1,i));
			for (int j = 1;j <= tot;j++)
				if (j + (j & -j) <= tot)
					MAX[j + (j & -j)] = max(MAX[j + (j & -j)],MAX[j]);
		}
	}
//	for (int i = 1;i <= n;i++)
//		cout << f[i] << ',' << i << ' ';
//	cout << endl;
//	return 0;
	for (int i = 1;i <= tot;i++)
		MAX[i] = max(MAX[i],MAX[i - (i & -i)]);
	int p = n,ed = tot;
	while (p > 1)
	{
		if (~a[pre[p]])
			p = pre[p];
		else
		{
			int gap = 0;
			for (int i = p - 1;i >= 1;i--)
			{
				if (a[i] == -1)
				{
					gap++;
					continue;
				}
				if (a[i] >= a[p] || min(gap,sum[a[p] - 1] - sum[a[i]]) < f[p] - f[i] - 1)
					continue;
			//	cout << i << ' ' << f[p] - f[i] - 1 << ' ' << gap << ' ' << sum[a[p] - 1] - sum[a[i]] << endl;
				for (int j = p - 1;j > i;j--)
					if (a[j] == -1)
					{
						ed = min(ed,a[p] - 1);
						while (ed - 1 > a[i] && !cnt[ed])
							ed--;
						if (!cnt[ed])
							break;
						cnt[ed]--;
						a[j] = ed--;
					}
				p = i;
				break;
			}
		}
	//	cout << p << endl;
	}
	for (int i = 1,j = 1;i <= n;i++)
		if (a[i] == -1)
		{
			while (j + 1 <= tot && !cnt[j])
				j++;
			a[i] = j;
			cnt[j]--;
		}
	for (int i = 2;i < n;i++)
		printf("%d ",val[a[i]]);
	printf("\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 200005;
const int INF = 1e9 + 1;

int n,m,tot;
int a[MAXN];
int v[MAXN];
int f[MAXN];
int val[MAXN];
int pre[MAXN];
int sum[MAXN];
int cnt[MAXN];

pair<int,int> MAX[MAXN];
pair<int,int> tmp[MAXN];

int getval(int v)
{
	int low = 1,high = tot;
	while (low < high)
	{
		int mid = low + high >> 1;
		if (val[mid] >= v)
			high = mid;
		else
			low = mid + 1;
	}
	return low;
}

void modify(int p,pair<int,int> v)
{
	while (p <= tot)
	{
		MAX[p] = max(MAX[p],v);
		p += p & -p;
	}
}

pair<int,int> query(int p)
{
	pair<int,int> r(0,0);
	while (p >= 1)
	{
		r = max(r,MAX[p]);
		p -= p & -p;
	}
	return r;
}

int main()
{
	scanf("%d",&n);
	a[1] = -INF;
	a[n + 2] = INF;
	val[++tot] = -INF;
	val[++tot] = INF;
	for (int i = 2;i <= n + 1;i++)
	{
		scanf("%d",&a[i]);
		if (~a[i])
			val[++tot] = a[i];
	}
	n += 2;
	scanf("%d",&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d",&v[i]);
		val[++tot] = v[i];
	}
	sort(v + 1,v + m + 1);
	sort(val + 1,val + tot + 1);
	tot = unique(val + 1,val + tot + 1) - val - 1;
	for (int i = 1;i <= n;i++)
		if (~a[i])
			a[i] = getval(a[i]);
	for (int i = 1;i <= m;i++)
	{
		v[i] = getval(v[i]);
		cnt[v[i]]++;
		sum[v[i]] = 1;
	}
	for (int i = 1;i <= tot;i++)
		sum[i] += sum[i - 1];
	for (int i = 1;i <= n;i++)
	{
	//	cout << "??" << a[i] << endl;
		if (~a[i])
		{
			pair<int,int> MX = query(a[i] - 1);
		//	cout << i << ' ' << MX.first << ',' << MX.second << endl;
			pre[i] = MX.second;
			modify(a[i],make_pair(f[i] = MX.first + 1,i));
		}
		else
		{
			for (int j = 1;j <= tot;j++)
				MAX[j] = max(MAX[j],MAX[j - (j & -j)]);
		//	for (int j = 1;j <= tot;j++)
		//		cout << MAX[j].first << ' ' << MAX[j].second << endl;
			for (int j = m;j >= 1;j--)
				MAX[v[j]] = max(MAX[v[j]],make_pair(MAX[v[j] - 1].first + 1,i));
			for (int j = 1;j <= tot;j++)
				if (j + (j & -j) <= tot)
					MAX[j + (j & -j)] = max(MAX[j + (j & -j)],MAX[j]);
		}
	}
//	for (int i = 1;i <= n;i++)
//		cout << f[i] << ',' << i << ' ';
//	cout << endl;
//	return 0;
	for (int i = 1;i <= tot;i++)
		MAX[i] = max(MAX[i],MAX[i - (i & -i)]);
	int p = n,ed = tot;
	while (p > 1)
	{
		if (~a[pre[p]])
			p = pre[p];
		else
		{
			int gap = 0;
			for (int i = p - 1;i >= 1;i--)
			{
				if (a[i] == -1)
				{
					gap++;
					continue;
				}
				if (a[i] >= a[p] || min(gap,sum[a[p] - 1] - sum[a[i]]) < f[p] - f[i] - 1)
					continue;
			//	cout << i << ' ' << f[p] - f[i] - 1 << ' ' << gap << ' ' << sum[a[p] - 1] - sum[a[i]] << endl;
				for (int j = p - 1;j > i;j--)
					if (a[j] == -1)
					{
						ed = min(ed,a[p] - 1);
						while (ed - 1 > a[i] && !cnt[ed])
							ed--;
						if (!cnt[ed])
							break;
						cnt[ed]--;
						a[j] = ed;
					}
				p = i;
				break;
			}
		}
	//	cout << p << endl;
	}
	for (int i = 1,j = 1;i <= n;i++)
		if (a[i] == -1)
		{
			while (j + 1 <= tot && !cnt[j])
				j++;
			a[i] = j;
			cnt[j]--;
		}
	for (int i = 2;i < n;i++)
		printf("%d ",val[a[i]]);
	printf("\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 200005;
const int INF = 1e9 + 1;

int n,m,tot;
int a[MAXN];
int v[MAXN];
int f[MAXN];
int val[MAXN];
int pre[MAXN];
int sum[MAXN];
int cnt[MAXN];

pair<int,int> MAX[MAXN];
pair<int,int> tmp[MAXN];

inline pair<int,int> max(const pair<int,int> &a,const pair<int,int> &b)
{
	return a.first < b.first ? b : a;
}

int getval(int v)
{
	int low = 1,high = tot;
	while (low < high)
	{
		int mid = low + high >> 1;
		if (val[mid] >= v)
			high = mid;
		else
			low = mid + 1;
	}
	return low;
}

void modify(int p,pair<int,int> v)
{
	while (p <= tot)
	{
		MAX[p] = max(MAX[p],v);
		p += p & -p;
	}
}

pair<int,int> query(int p)
{
	pair<int,int> r(0,0);
	while (p >= 1)
	{
		r = max(r,MAX[p]);
		p -= p & -p;
	}
	return r;
}

int main()
{
	scanf("%d",&n);
	a[1] = -INF;
	a[n + 2] = INF;
	val[++tot] = -INF;
	val[++tot] = INF;
	for (int i = 2;i <= n + 1;i++)
	{
		scanf("%d",&a[i]);
		if (~a[i])
			val[++tot] = a[i];
	}
	n += 2;
	scanf("%d",&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d",&v[i]);
		val[++tot] = v[i];
	}
	sort(v + 1,v + m + 1);
	sort(val + 1,val + tot + 1);
	tot = unique(val + 1,val + tot + 1) - val - 1;
	for (int i = 1;i <= n;i++)
		if (~a[i])
			a[i] = getval(a[i]);
	for (int i = 1;i <= m;i++)
	{
		v[i] = getval(v[i]);
		cnt[v[i]]++;
		sum[v[i]] = 1;
	}
	for (int i = 1;i <= tot;i++)
		sum[i] += sum[i - 1];
	for (int i = 1;i <= n;i++)
	{
	//	cout << "??" << a[i] << endl;
		if (~a[i])
		{
			pair<int,int> MX = query(a[i] - 1);
		//	cout << i << ' ' << MX.first << ',' << MX.second << endl;
			pre[i] = MX.second;
			modify(a[i],make_pair(f[i] = MX.first + 1,i));
		}
		else
		{
			for (int j = 1;j <= tot;j++)
				MAX[j] = max(MAX[j],MAX[j - (j & -j)]);
		//	for (int j = 1;j <= tot;j++)
		//		cout << MAX[j].first << ' ' << MAX[j].second << endl;
			for (int j = m;j >= 1;j--)
				MAX[v[j]] = max(MAX[v[j]],make_pair(MAX[v[j] - 1].first + 1,i));
			for (int j = 1;j <= tot;j++)
				if (j + (j & -j) <= tot)
					MAX[j + (j & -j)] = max(MAX[j + (j & -j)],MAX[j]);
		}
	}
//	for (int i = 1;i <= n;i++)
//		cout << f[i] << ',' << i << ' ';
//	cout << endl;
//	return 0;
	for (int i = 1;i <= tot;i++)
		MAX[i] = max(MAX[i],MAX[i - (i & -i)]);
	int p = n,ed = tot;
	while (p > 1)
	{
		if (~a[pre[p]])
			p = pre[p];
		else
		{
			int gap = 0;
			for (int i = p - 1;i >= 1;i--)
			{
				if (a[i] == -1)
				{
					gap++;
					continue;
				}
				if (a[i] >= a[p] || min(gap,sum[a[p] - 1] - sum[a[i]]) < f[p] - f[i] - 1)
					continue;
			//	cout << i << ' ' << f[p] - f[i] - 1 << ' ' << gap << ' ' << sum[a[p] - 1] - sum[a[i]] << endl;
				for (int j = p - 1;j > i;j--)
					if (a[j] == -1)
					{
						ed = min(ed,a[p] - 1);
						while (ed - 1 > a[i] && !cnt[ed])
							ed--;
						if (!cnt[ed])
							break;
						cnt[ed]--;
						a[j] = ed--;
					}
				p = i;
				break;
			}
		}
	//	cout << p << endl;
	}
	for (int i = 1,j = 1;i <= n;i++)
		if (a[i] == -1)
		{
			while (j + 1 <= tot && !cnt[j])
				j++;
			a[i] = j;
			cnt[j]--;
		}
	for (int i = 2;i < n;i++)
		printf("%d ",val[a[i]]);
	printf("\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 200005;
const int INF = 1e9 + 1;

int n,m,tot;
int a[MAXN];
int v[MAXN];
int f[MAXN];
int val[MAXN];
int pre[MAXN];
int sum[MAXN];
int cnt[MAXN];

pair<int,int> MAX[MAXN];
pair<int,int> tmp[MAXN];

int getval(int v)
{
	int low = 1,high = tot;
	while (low < high)
	{
		int mid = low + high >> 1;
		if (val[mid] >= v)
			high = mid;
		else
			low = mid + 1;
	}
	return low;
}

void modify(int p,pair<int,int> v)
{
	while (p <= tot)
	{
		MAX[p] = max(MAX[p],v);
		p += p & -p;
	}
}

pair<int,int> query(int p)
{
	pair<int,int> r(0,0);
	while (p >= 1)
	{
		r = max(r,MAX[p]);
		p -= p & -p;
	}
	return r;
}

int main()
{
	scanf("%d",&n);
	a[1] = -INF;
	a[n + 2] = INF;
	val[++tot] = -INF;
	val[++tot] = INF;
	for (int i = 2;i <= n + 1;i++)
	{
		scanf("%d",&a[i]);
		if (~a[i])
			val[++tot] = a[i];
	}
	n += 2;
	scanf("%d",&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d",&v[i]);
		val[++tot] = v[i];
	}
	sort(v + 1,v + m + 1);
	sort(val + 1,val + tot + 1);
	tot = unique(val + 1,val + tot + 1) - val - 1;
	for (int i = 1;i <= n;i++)
		if (~a[i])
			a[i] = getval(a[i]);
	for (int i = 1;i <= m;i++)
	{
		v[i] = getval(v[i]);
		cnt[v[i]]++;
		sum[v[i]] = 1;
	}
	for (int i = 1;i <= tot;i++)
		sum[i] += sum[i - 1];
	for (int i = 1;i <= n;i++)
	{
	//	cout << "??" << a[i] << endl;
		if (~a[i])
		{
			pair<int,int> MX = query(a[i] - 1);
		//	cout << i << ' ' << MX.first << ',' << MX.second << endl;
			pre[i] = MX.second;
			modify(a[i],make_pair(f[i] = MX.first + 1,i));
		}
		else
		{
			for (int j = 1;j <= tot;j++)
				MAX[j] = max(MAX[j],MAX[j - (j & -j)]);
		//	for (int j = 1;j <= tot;j++)
		//		cout << MAX[j].first << ' ' << MAX[j].second << endl;
			for (int j = m;j >= 1;j--)
				MAX[v[j]] = max(MAX[v[j]],make_pair(MAX[v[j] - 1].first + 1,i));
			for (int j = 1;j <= tot;j++)
				if (j + (j & -j) <= tot)
					MAX[j + (j & -j)] = max(MAX[j + (j & -j)],MAX[j]);
		}
	}
//	for (int i = 1;i <= n;i++)
//		cout << f[i] << ' ';
//	cout << endl;
//	return 0;
	for (int i = 1;i <= tot;i++)
		MAX[i] = max(MAX[i],MAX[i - (i & -i)]);
	int p = n,ed = tot;
	while (p > 1)
	{
		if (~a[pre[p]])
			p = pre[p];
		else
		{
			int gap = 0;
			for (int i = p - 1;i >= 1;i--)
			{
				if (a[i] == -1)
				{
					gap++;
					continue;
				}
				if (min(gap,sum[a[p] - 1] - sum[a[i]]) < f[p] - f[i] - 1)
					continue;
			//	cout << i << ' ' << f[p] - f[i] - 1 << ' ' << gap << ' ' << sum[a[p] - 1] - sum[a[i]] << endl;
				for (int j = p - 1;j > i;j--)
					if (a[j] == -1)
					{
						ed = min(ed,a[p] - 1);
						while (ed - 1 > a[i] && !cnt[ed])
							ed--;
						if (!cnt[ed])
							break;
						cnt[ed]--;
						a[j] = ed;
					}
				p = i;
				break;
			}
		}
	//	cout << p << endl;
	}
	for (int i = 1,j = 1;i <= n;i++)
		if (a[i] == -1)
		{
			while (j + 1 <= tot && !cnt[j])
				j++;
			a[i] = j;
			cnt[j]--;
		}
	for (int i = 2;i < n;i++)
		printf("%d ",val[a[i]]);
	printf("\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 200005;
const int INF = 1e9 + 1;

int n,m,tot;
int a[MAXN];
int v[MAXN];
int f[MAXN];
int val[MAXN];
int pre[MAXN];
int sum[MAXN];
int cnt[MAXN];

pair<int,int> MAX[MAXN];
pair<int,int> tmp[MAXN];

int getval(int v)
{
	int low = 1,high = tot;
	while (low < high)
	{
		int mid = low + high >> 1;
		if (val[mid] >= v)
			high = mid;
		else
			low = mid + 1;
	}
	return low;
}

void modify(int p,pair<int,int> v)
{
	while (p <= tot)
	{
		MAX[p] = max(MAX[p],v);
		p += p & -p;
	}
}

pair<int,int> query(int p)
{
	pair<int,int> r(0,0);
	while (p >= 1)
	{
		r = max(r,MAX[p]);
		p -= p & -p;
	}
	return r;
}

int main()
{
	scanf("%d",&n);
	a[1] = -INF;
	a[n + 2] = INF;
	val[++tot] = -INF;
	val[++tot] = INF;
	for (int i = 2;i <= n + 1;i++)
	{
		scanf("%d",&a[i]);
		if (~a[i])
			val[++tot] = a[i];
	}
	n += 2;
	scanf("%d",&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d",&v[i]);
		val[++tot] = v[i];
	}
	sort(v + 1,v + m + 1);
	sort(val + 1,val + tot + 1);
	tot = unique(val + 1,val + tot + 1) - val - 1;
	for (int i = 1;i <= n;i++)
		if (~a[i])
			a[i] = getval(a[i]);
	for (int i = 1;i <= m;i++)
	{
		v[i] = getval(v[i]);
		cnt[v[i]]++;
		sum[v[i]] = 1;
	}
	for (int i = 1;i <= tot;i++)
		sum[i] += sum[i - 1];
	for (int i = 1;i <= n;i++)
	{
	//	cout << "??" << a[i] << endl;
		if (~a[i])
		{
			pair<int,int> MX = query(a[i] - 1);
		//	cout << i << ' ' << MX.first << ',' << MX.second << endl;
			pre[i] = MX.second;
			modify(a[i],make_pair(f[i] = MX.first + 1,i));
		}
		else
		{
			for (int j = 1;j <= tot;j++)
				MAX[j] = max(MAX[j],MAX[j - (j & -j)]);
		//	for (int j = 1;j <= tot;j++)
		//		cout << MAX[j].first << ' ' << MAX[j].second << endl;
			for (int j = m;j >= 1;j--)
				MAX[v[j]] = max(MAX[v[j]],make_pair(MAX[v[j] - 1].first + 1,i));
			for (int j = 1;j <= tot;j++)
				if (j + (j & -j) <= tot)
					MAX[j + (j & -j)] = max(MAX[j + (j & -j)],MAX[j]);
		}
	}
//	for (int i = 1;i <= n;i++)
//		cout << f[i] << ' ';
//	cout << endl;
//	return 0;
	for (int i = 1;i <= tot;i++)
		MAX[i] = max(MAX[i],MAX[i - (i & -i)]);
	int p = n,ed = tot;
	while (p > 1)
	{
		if (~a[pre[p]])
			p = pre[p];
		else
		{
			int gap = 0;
			for (int i = p - 1;i >= 1;i--)
			{
				if (a[i] == -1)
				{
					gap++;
					continue;
				}
			//	cout << i << ' ' << f[p] - f[i] - 1 << ' ' << gap << ' ' << sum[a[p] - 1] - sum[a[i]] << endl;
				if (min(gap,sum[a[p] - 1] - sum[a[i]]) < f[p] - f[i] - 1)
					continue;
				for (int j = p - 1;j > i;j--)
					if (a[j] == -1)
					{
						ed = min(ed,a[p] - 1);
						while (ed - 1 > a[i] && !cnt[ed])
							ed--;
						if (ed - 1 <= a[i])
							break;
						cnt[ed]--;
						a[j] = ed;
					}
				p = i;
				break;
			}
		}
	//	cout << p << endl;
	}
	for (int i = 1,j = 1;i <= n;i++)
		if (a[i] == -1)
		{
			while (j + 1 <= tot && !cnt[j])
				j++;
			a[i] = j;
			cnt[j]--;
		}
	for (int i = 2;i < n;i++)
		printf("%d ",val[a[i]]);
	printf("\n");
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 200005;
const int INF = 1e9 + 1;

int n,m,tot;
int a[MAXN];
int v[MAXN];
int f[MAXN];
int val[MAXN];
int pre[MAXN];
int sum[MAXN];
int cnt[MAXN];

pair<int,int> MAX[MAXN];
pair<int,int> tmp[MAXN];

inline pair<int,int> max(const pair<int,int> &a,const pair<int,int> &b)
{
	return a.first < b.first ? b : a;
}

int getval(int v)
{
	int low = 1,high = tot;
	while (low < high)
	{
		int mid = low + high >> 1;
		if (val[mid] >= v)
			high = mid;
		else
			low = mid + 1;
	}
	return low;
}

void modify(int p,pair<int,int> v)
{
	while (p <= tot)
	{
		MAX[p] = max(MAX[p],v);
		p += p & -p;
	}
}

pair<int,int> query(int p)
{
	pair<int,int> r(0,0);
	while (p >= 1)
	{
		r = max(r,MAX[p]);
		p -= p & -p;
	}
	return r;
}

int main()
{
	scanf("%d",&n);
	a[1] = -INF;
	a[n + 2] = INF;
	val[++tot] = -INF;
	for (int i = 2;i <= n + 1;i++)
	{
		scanf("%d",&a[i]);
		if (~a[i])
			val[++tot] = a[i];
	}
	n += 2;
	scanf("%d",&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d",&v[i]);
		val[++tot] = v[i];
	}
	sort(v + 1,v + m + 1);
	sort(val + 1,val + tot + 1);
	tot = unique(val + 1,val + tot + 1) - val - 1;
	for (int i = 1;i <= n;i++)
		if (~a[i])
			a[i] = getval(a[i]);
	for (int i = 1;i <= m;i++)
	{
		v[i] = getval(v[i]);
		cnt[v[i]]++;
		sum[v[i]] = 1;
	}
	for (int i = 1;i <= tot;i++)
		sum[i] += sum[i - 1];
	for (int i = 1;i <= n;i++)
	{
	//	cout << "??" << a[i] << endl;
		if (~a[i])
		{
			pair<int,int> MX = query(a[i] - 1);
		//	cout << i << ' ' << MX.first << ',' << MX.second << endl;
			pre[i] = MX.second;
			modify(a[i],make_pair(f[i] = MX.first + 1,i));
		}
		else
		{
			for (int j = 1;j <= tot;j++)
				MAX[j] = max(MAX[j],MAX[j - (j & -j)]);
		//	for (int j = 1;j <= tot;j++)
		//		cout << MAX[j].first << ' ' << MAX[j].second << endl;
			for (int j = m;j >= 1;j--)
				MAX[v[j]] = max(MAX[v[j]],make_pair(MAX[v[j] - 1].first + 1,i));
			for (int j = 1;j <= tot;j++)
				if (j + (j & -j) <= tot)
					MAX[j + (j & -j)] = max(MAX[j + (j & -j)],MAX[j]);
		}
	}
//	for (int i = 1;i <= n;i++)
//		cout << f[i] << ',' << i << ' ';
//	cout << endl;
//	return 0;
	for (int i = 1;i <= tot;i++)
		MAX[i] = max(MAX[i],MAX[i - (i & -i)]);
	int p = n,ed = tot;
	while (p > 1)
	{
		if (~a[pre[p]])
			p = pre[p];
		else
		{
			int gap = 0;
			for (int i = p - 1;i >= 1;i--)
			{
				if (a[i] == -1)
				{
					gap++;
					continue;
				}
				if (a[i] >= a[p] || min(gap,sum[a[p] - 1] - sum[a[i]]) < f[p] - f[i] - 1)
					continue;
			//	cout << i << ' ' << f[p] - f[i] - 1 << ' ' << gap << ' ' << sum[a[p] - 1] - sum[a[i]] << endl;
				for (int j = p - 1;j > i;j--)
					if (a[j] == -1)
					{
						ed = min(ed,a[p] - 1);
						while (ed - 1 > a[i] && !cnt[ed])
							ed--;
						if (!cnt[ed])
							break;
						cnt[ed]--;
						a[j] = ed--;
					}
				p = i;
				break;
			}
		}
	//	cout << p << endl;
	}
	for (int i = 1,j = 1;i <= n;i++)
		if (a[i] == -1)
		{
			while (j + 1 <= tot && !cnt[j])
				j++;
			a[i] = j;
			cnt[j]--;
		}
	for (int i = 2;i < n;i++)
		printf("%d ",val[a[i]]);
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=5e5+5,K=1e3+5;

int n,m,a[N],b[N],mxb,val[N],rk,arr[N],las[N],lasb[N],cnt[N];
struct node{
    int id,v;
    node(int id=0,int v=0):id(id),v(v){}
    inline bool operator<(node& x){return v<x.v;}
    inline bool operator>(node& x){return v>x.v;}
}D[N],tr[N],buc[N],ans;int dl;
inline void chk(node& x,node y){if(y>x)x=y;}
int lbt[N];
void ins(int pos,node p){chk(buc[pos],p);for(;pos<=rk;pos+=lbt[pos])chk(tr[pos],p);}
node qry(int pos){node p(0,0);for(;pos;pos-=lbt[pos])chk(p,tr[pos]);return p;}

int f[N],pre[N],p[N];int pl;
bool cmp(int x,int y){return f[x]>f[y];}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]==-1)las[i]=i;
        else las[i]=las[i-1],D[++dl]=node(i,a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)scanf("%d",&b[i]),D[++dl]=node(i+n,b[i]);
    sort(D+1,D+dl+1),D[0].v=-1;
    for(int i=1;i<=dl;++i){
        rk+=D[i].v!=D[i-1].v,val[rk]=D[i].v;
        if(D[i].id<=n)a[D[i].id]=rk;
        else b[D[i].id-n]=rk;
    }
    //for(int i=1;i<=rk;++i)printf("%d ",val[i]);putchar('\n');
    for(int i=1;i<=m;++i)++cnt[b[i]],mxb=max(mxb,b[i]);
    for(int i=1;i<=rk;++i)lasb[i]=cnt[i]?i:lasb[i-1],lbt[i]=i&-i;
    //puts("qwq");
    //int qwqqwq=0;
    //printf("rk=%d\n",rk);
    for(int i=1;i<=n;++i){
        if(a[i]==-1){
            node p,q;
            //printf("%d\n",++qwqqwq);
            for(register int j=1;j<=rk;++j){
                q=p,chk(p,buc[j]);
                //printf("%d(%d,%d)\n",j,q.id,q.v);
                if(cnt[j])chk(buc[j],node(i,q.v+1)),chk(tr[j],buc[j]);
                if(j+lbt[j]<=rk)chk(tr[j+lbt[j]],tr[j]);
            }
            chk(ans,tr[rk]);
            //printf("p=(%d,%d)\n",p.id,p.v);
        }else{
            node p=qry(a[i]-1);++p.v;
            pre[i]=p.id,f[i]=p.v;
            chk(ans,node(i,f[i])),ins(a[i],node(i,f[i]));
        }
        //printf("pre[%d]=%d,f[%d]=%d\n",i,pre[i],i,f[i]);
    }
    //puts("qwq");
    //printf("ans=(%d,%d)\n",ans.id,ans.v);
    for(int i=1;i<=n;++i)if(a[i]!=-1)p[++pl]=i;
    sort(p+1,p+pl+1,cmp);
    //for(int i=1;i<=n;++i)printf("%d ",pre[i]);putchar('\n');
    //for(int i=1;i<=pl;++i)printf("f[%d]=%d,a[%d]=%d\n",p[i],f[p[i]],p[i],a[p[i]]);
    for(int i=ans.id,j=ans.v,k=1,A=a[i]==-1?mxb:a[i];i;--j){
        //printf("j=%d\n",j);
        //printf("(%d,%d,%d)\n",i,val[A],a[i]);
        arr[i]=A;if(a[i]==-1)--cnt[A];
        if(a[i]==-1){
            while(k<=pl&&f[p[k]]>=j-1){
                if(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)break;
                ++k;
            }
            if(k<=pl&&a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)i=p[k];
            else i=las[i-1];
        }else i=pre[i];
        if(a[i]!=-1)A=a[i];
        else A=lasb[A-1];
    }
    //for(int i=1;i<=n;++i)printf("%d ",arr[i]);putchar('\n');
    for(int i=n,j=rk;i>=1;--i){
        while(!cnt[j])--j;
        if(!arr[i]){
            if(a[i]==-1)arr[i]=j,--cnt[j];
            else arr[i]=a[i];
        }
    }
    for(int i=1;i<=n;++i)printf("%d ",val[arr[i]]);
    putchar('\n');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=2e5+5,K=1e3+5;

int n,m,a[N],b[N],mxb,val[N],rk,arr[N],las[N],lasb[N],cnt[N];
struct node{
    int id,v;
    node(int id=0,int v=0):id(id),v(v){}
    bool operator<(node& x){return v<x.v;}
    bool operator>(node& x){return v>x.v||(v==x.v&&id>x.id);}
}D[N],tr[N],buc[N],ans;int dl;
inline void chk(node& x,node y){if(y>x)x=y;}
inline int lowbit(int x){return x&-x;}
void build(){for(int i=1;i<=rk;++i)chk(tr[i],buc[i]),chk(tr[i+lowbit(i)],tr[i]);}
void ins(int pos,node p){chk(buc[pos],p);for(;pos<=rk;pos+=lowbit(pos))chk(tr[pos],p);}
node qry(int pos){node p(0,0);for(;pos;pos-=lowbit(pos))chk(p,tr[pos]);return p;}

int f[N],pre[N],p[N];int pl;
bool cmp(int x,int y){return f[x]>f[y];}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]==-1)las[i]=i;
        else las[i]=las[i-1],D[++dl]=node(i,a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)scanf("%d",&b[i]),D[++dl]=node(i+n,b[i]);
    sort(D+1,D+dl+1),D[0].v=-1;
    for(int i=1;i<=dl;++i){
        rk+=D[i].v!=D[i-1].v,val[rk]=D[i].v;
        if(D[i].id<=n)a[D[i].id]=rk;
        else b[D[i].id-n]=rk;
    }
    //for(int i=1;i<=rk;++i)printf("%d ",val[i]);putchar('\n');
    for(int i=1;i<=m;++i)++cnt[b[i]],mxb=max(mxb,b[i]);
    for(int i=1;i<=rk;++i)lasb[i]=cnt[i]?i:lasb[i-1];
    for(int i=1;i<=n;++i){
        if(a[i]==-1){
            node p,q;
            for(int j=1;j<=rk;++j){
                q=p,chk(p,buc[j]);
                //printf("%d(%d,%d)\n",j,q.id,q.v);
                if(cnt[j])chk(buc[j],node(i,q.v+1)),chk(ans,node(i,q.v+1));
            }
            //printf("p=(%d,%d)\n",p.id,p.v);
            build();
        }else{
            node p=qry(a[i]-1);++p.v;
            pre[i]=p.id,f[i]=p.v;
            chk(ans,node(i,f[i])),ins(a[i],node(i,f[i]));
        }
        //printf("pre[%d]=%d,f[%d]=%d\n",i,pre[i],i,f[i]);
    }
    //printf("ans=(%d,%d)\n",ans.id,ans.v);
    for(int i=1;i<=n;++i)if(a[i]!=-1)p[++pl]=i;
    sort(p+1,p+pl+1,cmp);
    //for(int i=1;i<=n;++i)printf("%d ",pre[i]);putchar('\n');
    //for(int i=1;i<=pl;++i)printf("f[%d]=%d,a[%d]=%d\n",p[i],f[p[i]],p[i],a[p[i]]);
    for(int i=ans.id,j=ans.v,k=1,A=a[i]==-1?mxb:a[i];i;--j){
        //printf("j=%d\n",j);
        //printf("(%d,%d,%d)\n",i,val[A],a[i]);
        arr[i]=A;if(a[i]==-1)--cnt[A];
        if(a[i]==-1){
            while(k<=pl&&f[p[k]]>=j-1){
                if(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)break;
                ++k;
            }
            if(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)i=p[k];
            else i=las[i-1];
        }else i=pre[i];
        if(a[i]!=-1)A=a[i];
        else A=lasb[A-1];
    }
    //for(int i=1;i<=n;++i)printf("%d ",arr[i]);putchar('\n');
    for(int i=n,j=rk;i>=1;--i){
        while(!cnt[j])--j;
        if(!arr[i]){
            if(a[i]==-1)arr[i]=j,--cnt[j];
            else arr[i]=a[i];
        }
    }
    for(int i=1;i<=n;++i)printf("%d ",val[arr[i]]);
    putchar('\n');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=5e5+5,K=1e3+5;

int n,m,a[N],b[N],mxb,val[N],rk,arr[N],las[N],lasb[N],cnt[N];
struct node{
    int id,v;
    node(int id=0,int v=0):id(id),v(v){}
    inline bool operator<(node& x){return v<x.v;}
    inline bool operator>(node& x){return v>x.v||(v==x.v&&id>x.id);}
}D[N],tr[N],buc[N],ans;int dl;
inline void chk(node& x,node y){if(y>x)x=y;}
inline int lowbit(int x){return x&-x;}
void ins(int pos,node p){chk(buc[pos],p);for(;pos<=rk;pos+=lowbit(pos))chk(tr[pos],p);}
node qry(int pos){node p(0,0);for(;pos;pos-=lowbit(pos))chk(p,tr[pos]);return p;}

int f[N],pre[N],p[N];int pl;
bool cmp(int x,int y){return f[x]>f[y];}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]==-1)las[i]=i;
        else las[i]=las[i-1],D[++dl]=node(i,a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)scanf("%d",&b[i]),D[++dl]=node(i+n,b[i]);
    sort(D+1,D+dl+1),D[0].v=-1;
    for(int i=1;i<=dl;++i){
        rk+=D[i].v!=D[i-1].v,val[rk]=D[i].v;
        if(D[i].id<=n)a[D[i].id]=rk;
        else b[D[i].id-n]=rk;
    }
    //for(int i=1;i<=rk;++i)printf("%d ",val[i]);putchar('\n');
    for(int i=1;i<=m;++i)++cnt[b[i]],mxb=max(mxb,b[i]);
    for(int i=1;i<=rk;++i)lasb[i]=cnt[i]?i:lasb[i-1];
    //puts("qwq");
    //int qwqqwq=0;
    //printf("rk=%d\n",rk);
    for(int i=1;i<=n;++i){
        if(a[i]==-1){
            node p,q;
            //printf("%d\n",++qwqqwq);
            for(register int j=1;j<=rk;++j){
                q=p,chk(p,buc[j]);
                //printf("%d(%d,%d)\n",j,q.id,q.v);
                if(cnt[j])chk(buc[j],node(i,q.v+1)),chk(ans,node(i,q.v+1)),chk(tr[j],buc[j]);
                chk(tr[j+lowbit(j)],tr[j]);
            }
            //printf("p=(%d,%d)\n",p.id,p.v);
        }else{
            node p=qry(a[i]-1);++p.v;
            pre[i]=p.id,f[i]=p.v;
            chk(ans,node(i,f[i])),ins(a[i],node(i,f[i]));
        }
        //printf("pre[%d]=%d,f[%d]=%d\n",i,pre[i],i,f[i]);
    }
    //puts("qwq");
    //printf("ans=(%d,%d)\n",ans.id,ans.v);
    for(int i=1;i<=n;++i)if(a[i]!=-1)p[++pl]=i;
    sort(p+1,p+pl+1,cmp);
    //for(int i=1;i<=n;++i)printf("%d ",pre[i]);putchar('\n');
    //for(int i=1;i<=pl;++i)printf("f[%d]=%d,a[%d]=%d\n",p[i],f[p[i]],p[i],a[p[i]]);
    for(int i=ans.id,j=ans.v,k=1,A=a[i]==-1?mxb:a[i];i;--j){
        //printf("j=%d\n",j);
        //printf("(%d,%d,%d)\n",i,val[A],a[i]);
        arr[i]=A;if(a[i]==-1)--cnt[A];
        if(a[i]==-1){
            while(k<=pl&&f[p[k]]>=j-1){
                if(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)break;
                ++k;
            }
            if(k<=pl&&a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)i=p[k];
            else i=las[i-1];
        }else i=pre[i];
        if(a[i]!=-1)A=a[i];
        else A=lasb[A-1];
    }
    //for(int i=1;i<=n;++i)printf("%d ",arr[i]);putchar('\n');
    for(int i=n,j=rk;i>=1;--i){
        while(!cnt[j])--j;
        if(!arr[i]){
            if(a[i]==-1)arr[i]=j,--cnt[j];
            else arr[i]=a[i];
        }
    }
    for(int i=1;i<=n;++i)printf("%d ",val[arr[i]]);
    putchar('\n');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=2e5+5,K=1e3+5;

int n,m,a[N],b[N],mxb,val[N],rk,arr[N],las[N],lasb[N],cnt[N];
struct node{
    int id,v;
    node(int id=0,int v=0):id(id),v(v){}
    bool operator<(node& x){return v<x.v;}
    bool operator>(node& x){return v>x.v||(v==x.v&&id>x.id);}
}D[N],tr[N],buc[N],ans;int dl;
inline void chk(node& x,node y){if(y>x)x=y;}
inline int lowbit(int x){return x&-x;}
void build(){for(int i=1;i<=rk;++i)chk(tr[i],buc[i]),chk(tr[i+lowbit(i)],tr[i]);}
void ins(int pos,node p){chk(buc[pos],p);for(;pos<=rk;pos+=lowbit(pos))chk(tr[pos],p);}
node qry(int pos){node p(0,0);for(;pos;pos-=lowbit(pos))chk(p,tr[pos]);return p;}

int f[N],pre[N],p[N];int pl;
bool cmp(int x,int y){return a[x]>a[y]||(a[x]==a[y]&&x>y);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]==-1)las[i]=i;
        else las[i]=las[i-1],D[++dl]=node(i,a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)scanf("%d",&b[i]),D[++dl]=node(i+n,b[i]);
    sort(D+1,D+dl+1),D[0].v=-1;
    for(int i=1;i<=dl;++i){
        rk+=D[i].v!=D[i-1].v,val[rk]=D[i].v;
        if(D[i].id<=n)a[D[i].id]=rk;
        else b[D[i].id-n]=rk;
    }
    //for(int i=1;i<=rk;++i)printf("%d ",val[i]);putchar('\n');
    for(int i=1;i<=m;++i)++cnt[b[i]],mxb=max(mxb,b[i]);
    for(int i=1;i<=rk;++i)lasb[i]=cnt[i]?i:lasb[i-1];
    for(int i=1;i<=n;++i){
        if(a[i]==-1){
            node p,q;
            for(int j=1;j<=rk;++j){
                q=p,chk(p,buc[j]);
                //printf("%d(%d,%d)\n",j,q.id,q.v);
                if(cnt[j])chk(buc[j],node(i,q.v+1)),chk(ans,node(i,q.v+1));
            }
            //printf("p=(%d,%d)\n",p.id,p.v);
            build();
        }else{
            node p=qry(a[i]-1);++p.v;
            pre[i]=p.id,f[i]=p.v;
            chk(ans,node(i,f[i])),ins(a[i],node(i,f[i]));
        }
        //printf("pre[%d]=%d,f[%d]=%d\n",i,pre[i],i,f[i]);
    }
    //printf("ans=(%d,%d)\n",ans.id,ans.v);
    for(int i=1;i<=n;++i)if(a[i]!=-1)p[++pl]=i;
    sort(p+1,p+pl+1,cmp);
    //for(int i=1;i<=n;++i)printf("%d ",f[i]);putchar('\n');
    for(int i=ans.id,j=ans.v,k=pl,A=a[i]==-1?mxb:a[i];i;--j){
        arr[i]=A;if(a[i]==-1)--cnt[A];
        if(a[i]==-1){
            while(k>=1&&!(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1))--k;
            if(k)i=p[k];
            else i=las[i-1];
        }else i=pre[i];
        if(a[i]!=-1)A=a[i];
        else A=lasb[A-1];
    }
    //for(int i=1;i<=n;++i)printf("%d ",arr[i]);putchar('\n');
    for(int i=n,j=rk;i>=1;--i){
        while(!cnt[j])--j;
        if(!arr[i]){
            if(a[i]==-1)arr[i]=j,--cnt[j];
            else arr[i]=a[i];
        }
    }
    for(int i=1;i<=n;++i)printf("%d ",val[arr[i]]);
    putchar('\n');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=5e5+5,K=1e3+5;

int n,m,a[N],b[N],mxb,val[N],rk,arr[N],las[N],lasb[N],cnt[N];
struct node{
    int id,v;
    node(int id=0,int v=0):id(id),v(v){}
    bool operator<(node& x){return v<x.v;}
    bool operator>(node& x){return v>x.v||(v==x.v&&id>x.id);}
}D[N],tr[N],buc[N],ans;int dl;
inline void chk(node& x,node y){if(y>x)x=y;}
inline int lowbit(int x){return x&-x;}
void build(){for(int i=1;i<=rk;++i)chk(tr[i],buc[i]),chk(tr[i+lowbit(i)],tr[i]);}
void ins(int pos,node p){chk(buc[pos],p);for(;pos<=rk;pos+=lowbit(pos))chk(tr[pos],p);}
node qry(int pos){node p(0,0);for(;pos;pos-=lowbit(pos))chk(p,tr[pos]);return p;}

int f[N],pre[N],p[N];int pl;
bool cmp(int x,int y){return f[x]>f[y];}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]==-1)las[i]=i;
        else las[i]=las[i-1],D[++dl]=node(i,a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)scanf("%d",&b[i]),D[++dl]=node(i+n,b[i]);
    sort(D+1,D+dl+1),D[0].v=-1;
    for(int i=1;i<=dl;++i){
        rk+=D[i].v!=D[i-1].v,val[rk]=D[i].v;
        if(D[i].id<=n)a[D[i].id]=rk;
        else b[D[i].id-n]=rk;
    }
    //for(int i=1;i<=rk;++i)printf("%d ",val[i]);putchar('\n');
    for(int i=1;i<=m;++i)++cnt[b[i]],mxb=max(mxb,b[i]);
    for(int i=1;i<=rk;++i)lasb[i]=cnt[i]?i:lasb[i-1];
    for(int i=1;i<=n;++i){
        if(a[i]==-1){
            node p,q;
            for(int j=1;j<=rk;++j){
                q=p,chk(p,buc[j]);
                //printf("%d(%d,%d)\n",j,q.id,q.v);
                if(cnt[j])chk(buc[j],node(i,q.v+1)),chk(ans,node(i,q.v+1));
            }
            //printf("p=(%d,%d)\n",p.id,p.v);
            build();
        }else{
            node p=qry(a[i]-1);++p.v;
            pre[i]=p.id,f[i]=p.v;
            chk(ans,node(i,f[i])),ins(a[i],node(i,f[i]));
        }
        //printf("pre[%d]=%d,f[%d]=%d\n",i,pre[i],i,f[i]);
    }
    //printf("ans=(%d,%d)\n",ans.id,ans.v);
    for(int i=1;i<=n;++i)if(a[i]!=-1)p[++pl]=i;
    sort(p+1,p+pl+1,cmp);
    //for(int i=1;i<=n;++i)printf("%d ",pre[i]);putchar('\n');
    //for(int i=1;i<=pl;++i)printf("f[%d]=%d,a[%d]=%d\n",p[i],f[p[i]],p[i],a[p[i]]);
    for(int i=ans.id,j=ans.v,k=1,A=a[i]==-1?mxb:a[i];i;--j){
        //printf("j=%d\n",j);
        //printf("(%d,%d,%d)\n",i,val[A],a[i]);
        arr[i]=A;if(a[i]==-1)--cnt[A];
        if(a[i]==-1){
            while(k<=pl&&f[p[k]]>=j-1){
                if(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)break;
                ++k;
            }
            if(k<=pl&&a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1)i=p[k];
            else i=las[i-1];
        }else i=pre[i];
        if(a[i]!=-1)A=a[i];
        else A=lasb[A-1];
    }
    //for(int i=1;i<=n;++i)printf("%d ",arr[i]);putchar('\n');
    for(int i=n,j=rk;i>=1;--i){
        while(!cnt[j])--j;
        if(!arr[i]){
            if(a[i]==-1)arr[i]=j,--cnt[j];
            else arr[i]=a[i];
        }
    }
    for(int i=1;i<=n;++i)printf("%d ",val[arr[i]]);
    putchar('\n');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=2e5+5,K=1e3+5;

int n,m,a[N],b[N],mxb,val[N],rk,arr[N],las[N],lasb[N],cnt[N];
struct node{
    int id,v;
    node(int id=0,int v=0):id(id),v(v){}
    bool operator<(node& x){return v<x.v;}
    bool operator>(node& x){return v>x.v||(v==x.v&&id>x.id);}
}D[N],tr[N],buc[N],ans;int dl;
inline void chk(node& x,node y){if(y>x)x=y;}
inline int lowbit(int x){return x&-x;}
void build(){for(int i=1;i<=rk;++i)chk(tr[i],buc[i]),chk(tr[i+lowbit(i)],tr[i]);}
void ins(int pos,node p){chk(buc[pos],p);for(;pos<=rk;pos+=lowbit(pos))chk(tr[pos],p);}
node qry(int pos){node p(0,0);for(;pos;pos-=lowbit(pos))chk(p,tr[pos]);return p;}

int f[N],pre[N],p[N];int pl;
bool cmp(int x,int y){return a[x]>a[y]||(a[x]==a[y]&&x>y);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]==-1)las[i]=i;
        else las[i]=las[i-1],D[++dl]=node(i,a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)scanf("%d",&b[i]),D[++dl]=node(i+n,b[i]);
    sort(D+1,D+dl+1),D[0].v=-1;
    for(int i=1;i<=dl;++i){
        rk+=D[i].v!=D[i-1].v,val[rk]=D[i].v;
        if(D[i].id<=n)a[D[i].id]=rk;
        else b[D[i].id-n]=rk;
    }
    //for(int i=1;i<=rk;++i)printf("%d ",val[i]);putchar('\n');
    for(int i=1;i<=m;++i)++cnt[b[i]],mxb=max(mxb,b[i]);
    for(int i=1;i<=rk;++i)lasb[i]=cnt[i]?i:lasb[i-1];
    for(int i=1;i<=n;++i){
        if(a[i]==-1){
            node p,q;
            for(int j=1;j<=rk;++j){
                q=p,chk(p,buc[j]);
                //printf("%d(%d,%d)\n",j,q.id,q.v);
                if(cnt[j])chk(buc[j],node(i,q.v+1)),chk(ans,node(i,q.v+1));
            }
            //printf("p=(%d,%d)\n",p.id,p.v);
            build();
        }else{
            node p=qry(a[i]-1);++p.v;
            pre[i]=p.id,f[i]=p.v;
            chk(ans,node(i,f[i])),ins(a[i],node(i,f[i]));
        }
        //printf("pre[%d]=%d,f[%d]=%d\n",i,pre[i],i,f[i]);
    }
    //printf("ans=(%d,%d)\n",ans.id,ans.v);
    for(int i=1;i<=n;++i)if(a[i]!=-1)p[++pl]=i;
    sort(p+1,p+pl+1,cmp);
    //for(int i=1;i<=n;++i)printf("%d ",f[i]);putchar('\n');
    for(int i=ans.id,j=ans.v,k=pl,A=a[i]==-1?mxb:a[i];i;--j){
        arr[i]=A;if(a[i]==-1)--cnt[A];
        if(a[i]==-1){
            while(k>=1&&!(a[p[k]]<A&&p[k]<i&&f[p[k]]==j-1))--k;
            if(k)i=p[k];
            else i=las[i-1];
        }else i=pre[i];
        if(a[i]!=-1)A=a[i];
        else A=lasb[A-1];
    }
    //for(int i=1;i<=n;++i)printf("%d ",arr[i]);putchar('\n');
    for(int i=n,j=rk;i>=1;--i){
        while(!cnt[j])--j;
        if(a[i]==-1&&!arr[i])arr[i]=j,--cnt[j];
    }
    for(int i=1;i<=n;++i)printf("%d ",val[arr[i]]);
    putchar('\n');
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 100005,M = 100005,INF = 1e9 + 9;

int mn[N],pos[N],mx;
int n,a[N],f[N],g[N];
int m,b[M];
int main(){
	int i,j,p;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]),mn[i] = INF; a[++n] = INF-1; mn[n] = INF;
	read(m);
	for (i = 1; i <= m; ++i) read(b[i]); sort(b+1,b+m+1);
	for (i = 1; i <= n; ++i){
		if (a[i] != -1){
			p = lower_bound(mn,mn+mx+1,a[i]) - mn;
			if (p > mx) ++mx;
			if (a[i] < mn[p]) mn[p] = a[i],pos[p] = i;
			f[i] = p,g[i] = pos[p-1];
			continue;
		}
		for (p = mx+1,j = m; j ; --j){
			while (p && b[j] <= mn[p-1]) --p;
			if (b[j] < mn[p]) mn[p] = b[j],pos[p] = i;
		}
		f[i] = -1;
		if (pos[mx+1]) ++mx;
	}
	int now = n,nowlen = f[n],nowv = a[n];
	while (nowlen){
		if (a[now] != -1){ --nowlen,nowv = a[now],now = g[now]; continue; }
		for (i = m; i ; --i) if (b[i] != -1 && b[i] < nowv){
			a[now] = b[i]; b[i] = -1; break;
		}
		for (i = now-1; i >= nowlen-1; --i)
			if (f[i] == nowlen-1 && a[i] < a[now]){ g[now] = i; break; }
		if (!g[i]) for (i = now-1; i ; --i) if (a[i] == -1){ g[now] = i; break; }
		--nowlen,nowv = a[now],now = g[now];
	}
	for (i = 1; i <= n; ++i) if (a[i] == -1)
	for (j = 1; j <= m; ++j) if (b[j] != -1){ a[i] = b[j]; b[j] = -1; break; }
	for (i = 1; i < n; ++i) write(a[i]),putchar(i<n?' ':'\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 100005,M = 100005,INF = 1e9 + 9;

int mn[N],pos[N],mx;
int n,a[N],f[N],g[N];
int m,b[M];
int main(){
	int i,j,p;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]),mn[i] = INF; a[++n] = INF; mn[n] = INF;
	read(m);
	for (i = 1; i <= m; ++i) read(b[i]); sort(b+1,b+m+1);
	for (i = 1; i <= n; ++i){
		if (a[i] != -1){
			p = lower_bound(mn,mn+mx+1,a[i]) - mn;
			if (p > mx) ++mx;
			if (a[i] < mn[p]) mn[p] = a[i],pos[p] = i;
			f[i] = p,g[i] = pos[p-1];
			continue;
		}
		for (p = mx+1,j = m; j ; --j){
			while (p && b[j] <= mn[p-1]) --p;
			if (b[j] < mn[p]) mn[p] = b[j],pos[p] = i;
		}
		f[i] = -1;
		if (pos[mx+1]) ++mx;
	}
	int now = n,nowlen = f[n],nowv = a[n];
	while (nowlen){
		if (a[now] != -1){ --nowlen,nowv = a[now],now = g[now]; continue; }
		for (i = m; i ; --i) if (b[i] != -1 && b[i] < nowv){
			a[now] = b[i]; b[i] = -1; break;
		}
		if (nowlen == 1) break;
		for (i = now-1; i >= nowlen-1; --i)
			if (f[i] == nowlen-1 && a[i] < a[now]){ g[now] = i; break; }
		if (!g[i]) for (i = now-1; i ; --i) if (a[i] == -1){ g[now] = i; break; }
		--nowlen,nowv = a[now],now = g[now];
	}
	for (i = 1; i <= n; ++i) if (a[i] == -1)
	for (j = 1; j <= m; ++j) if (b[j] != -1){ a[i] = b[j]; break; }
	for (i = 1; i < n; ++i) write(a[i]),putchar(i<n?' ':'\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
const int N = 100005,M = 100005,INF = 1e9 + 9;
int mn[N],pos[N],mx;
int n,a[N],f[N],g[N],m,b[M];
int main(){
	register int i,j,p;
	read(n); for (i = 1; i <= n; ++i) read(a[i]),mn[i] = INF; a[++n] = INF-1; mn[n] = INF;
	read(m); for (i = 1; i <= m; ++i) read(b[i]); sort(b+1,b+m+1);
	for (i = 1; i <= n; ++i){
		if (a[i] != -1){
			p = lower_bound(mn,mn+mx+1,a[i]) - mn; if (p > mx) ++mx;
			if (a[i] < mn[p]) mn[p] = a[i],pos[p] = i;
			f[i] = p,g[i] = pos[p-1]; continue;
		}
		for (p = mx+1,j = m; j ; --j){
			while (p && b[j] <= mn[p-1]) --p;
			if (b[j] < mn[p]) mn[p] = b[j],pos[p] = i;
		}
		f[i] = -1; if (pos[mx+1]) ++mx;
	}
	int now = n,nowlen = f[n],nowv = a[n];
	while (nowlen){
		if (a[now] != -1){ --nowlen,nowv = a[now],now = g[now]; continue; }
		for (i = m; i ; --i) if (b[i] != -1 && b[i] < nowv){ a[now] = b[i]; b[i] = -1; break; }
		for (i = now-1; i ; --i) if (f[i] == nowlen-1 && a[i] < a[now]){ g[now] = i; break; }
		if (!g[now]) for (i = now-1; i ; --i) if (a[i] == -1){ g[now] = i; break; }
		--nowlen,nowv = a[now],now = g[now];
	}
	for (i = 1; i <= n; ++i) if (a[i] == -1)
	for (j = 1; j <= m; ++j) if (b[j] != -1){ a[i] = b[j]; b[j] = -1; break; }
	for (i = 1; i < n; ++i) write(a[i]),putchar(i<n?' ':'\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 100005,M = 100005,INF = 1e9 + 9;

int mn[N],pos[N],mx;
int n,a[N],f[N],g[N];
int m,b[M];
int main(){
	int i,j,p;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]),mn[i] = INF; a[++n] = INF-1; mn[n] = INF;
	read(m);
	for (i = 1; i <= m; ++i) read(b[i]); sort(b+1,b+m+1);
	for (i = 1; i <= n; ++i){
		if (a[i] != -1){
			p = lower_bound(mn,mn+mx+1,a[i]) - mn;
			if (p > mx) ++mx;//,cerr<<i<<' '<<mx<<'\n';
			if (a[i] < mn[p]) mn[p] = a[i],pos[p] = i;
			f[i] = p,g[i] = pos[p-1];
			continue;
		}
		for (p = mx+1,j = m; j ; --j){
			while (p && b[j] <= mn[p-1]) --p;
			if (b[j] < mn[p]) mn[p] = b[j],pos[p] = i;
		}
		f[i] = -1;
		if (pos[mx+1]) ++mx;//,cerr<<i<<' '<<mx<<'\n';
	}
	int now = n,nowlen = f[n],nowv = a[n];
//	cerr<<"ans "<<f[n]-1<<'\n';
	while (nowlen){
	//	cerr<<nowlen<<' '<<now<<' ';
		if (a[now] != -1){
	//	cerr<<a[now]<<'\n';
		--nowlen,nowv = a[now],now = g[now]; continue; }
		for (i = m; i ; --i) if (b[i] != -1 && b[i] < nowv){
			a[now] = b[i]; b[i] = -1; break;
		}
	//	assert(a[i]);
		for (i = now-1; i ; --i)
			if (f[i] == nowlen-1 && a[i] < a[now]){ g[now] = i; break; }
		if (!g[now]) for (i = now-1; i ; --i) if (a[i] == -1){ g[now] = i; break; }
	//	cerr<<a[now]<<'\n';
		--nowlen,nowv = a[now],now = g[now];
	}
	for (i = 1; i <= n; ++i) if (a[i] == -1)
	for (j = 1; j <= m; ++j) if (b[j] != -1){ a[i] = b[j]; b[j] = -1; break; }
	for (i = 1; i < n; ++i) write(a[i]),putchar(i<n?' ':'\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 100005,M = 100005,INF = 1e9 + 9;

int mn[N],pos[N],mx;
int n,a[N],f[N],g[N];
int m,b[M];
int main(){
	int i,j,p;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]),mn[i] = INF; a[++n] = INF; mn[n] = INF;
	read(m);
	for (i = 1; i <= m; ++i) read(b[i]); sort(b+1,b+m+1);
	for (i = 1; i <= n; ++i){
		if (a[i] != -1){
			p = lower_bound(mn,mn+mx+1,a[i]) - mn;
			if (p > mx) ++mx;
			if (a[i] < mn[p]) mn[p] = a[i],pos[p] = i;
			f[i] = p,g[i] = pos[p-1];
			continue;
		}
		for (p = mx+1,j = m; j ; --j){
			while (p && b[j] <= mn[p-1]) --p;
			if (b[j] < mn[p]) mn[p] = b[j],pos[p] = i;
		}
		f[i] = -1;
		if (pos[mx+1]) ++mx;
	}
	int now = n,nowlen = f[n],nowv = a[n];
	while (nowlen){
		if (a[now] != -1){ --nowlen,nowv = a[now],now = g[now]; continue; }
		for (i = m; i ; --i) if (b[i] != -1 && b[i] < nowv){
			a[now] = b[i]; b[i] = -1; break;
		}
		if (nowlen == 1) break;
		for (i = now-1; i >= nowlen-1; --i)
			if (f[i] == nowlen-1 && a[i] < a[now]){ g[now] = i; break; }
		if (!g[i]) for (i = now-1; i ; --i) if (a[i] == -1){ g[now] = i; break; }
		--nowlen,nowv = a[now],now = g[now];
	}
	for (i = 1; i <= n; ++i) if (a[i] == -1)
	for (j = 1; j <= m; ++j) if (b[j] != -1){ a[i] = b[j]; b[j] = -1; break; }
	for (i = 1; i < n; ++i) write(a[i]),putchar(i<n?' ':'\n');
	return 0;
}