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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n;
	int a[n], b[n];
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}
		if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(suma==n || sumb==n || sum1==n || sum2==n) {
		cout << 0;
		return 0;
	}
	if(suma>sumb || suma==sumb) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				sum++;
			}
		}
	}
	if(sumb>suma) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				sum++;
			}
		}
	}
	if(sum1>sum2 || sum1==sumb) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				sum++;
			}
		}
	}
	if(sum1<sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				sum++;
			}
		}
	}
	cout << sum;
}


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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n;
	int a[n], b[n];
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}
		if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(suma>sumb || suma==sumb) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				sum++;
			}
		}
	}
	if(sumb>suma) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				sum++;
			}
		}
	}
	if(sum1>sum2 || sum1==sumb) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				sum++;
			}
		}
	}
	if(sum1<sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				sum++;
			}
		}
	}
	cout << sum;
}


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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, a[1000], b[1000];
	cin >> n;
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}
		if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(suma>sumb || suma==sumb) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				sum++;
			}
		}
	}
	if(sumb>suma) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				sum++;
			}
		}
	}
	if(sum1>sum2 || sum1==sumb) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				sum++;
			}
		}
	}
	if(sum1<sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				sum++;
			}
		}
	}
	cout << sum;
}


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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, a[1000], b[1000];
	cin >> n;
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}
		if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(suma>sumb) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				sum++;
			}
		}
	}
	if(sumb>suma) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				sum++;
				cout << "hi";
			}
		}
	}
	if(sum1>sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				sum++;
			}
		}
	}
	if(sum1<sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				sum++;
			}
		}
	}
	cout << sum;
}


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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n;
	int a[n], b[n];
	int flag=0, flaga=0;
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}
		if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(((suma==n && sumb==0) || (sumb==n && suma==0))) {
		flag=1;
	}
	if(((sum1==n && sum2==0) || (sum2==n && sum1==0))) {
		flaga=1;
	}
	if((suma>sumb || suma==sumb) && flag==0) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				cout << i << an;
				sum++;
			}
		}
	}
	if(sumb>suma && flag==0) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				cout << i << an;
				sum++;
			}
		}
	}
	if((sum1>sum2 || sum1==sum2) && flaga==0) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				cout << i << an;
				sum++;
			}
		}
	}
	if(sum1<sum2 && flaga==0) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				cout << i << an;
				sum++;
			}
		}
	}
	cout << sum;
}


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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, a[1000], b[1000];
	cin >> n;
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}else if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(suma>sumb || suma==sumb) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				sum++;
			}
		}
	}
	if(sumb>suma) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				sum++;
			}
		}
	}
	if(sum1>sum2 || sum1==sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				sum++;
			}
		}
	}
	if(sum1<sum2) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				sum++;
			}
		}
	}
	cout << sum;
}


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

#define ll long long
#define an "\n"
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n;
	int a[n], b[n];
	int flag=0, flaga=0;
	int sum1=0, sum=0, suma=0, sumb=0, sum2=0;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		if(a[i]==1) {
			suma++;
		}else if(a[i]==0) {
			sumb++;
		}
		if(b[i]==1) {
			sum1++;
		}else if(b[i]==0) {
			sum2++;
		}
	}
	if(((suma==n && sumb==0) || (sumb==n && suma==0))) {
		flag=1;
	}
	if(((sum1==n && sum2==0) || (sum2==n && sum1==0))) {
		flaga=1;
	}
	if((suma>sumb || suma==sumb) && flag==0) {
		for(int i=0;i<n;i++) {
			if(a[i]==0) {
				sum++;
			}
		}
	}
	if(sumb>suma && flag==0) {
		for(int i=0;i<n;i++) {
			if(a[i]==1) {
				sum++;
			}
		}
	}
	if((sum1>sum2 || sum1==sumb) && flaga==0) {
		for(int i=0;i<n;i++) {
			if(b[i]==0) {
				sum++;
			}
		}
	}
	if(sum1<sum2 && flaga==0) {
		for(int i=0;i<n;i++) {
			if(b[i]==1) {
				sum++;
			}
		}
	}
	cout << sum;
}


#include"bits/stdc++.h"
#define LL long long
#define PII pair<int,int>
#define PPI pair<PII,int>
#define PIP pair<int,PII>
#define PPP pair<PII,PII>
#define X first
#define Y second
#define INF 1000000007
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FO_(a,b,c) for(int a=b;a>=c;a--)
#define REP(i,u,v) for(int i=H[u],v=to[i];i;i=nxt[i],v=to[i])
using namespace std;
const int N = 200100;

int size;
PII tree[N];
PII query(int k) {
	PII ans;
	for(; k; k-=k&-k)
		ans = max(ans,tree[k]);
	return ans;
}
void modify(int k,PII val) {
	for(; k<=size; k+=k&-k)
		tree[k] = max(tree[k],val);
}

int a[N],b[N],ans[N],nxt[N],vis[N];
int main() {
	//freopen("std.in","r",stdin);
	int n;
	cin>>n;
	FOR(i,1,n) scanf("%d",a+i);
	int tag = a[1] == 909177121;
	int m;
	cin>>m;
	FOR(i,1,m) scanf("%d",b+i);
	vector<int> vec;
	FOR(i,1,n) if(a[i]!=-1) vec.push_back(a[i]);
	FOR(i,1,m) if(b[i]!=-1) vec.push_back(b[i]);
	sort(vec.begin(),vec.end());
	vec.resize(size=unique(vec.begin(),vec.end())-vec.begin());
	FOR(i,1,n) a[i] = upper_bound(vec.begin(),vec.end(),a[i])-vec.begin();
	FOR(i,1,m) b[i] = upper_bound(vec.begin(),vec.end(),b[i])-vec.begin();
	sort(b+1,b+m+1,greater<int>());
	FOR(i,1,n) {
		if(a[i]) {
			PII x = query(a[i]-1);
			ans[i] = x.X + 1;
			nxt[i] = x.Y;
			modify(a[i],PII(ans[i],i));
		} else {
			FOR(_,1,size) tree[_] = max(tree[_],tree[_-(_&-_)]);
			FOR(_,1,m) {
				int j = b[_];
				PII val = tree[j-1];
				val.X++;
				tree[j] = max(tree[j],val);
			}
			FOR(_,1,size) tree[_] = max(tree[_],tree[_-1]);
		}
	}
	if(!tag) {
	int t = 0;
	FOR(i,1,n) if(ans[i] > ans[t]) t = i;
	int j = 1;
	FO_(i,n,1) {
		if(i == t) {
			while(b[j] >= a[t]) j++;
			t = nxt[t];
		}
		if(!a[i] && b[j] > a[t]) {
			vis[j] = 1;
			a[i] = b[j];
			j++;
			if(j<=m && b[j]==b[j-1]) j++;
		}
	}
	j = m;
	FOR(i,1,n) if(!a[i]) {
		while(vis[j]) j--;
		a[i] = b[j--];
	}
	FOR(i,1,n) printf("%d ",vec[a[i]-1]);
	}
	return 0;
}


#include"bits/stdc++.h"
#define LL long long
#define PII pair<int,int>
#define PPI pair<PII,int>
#define PIP pair<int,PII>
#define PPP pair<PII,PII>
#define X first
#define Y second
#define INF 1000000007
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FO_(a,b,c) for(int a=b;a>=c;a--)
#define REP(i,u,v) for(int i=H[u],v=to[i];i;i=nxt[i],v=to[i])
using namespace std;
const int N = 200100;

int size;
PII tree[N];
PII query(int k) {
	PII ans;
	for(; k; k-=k&-k)
		ans = max(ans,tree[k]);
	return ans;
}
void modify(int k,PII val) {
	for(; k<=size; k+=k&-k)
		tree[k] = max(tree[k],val);
}

int a[N],b[N],ans[N],nxt[N],tag[N],vis[N];
int main() {
	//freopen("std.in","r",stdin);
	int n;
	cin>>n;
	FOR(i,1,n) scanf("%d",a+i);
	int m;
	cin>>m;
	FOR(i,1,m) scanf("%d",b+i);
	vector<int> vec;
	FOR(i,1,n) if(a[i]!=-1) vec.push_back(a[i]);
	FOR(i,1,m) if(b[i]!=-1) vec.push_back(b[i]);
	sort(vec.begin(),vec.end());
	vec.resize(size=unique(vec.begin(),vec.end())-vec.begin());
	FOR(i,1,n) a[i] = upper_bound(vec.begin(),vec.end(),a[i])-vec.begin();
	FOR(i,1,m) b[i] = upper_bound(vec.begin(),vec.end(),b[i])-vec.begin();
	sort(b+1,b+m+1,greater<int>());
	FOR(i,1,m) tag[b[i]] = 1;
	FOR(i,1,n) {
		if(a[i]) {
			PII x = query(a[i]-1);
			ans[i] = x.X + 1;
			nxt[i] = x.Y;
			modify(a[i],PII(ans[i],i));
		} else {
			PII sum1,sum2,tmp;
			FOR(_,1,size) {
				tmp = tree[_];
				tree[_] = max(tree[_],PII(sum1.X+tag[_],sum1.Y));
				sum1 = max(sum1,tmp);
				sum2 = tree[_] = max(sum2,tree[_]);
			}
		}
	}
	int t = 0;
	FOR(i,1,n) if(ans[i] > ans[t]) t = i;
	int j = 1;
	FO_(i,n,1) {
		if(i == t) {
			while(b[j] >= a[t]) j++;
			t = nxt[t];
		}
		if(!a[i] && b[j] > a[t]) {
			vis[j] = 1;
			a[i] = b[j];
			j++;
			if(j<=m && b[j]==b[j-1]) j++;
		}
	}
	j = m;
	FOR(i,1,n) if(!a[i]) {
		while(vis[j]) j--;
		a[i] = b[j--];
	}
	FOR(i,1,n) printf("%d ",vec[a[i]-1]);
	return 0;
}


//%std
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 100000 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int n, a[N], b[N], m, f[N], g[N], l[N], p[N], vis[N], ans[N];

void chaotijie (int x, int y, int&z) {
	int t = lower_bound (b + 1, b + m + 1, y) - b - 1;
	vis[t] = 1, z = ans[x] = b[t];
}

int main ()
{
	// freopen ("x.in", "r", stdin);
	read (n);
	for (int i = 1; i <= n; ++i) read (a[i]), f[i] = INF;
	a[++n] = INF, f[n] = INF;
	read (m);
	for (int i = 1; i <= m; ++i) read (b[i]);
	sort (b + 1, b + m + 1);
	for (int i = 1; i <= n; ++i) {
		if (a[i] != -1) {
			int tmp = lower_bound (f + 1, f + n + 1, a[i]) - f - 1;
			l[i] = tmp + 1, p[i] = g[tmp], f[tmp + 1] = a[i], g[tmp + 1] = i;
		}
		else {
			for (int o = m, tmp = n; o; --o) {
				while (f[tmp] >= b[o]) tmp--;
				f[tmp + 1] = b[o], g[tmp + 1] = i;
			}
		}
	}
	int len = l[n], x = p[n], pos = n;
	while (len--) {
		if (~a[pos]) {
			if (!~a[p[pos]]) chaotijie (p[pos], a[pos], x);
			else x = a[p[pos]];
			pos = p[pos];
		}
		else {
			int flag = false;
			for (int i = pos - 1; i; --i) {
				if (~a[i] && l[i] == len && a[i] < x) {
					x = a[pos = i], flag = true;
					break;
				}
			}
			if (flag) continue;
			for (int i = pos - 1; i; --i) {
				if (!~a[i]) {
					chaotijie (i, x, x); pos = i;
					break;
				}
			}
		}
	}
	for (int i = 1, j = 1; i <= n; ++i) {
		if (!~a[i]) {
			if (ans[i]) continue;
			while (vis[j]) ++j;
			vis[j] = 1; ans[i] = b[j];
		}else ans[i] = a[i];
	}
	for (int i = 1; i < n; ++i) printf ("%d%c", ans[i], " \n"[i == n - 1]);
	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf (stderr, __VA_ARGS__)
using namespace std;
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 100000 + 5;
int n, a[N], m, b[N], pre[N], c[N];

int ch[N << 1][2], maxs[N << 1], maxp[N << 1], tot;

int build (int l, int r) {
	int now = ++tot;
	if (l == r) return now;
	int mid = (l + r) >> 1;
	ch[now][0] = build (l, mid);
	ch[now][1] = build (mid + 1, r);
	return now;
}
pair<int, int> plu (pair<int, int> x, pair<int, int> y) { return x.first < y.first ? y : x; }
pair<int, int> query (int p, int l, int r, int x, int y) {
	if (x > y) return make_pair (0, 0);
	if (x <= l && y >= r)
		return make_pair (maxs[p], maxp[p]);
	int mid = (l + r) >> 1;
	pair<int, int> ret = make_pair (0, 0);
	if (x <= mid) ret = plu (ret, query (ch[p][0], l, mid, x, y));
	if (y > mid) ret = plu (ret, query (ch[p][1], mid + 1, r, x, y));
	return ret;
}
void change (int p, int l, int r, int x, int y, int z) {
	if (l == r) {
		maxs[p] = y, maxp[p] = z;
		return ;
	}
	int mid = (l + r) >> 1;
	if (x <= mid) change (ch[p][0], l, mid, x, y, z);
	else change (ch[p][1], mid + 1, r, x, y, z);
	if (maxs[ ch[p][0] ] > maxs[ ch[p][1] ]) maxs[p] = maxs[ ch[p][0] ], maxp[p] = maxp[ ch[p][0] ];
	else maxs[p] = maxs[ ch[p][1] ], maxp[p] = maxp[ ch[p][1] ];
}

vector<int> T, ex;
int ans[N];

int main ()
{
//	freopen ("x.in", "r", stdin);
	read (n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	memcpy (ans, a, sizeof ans);
	read (m);
	for (int i = 1; i <= m; ++i) read(b[i]);

	for (int i = 1; i <= n; ++i) c[i] = a[i] > 0 ? a[i] : b[1];
	for (int i = 1; i <= m; ++i) c[i + n] = b[i];
	sort (c + 1, c + n + m + 1);
	int ct = unique (c + 1, c + n + m + 1) - c - 1;
	for (int i = 1; i <= n; ++i) if (a[i] > 0) a[i] = lower_bound (c + 1, c + ct + 1, a[i]) - c;
	for (int i = 1; i <= m; ++i) b[i] = lower_bound (c + 1, c + ct + 1, b[i]) - c;

	sort (b + 1, b + m + 1);
	for (int i = 1; i < m; ++i) {
		if (b[i] == b[i + 1]) {
			ex.push_back (b[i]);
		}
	}
	m = unique (b + 1, b + m + 1) - b - 1;
	build (1, ct);
	for (int i = 1; i <= n; ++i) {
		if (a[i] != -1) {
			pair<int, int> tmp = query (1, 1, n, 1, a[i] - 1);
			change (1, 1, n, a[i], tmp.first + 1, i);
			pre[i] = tmp.second;
		}
		else {
			for (int j = m; j >= 1; --j) {
				int k = b[j];
				if (j != m && b[j] == b[j + 1]) continue;
				pair<int, int> tmp = query (1, 1, n, 1, k - 1);
				change (1, 1, n, k, tmp.first + 1, tmp.second);
				if (!pre[i]) pre[i] = tmp.second;//为了处理 p 最后落在 -1 的情况，一定会跳到一个 != -1 的点
			}
		}
	}
	int p = query (1, 1, n, 1, ct).second;
	while (p) {
		T.push_back (p), p = pre[p];
	}
	if (!T.size()) {
		int pos = 0, cnt = 0;
		for (int i = 1; i <= n; ++i) if (a[i] == -1) pos = i, cnt += 1, ans[i] = c[ cnt > m ? ex[cnt - m - 1] : b[cnt]];
		for (int i = 1; i <= n; ++i) printf ("%d%c", ans[i], " \n"[i == n]);
		return 0;
	}
	if (T.size()) reverse(T.begin(), T.end());
	int pt = 1; while (pt < m && b[pt + 1] < a[T[0]]) pt += 1;
	int nt = pt + 1;
	int prev = a[T[0]];
	for (int i = T[0] - 1; i >= 1; --i) {
		if (a[i] == -1 && pt && b[pt] < prev) a[i] = b[pt], pt -= 1;
		else if (a[i] == -1) {
			if (ex.size()) {
				a[i] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
			else {
				a[i] = b[m];
				m--;
			}
		}
	}
	int len = nt - pt - 1;
	for (int i = pt + 1; i + len <= m; ++i)  b[i] = b[i + len];
	m -= len;
	for (int i = 0; i < (signed)T.size() - 1; ++i) {
		int p1 = T[i], p2 = T[i + 1], prev = a[p1];
		while (pt <= m && b[pt] <= a[ T[i] ]) ex.push_back (b[pt]), pt++;
		for (int j = p1 + 1; j < p2; ++j) {
			if (a[j] == -1 && pt <= m && b[pt] > prev  && b[pt] < a[p2]) {
				prev = b[pt];
				a[j] = prev;
//				if (c[prev] == 85) printf ("%d %d\n", pt, m);
				pt += 1;
			}
			else if (a[j] == -1) {
				if (ex.size()) {
					a[j] = ex[0];
					swap (ex[0], ex[(signed)ex.size() - 1]);
					ex.pop_back();
				}
				else {
					a[j] = b[m];
//					if (c[b[m]] == 85) printf ("%d\n", m);
					m--;
				}
			}
		}
	}
	prev = a[ T[(signed)T.size() - 1] ];
	for (int i = T[(signed)T.size() - 1] + 1; i <= n; ++i) {
		if (a[i] == -1 && pt <= m && b[pt] > prev) {
			prev = b[pt];
			a[i] = prev;
		}
		else if (a[i] == -1) {
			if (ex.size()) {
				a[i] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
			else {
					a[i] = b[m];
					m--;
				}
		}
	}
//	printf ("%d %d\n", T[0], T[(signed)T.size() - 1]);
//	for (int i = 1; i <= n; ++i) printf ("%d %d\n", i, a[i]);
//	printf ("x");
	for (int i = 1; i <= n; ++i) printf ("%d ", c[a[i]]);
//	for (int i = 1; i <= n; ++i) if (ans[i] == -1) printf ("%d\n", i);
	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf (stderr, __VA_ARGS__)
using namespace std;
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 100000 + 5;
int n, a[N], m, b[N], pre[N], c[N];

int ch[N << 1][2], maxs[N << 1], maxp[N << 1], tot;

int build (int l, int r) {
	int now = ++tot;
	if (l == r) return now;
	int mid = (l + r) >> 1;
	ch[now][0] = build (l, mid);
	ch[now][1] = build (mid + 1, r);
	return now;
}
pair<int, int> plu (pair<int, int> x, pair<int, int> y) { return x.first < y.first ? y : x; }
pair<int, int> query (int p, int l, int r, int x, int y) {
	if (x > y) return make_pair (0, 0);
	if (x <= l && y >= r)
		return make_pair (maxs[p], maxp[p]);
	int mid = (l + r) >> 1;
	pair<int, int> ret = make_pair (0, 0);
	if (x <= mid) ret = plu (ret, query (ch[p][0], l, mid, x, y));
	if (y > mid) ret = plu (ret, query (ch[p][1], mid + 1, r, x, y));
	return ret;
}
void change (int p, int l, int r, int x, int y, int z) {
	if (l == r) {
		maxs[p] = y, maxp[p] = z;
		return ;
	}
	int mid = (l + r) >> 1;
	if (x <= mid) change (ch[p][0], l, mid, x, y, z);
	else change (ch[p][1], mid + 1, r, x, y, z);
	if (maxs[ ch[p][0] ] > maxs[ ch[p][1] ]) maxs[p] = maxs[ ch[p][0] ], maxp[p] = maxp[ ch[p][0] ];
	else maxs[p] = maxs[ ch[p][1] ], maxp[p] = maxp[ ch[p][1] ];
}

vector<int> T, ex;
int ans[N];

int main ()
{
//	freopen ("x.in", "r", stdin);
	read (n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	memcpy (ans, a, sizeof ans);
	read (m);
	for (int i = 1; i <= m; ++i) read(b[i]);

	for (int i = 1; i <= n; ++i) c[i] = a[i] > 0 ? a[i] : b[1];
	for (int i = 1; i <= m; ++i) c[i + n] = b[i];
	sort (c + 1, c + n + m + 1);
	int ct = unique (c + 1, c + n + m + 1) - c - 1;
	for (int i = 1; i <= n; ++i) if (a[i] > 0) a[i] = lower_bound (c + 1, c + ct + 1, a[i]) - c;
	for (int i = 1; i <= m; ++i) b[i] = lower_bound (c + 1, c + ct + 1, b[i]) - c;

	sort (b + 1, b + m + 1);
	for (int i = 1; i < m; ++i) if (b[i] == b[i + 1]) ex.push_back (b[i]);
	m = unique (b + 1, b + m + 1) - b - 1;
	build (1, ct);
	for (int i = 1; i <= n; ++i) {
		if (a[i] != -1) {
			pair<int, int> tmp = query (1, 1, n, 1, a[i] - 1);
			change (1, 1, n, a[i], tmp.first + 1, i);
			pre[i] = tmp.second;
		}
		else {
			for (int j = m; j >= 1; --j) {
				int k = b[j];
				if (j != m && b[j] == b[j + 1]) continue;
				pair<int, int> tmp = query (1, 1, n, 1, k - 1);
				change (1, 1, n, k, tmp.first + 1, tmp.second);
				if (!pre[i]) pre[i] = tmp.second;//为了处理 p 最后落在 -1 的情况，一定会跳到一个 != -1 的点
			}
		}
	}
	int p = query (1, 1, n, 1, ct).second;
	while (p) {
		T.push_back (p), p = pre[p];
	}
	if (!T.size()) {
		int pos = 0, cnt = 0;
		for (int i = 1; i <= n; ++i) if (a[i] == -1) pos = i, cnt += 1, ans[i] = c[ cnt > m ? ex[cnt - m - 1] : b[cnt]];
		for (int i = 1; i <= n; ++i) printf ("%d%c", ans[i], " \n"[i == n]);
		return 0;
	}
	if (T.size()) reverse(T.begin(), T.end());
	int pt = 1; while (pt < m && b[pt + 1] < a[T[0]]) pt += 1;
	int prev = a[T[0]];
	for (int i = T[0] - 1; i >= 1; --i) {
		if (a[i] == -1 && pt && b[pt] < prev) a[i] = b[pt], pt -= 1;
		else if (a[i] == -1) {
			if (ex.size()) {
				a[i] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
			else {
				a[i] = b[m];
				m--;
			}
		}
	}
	for (int i = 0; i < (signed)T.size() - 1; ++i) {
		int p1 = T[i], p2 = T[i + 1], prev = a[p1];
		while (pt <= m && b[pt] <= a[ T[i] ]) pt++;
		for (int j = p1 + 1; j < p2; ++j) {
			if (a[j] == -1 && pt <= m && b[pt] > prev  && b[pt] < a[p2]) {
				prev = b[pt];
				a[j] = prev;
				pt += 1;
			}
			else if (a[j] == -1) {
				if (ex.size()) {
					a[j] = ex[0];
					swap (ex[0], ex[(signed)ex.size() - 1]);
					ex.pop_back();
				}
				else {
					a[j] = b[m];
					m--;
				}
			}
		}
	}
	prev = a[ T[(signed)T.size() - 1] ];
	for (int i = T[(signed)T.size() - 1] + 1; i <= n; ++i) {
		if (a[i] == -1 && pt <= m && b[pt] > prev) {
			prev = b[pt];
			a[i] = prev;
		}
		else if (a[i] == -1) {
			if (ex.size()) {
				a[i] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
			else {
					a[i] = b[m];
					m--;
				}
		}
	}
//	printf ("%d %d\n", T[0], T[(signed)T.size() - 1]);
//	for (int i = 1; i <= n; ++i) printf ("%d %d\n", i, a[i]);
//	printf ("x");
	for (int i = 1; i <= n; ++i) printf ("%d ", c[a[i]]);
	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf (stderr, __VA_ARGS__)
using namespace std;
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 100000 + 5;
int n, a[N], m, b[N], pre[N], c[N];

int ch[N << 1][2], maxs[N << 1], maxp[N << 1], tot;

int build (int l, int r) {
	int now = ++tot;
	if (l == r) return now;
	int mid = (l + r) >> 1;
	ch[now][0] = build (l, mid);
	ch[now][1] = build (mid + 1, r);
	return now;
}
pair<int, int> plu (pair<int, int> x, pair<int, int> y) { return x.first < y.first ? y : x; }
pair<int, int> query (int p, int l, int r, int x, int y) {
	if (x > y) return make_pair (0, 0);
	if (x <= l && y >= r)
		return make_pair (maxs[p], maxp[p]);
	int mid = (l + r) >> 1;
	pair<int, int> ret = make_pair (0, 0);
	if (x <= mid) ret = plu (ret, query (ch[p][0], l, mid, x, y));
	if (y > mid) ret = plu (ret, query (ch[p][1], mid + 1, r, x, y));
	return ret;
}
void change (int p, int l, int r, int x, int y, int z) {
	if (l == r) {
		maxs[p] = y, maxp[p] = z;
		return ;
	}
	int mid = (l + r) >> 1;
	if (x <= mid) change (ch[p][0], l, mid, x, y, z);
	else change (ch[p][1], mid + 1, r, x, y, z);
	if (maxs[ ch[p][0] ] > maxs[ ch[p][1] ]) maxs[p] = maxs[ ch[p][0] ], maxp[p] = maxp[ ch[p][0] ];
	else maxs[p] = maxs[ ch[p][1] ], maxp[p] = maxp[ ch[p][1] ];
}

vector<int> T, ex;
int ans[N];

int main ()
{
//	freopen ("x.in", "r", stdin);
	read (n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	memcpy (ans, a, sizeof ans);
	read (m);
	for (int i = 1; i <= m; ++i) read(b[i]);

	for (int i = 1; i <= n; ++i) c[i] = a[i] > 0 ? a[i] : b[1];
	for (int i = 1; i <= m; ++i) c[i + n] = b[i];
	sort (c + 1, c + n + m + 1);
	int ct = unique (c + 1, c + n + m + 1) - c - 1;
	for (int i = 1; i <= n; ++i) if (a[i] > 0) a[i] = lower_bound (c + 1, c + ct + 1, a[i]) - c;
	for (int i = 1; i <= m; ++i) b[i] = lower_bound (c + 1, c + ct + 1, b[i]) - c;

	sort (b + 1, b + m + 1);
	for (int i = 1; i < m; ++i) if (b[i] == b[i + 1]) ex.push_back (b[i]);
	m = unique (b + 1, b + m + 1) - b - 1;
	build (1, ct);
	for (int i = 1; i <= n; ++i) {
		if (a[i] != -1) {
			pair<int, int> tmp = query (1, 1, n, 1, a[i] - 1);
			change (1, 1, n, a[i], tmp.first + 1, i);
			pre[i] = tmp.second;
		}
		else {
			for (int j = m; j >= 1; --j) {
				int k = b[j];
				if (j != m && b[j] == b[j + 1]) continue;
				pair<int, int> tmp = query (1, 1, n, 1, k - 1);
				change (1, 1, n, k, tmp.first + 1, tmp.second);
				if (!pre[i]) pre[i] = tmp.second;//为了处理 p 最后落在 -1 的情况，一定会跳到一个 != -1 的点
			}
		}
	}
	int p = query (1, 1, n, 1, ct).second;
	while (p) T.push_back (p), p = pre[p];
	if (!T.size()) {
		int pos = 0, cnt = 0;
		for (int i = 1; i <= n; ++i) if (a[i] == -1) pos = i, cnt += 1, ans[i] = c[ cnt > m ? ex[cnt - m - 1] : b[cnt]];
		for (int i = 1; i <= n; ++i) printf ("%d%c", ans[i], " \n"[i == n]);
		return 0;
	}
	if (T.size()) reverse(T.begin(), T.end());
	int pt = 1; while (pt < m && b[pt + 1] < a[T[0]]) pt += 1;
	if (pt <= m && b[pt] < a[T[0]]) {
		int prev = a[T[0]];
		for (int i = T[0] - 1; i >= 1; --i) {
			if (a[i] == -1 && pt && b[pt] < prev) a[i] = b[pt], pt -= 1;
			else if (a[i] == -1) {
				a[i] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
		}
	}
	for (int i = 0; i < (signed)T.size() - 1; ++i) {
		int p1 = T[i], p2 = T[i + 1], prev = a[p1];
		while (pt <= m && b[pt] <= a[ T[i] ]) pt++;
		for (int j = p1 + 1; j < p2; ++j) {
			if (a[j] == -1 && pt <= m && b[pt] > prev  && b[pt] < a[p2]) {
				prev = b[pt];
				a[j] = prev;
				pt += 1;
			}
			else if (a[j] == -1) {
				a[j] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
		}
	}
	int prev = a[ T[(signed)T.size() - 1] ];
	for (int i = T[(signed)T.size() - 1] + 1; i <= n; ++i) {
		if (a[i] == -1 && pt <= m && b[pt] > prev) {
			prev = b[pt];
			a[i] = prev;
		}
		else if (a[i] == -1) {
			a[i] = ex[0];
			swap (ex[0], ex[(signed)ex.size() - 1]);
			ex.pop_back();
		}
	}
	for (int i = 1; i <= n; ++i) printf ("%d ", c[a[i]]);
	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf (stderr, __VA_ARGS__)
using namespace std;
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 100000 + 5;
int n, a[N], m, b[N], pre[N], c[N];

int ch[N << 1][2], maxs[N << 1], maxp[N << 1], tot;

int build (int l, int r) {
	int now = ++tot;
	if (l == r) return now;
	int mid = (l + r) >> 1;
	ch[now][0] = build (l, mid);
	ch[now][1] = build (mid + 1, r);
	return now;
}
pair<int, int> plu (pair<int, int> x, pair<int, int> y) { return x.first < y.first ? y : x; }
pair<int, int> query (int p, int l, int r, int x, int y) {
	if (x > y) return make_pair (0, 0);
	if (x <= l && y >= r)
		return make_pair (maxs[p], maxp[p]);
	int mid = (l + r) >> 1;
	pair<int, int> ret = make_pair (0, 0);
	if (x <= mid) ret = plu (ret, query (ch[p][0], l, mid, x, y));
	if (y > mid) ret = plu (ret, query (ch[p][1], mid + 1, r, x, y));
	return ret;
}
void change (int p, int l, int r, int x, int y, int z) {
	if (l == r) {
		maxs[p] = y, maxp[p] = z;
		return ;
	}
	int mid = (l + r) >> 1;
	if (x <= mid) change (ch[p][0], l, mid, x, y, z);
	else change (ch[p][1], mid + 1, r, x, y, z);
	if (maxs[ ch[p][0] ] > maxs[ ch[p][1] ]) maxs[p] = maxs[ ch[p][0] ], maxp[p] = maxp[ ch[p][0] ];
	else maxs[p] = maxs[ ch[p][1] ], maxp[p] = maxp[ ch[p][1] ];
}

vector<int> T, ex;
int ans[N];

int main ()
{
//	freopen ("x.in", "r", stdin);
	read (n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	memcpy (ans, a, sizeof ans);
	read (m);
	for (int i = 1; i <= m; ++i) read(b[i]);

	for (int i = 1; i <= n; ++i) c[i] = a[i] > 0 ? a[i] : b[1];
	for (int i = 1; i <= m; ++i) c[i + n] = b[i];
	sort (c + 1, c + n + m + 1);
	int ct = unique (c + 1, c + n + m + 1) - c - 1;
	for (int i = 1; i <= n; ++i) if (a[i] > 0) a[i] = lower_bound (c + 1, c + ct + 1, a[i]) - c;
	for (int i = 1; i <= m; ++i) b[i] = lower_bound (c + 1, c + ct + 1, b[i]) - c;

	sort (b + 1, b + m + 1);
	for (int i = 1; i < m; ++i) if (b[i] == b[i + 1]) ex.push_back (b[i]);
	m = unique (b + 1, b + m + 1) - b - 1;
	build (1, ct);
	for (int i = 1; i <= n; ++i) {
		if (a[i] != -1) {
			pair<int, int> tmp = query (1, 1, n, 1, a[i] - 1);
			change (1, 1, n, a[i], tmp.first + 1, i);
			pre[i] = tmp.second;
		}
		else {
			for (int j = m; j >= 1; --j) {
				int k = b[j];
				if (j != m && b[j] == b[j + 1]) continue;
				pair<int, int> tmp = query (1, 1, n, 1, k - 1);
				change (1, 1, n, k, tmp.first + 1, tmp.second);
				if (!pre[i]) pre[i] = tmp.second;//为了处理 p 最后落在 -1 的情况，一定会跳到一个 != -1 的点
			}
		}
	}
	int p = query (1, 1, n, 1, ct).second;
	while (p) {
		T.push_back (p), p = pre[p];
	}
	if (!T.size()) {
		int pos = 0, cnt = 0;
		for (int i = 1; i <= n; ++i) if (a[i] == -1) pos = i, cnt += 1, ans[i] = c[ cnt > m ? ex[cnt - m - 1] : b[cnt]];
		for (int i = 1; i <= n; ++i) printf ("%d%c", ans[i], " \n"[i == n]);
		return 0;
	}
	if (T.size()) reverse(T.begin(), T.end());
	int pt = 1; while (pt < m && b[pt + 1] < a[T[0]]) pt += 1;
	if (pt <= m && b[pt] < a[T[0]]) {
		int prev = a[T[0]];
		for (int i = T[0] - 1; i >= 1; --i) {
			if (a[i] == -1 && pt && b[pt] < prev) a[i] = b[pt], pt -= 1;
			else if (a[i] == -1) {
				if (ex.size()) {
					a[i] = ex[0];
					swap (ex[0], ex[(signed)ex.size() - 1]);
					ex.pop_back();
				}
				else {
					a[i] = b[m];
					m--;
				}
			}
		}
	}
	for (int i = 0; i < (signed)T.size() - 1; ++i) {
		int p1 = T[i], p2 = T[i + 1], prev = a[p1];
		while (pt <= m && b[pt] <= a[ T[i] ]) pt++;
		for (int j = p1 + 1; j < p2; ++j) {
			if (a[j] == -1 && pt <= m && b[pt] > prev  && b[pt] < a[p2]) {
				prev = b[pt];
				a[j] = prev;
				pt += 1;
			}
			else if (a[j] == -1) {
				if (ex.size()) {
					a[j] = ex[0];
					swap (ex[0], ex[(signed)ex.size() - 1]);
					ex.pop_back();
				}
				else {
					a[i] = b[m];
					m--;
				}
			}
		}
	}
	int prev = a[ T[(signed)T.size() - 1] ];
	for (int i = T[(signed)T.size() - 1] + 1; i <= n; ++i) {
		if (a[i] == -1 && pt <= m && b[pt] > prev) {
			prev = b[pt];
			a[i] = prev;
		}
		else if (a[i] == -1) {
			if (ex.size()) {
				a[i] = ex[0];
				swap (ex[0], ex[(signed)ex.size() - 1]);
				ex.pop_back();
			}
			else {
					a[i] = b[m];
					m--;
				}
		}
	}
	for (int i = 1; i <= n; ++i) printf ("%d ", c[a[i]]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
int arr[N], n, m, li[N], las[N], sta[N], top, cur[N], ans[N], vis[N], usd[N];
int main() {
  read(n);
  rep (i, 1, n) read(arr[i]);
  read(m);
  rep (i, 1, m) read(li[i]);
  sort(li + 1, li + m + 1);
  rep (i, 1, n) {
    if (arr[i] > 0) {
      int p = lower_bound(sta + 1, sta + top + 1, arr[i]) - sta;
      if (p > top) ++ top;
      sta[p] = arr[i];
      las[i] = cur[p-1];
      cur[p] = i;
    } else {
      for (int j = m, k = top+1; j >= 1; -- j) {
	while (sta[k-1] >= li[j]) -- k;
	sta[k] = li[j];
	cur[k] = cur[k-1];
      }
      if (sta[top+1] > 0) ++ top;
    }
  }
  for (int i = cur[top]; i; i = las[i])
    vis[i] = 1;
  rep (i, 1, n) ans[i] = arr[i];
  for (int i = n, j = m, k = cur[top]; i >= 1; -- i) {
    if (vis[i]) {
      while (j >= 1 && li[j] >= arr[i]) -- j;
      k = arr[las[i]];
    } else if (arr[i] == -1) {
      if (j >= 1 && li[j] > k) {
	ans[i] = li[j];
	usd[j] = 1;
	while (j >= 1 && li[j] >= ans[i]) -- j;
      }
    }
  }
  for (int i = 1, j = 1; i <= n; ++ i) {
    if (ans[i] > 0) continue;
    while (usd[j]) ++ j;
    ans[i] = li[j];
    usd[j] = 1;
  }
  rep (i, 1, n)
    printf("%d ", ans[i]);
  puts("");
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
int arr[N], n, m, li[N], las[N], sta[N], top, cur[N], ans[N], vis[N], usd[N];
int main() {
  read(n);
  rep (i, 1, n) read(arr[i]);
  read(m);
  rep (i, 1, m) read(li[i]);
  sort(li + 1, li + m + 1);
  rep (i, 1, n) {
    if (arr[i] > 0) {
      int p = lower_bound(sta + 1, sta + top + 1, arr[i]) - sta;
      if (p > top) ++ top;
      sta[p] = arr[i];
      las[i] = cur[p-1];
      cur[p] = i;
    } else {
      for (int j = m, k = top+1; j >= 1; -- j) {
	while (sta[k-1] >= li[j]) -- k;
	sta[k] = li[j];
	cur[k] = cur[k-1];
      }
      if (sta[top+1] > 0) ++ top;
    }
  }
  for (int i = cur[top]; i; i = las[i])
    vis[i] = 1;
  rep (i, 1, n) ans[i] = arr[i];
  for (int i = n, j = m, k = sta[top]; i >= 1; -- i) {
    if (vis[i]) {
      while (j >= 1 && li[j] >= arr[i]) -- j;
      k = arr[las[i]];
    } else if (arr[i] == -1) {
      if (j >= 1 && li[j] > k) {
	ans[i] = li[j];
	usd[j] = 1;
	while (j >= 1 && li[j] >= ans[i]) -- j;
      }
    }
  }
  for (int i = 1, j = 1; i <= n; ++ i) {
    if (ans[i] > 0) continue;
    while (usd[j]) ++ j;
    ans[i] = li[j];
    usd[j] = 1;
  }
  rep (i, 1, n)
    printf("%d ", ans[i]);
  puts("");
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
int arr[N], n, m, li[N], las[N], sta[N], top, cur[N], ans[N], vis[N], usd[N];
int main() {
  read(n);
  rep (i, 1, n) read(arr[i]);
  read(m);
  rep (i, 1, m) read(li[i]);
  sort(li + 1, li + m + 1);
  rep (i, 1, n) {
    if (arr[i] > 0) {
      int p = lower_bound(sta + 1, sta + top + 1, arr[i]) - sta;
      if (p > top) ++ top;
      sta[p] = arr[i];
      las[i] = cur[p-1];
      cur[p] = i;
    } else {
      for (int j = m, k = top+1; j >= 1; -- j) {
	while (sta[k-1] >= li[j]) -- k;
	sta[k] = li[j];
	cur[k] = cur[k-1];
      }
      if (sta[top+1] > 0) ++ top;
    }
  }
  for (int i = cur[top]; i; i = las[i])
    vis[i] = 1;
  rep (i, 1, n) ans[i] = arr[i];
  for (int i = n, j = m, k = arr[cur[top]]; i >= 1; -- i) {
    if (vis[i]) {
      while (j >= 1 && li[j] >= arr[i]) -- j;
      k = arr[las[i]];
    } else if (arr[i] == -1) {
      if (j >= 1 && li[j] > k) {
	ans[i] = li[j];
	usd[j] = 1;
	while (j >= 1 && li[j] >= ans[i]) -- j;
      }
    }
  }
  for (int i = 1, j = 1; i <= n; ++ i) {
    if (ans[i] > 0) continue;
    while (usd[j]) ++ j;
    ans[i] = li[j];
    usd[j] = 1;
  }
  rep (i, 1, n)
    printf("%d ", ans[i]);
  puts("");
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	for (int i = id[tot], j, A, B, C, now = a[i] == -1 ? b[m] : a[i], pos = m, nex = tot; i; ) {
		C = lower_bound(b + 1, b + m + 1, now) - b - 1;
//		printf("%d\n", now);
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = C - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

//			printf("%d\n", b[pos]);
			a[i] = b[pos]; vis[pos--] = 1;
		}
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	for (int i = id[tot], j, A, B, C, now = a[i] == -1 ? b[m] : a[i], pos = m, nex = tot; i; ) {
		C = lower_bound(b + 1, b + m + 1, now) - b - 1;
		printf("%d\n", now);
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = C - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

			printf("%d\n", b[pos]);
			a[i] = b[pos]; vis[pos--] = 1;
		}
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = max(0, al[i] - al[j] - (b[al[j] + 1] == a[j]));
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		if (min(qzh[i] - qzh[j], al[i] - al[j]) + p[j] + 1 != nex)
		puts ("A");
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
	if (a[1] == 65696) {
		printf("%d\n", tt);
	}
	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	for (int i = id[tot], j, A, B, C, now = a[i] == -1 ? b[m] : a[i], pos = m, nex = tot; i; ) {
		if (a[i] == -1) a[i] = now; C = lower_bound(b + 1, b + m + 1, now) - b - 1;
//		printf("%d\n", now);
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = C - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

//			printf("%d\n", b[pos]);
			a[i] = b[pos]; vis[pos--] = 1;
		}
		i = j;
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	if (n == 30000)
	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

const int maxn = 110000;

int n,m;
int a[maxn],b[maxn],al[maxn];
bool v[maxn];
int w[maxn],f[maxn],s[maxn];

int cal(int x,int y)
{
	return al[y]-al[x]-(b[al[y]]==a[y]?1:0);
}
int cal2(int x,int y)
{
	return s[y]-s[x];
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]); s[i]=s[i-1];
		if(a[i]==-1) ++s[i];
	}
	scanf("%d",&m); for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	sort(b+1,b+m+1); int L=unique(b+1,b+m+1)-(b+1);

	int tp; w[tp=0]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=-1)
		{
			int l=0,r=tp;
			while(l<=r)
			{
				int mid=l+r>>1;
				if(w[mid]<a[i]) l=mid+1;
				else r=mid-1;
			}int j=l;
			w[j]=a[i]; f[i]=j;
			if(w[tp+1]) tp++;
		}
		else
		{
			int pos=tp+1;
			for(int j=L;j>=1;j--)
			{
				while(pos&&w[pos-1]>=b[j]) pos--;
				w[pos]=b[j];
			}
			f[i]=pos;
			if(w[tp+1]) tp++;
		}
	}
	int now=n+1; a[now]=inf+1; s[now]=s[n]; f[now]=tp+1;
	for(int i=1;i<=n+1;i++) if(a[i]!=-1)
	{
		int l=1,r=L;
		while(l<=r)
		{
			int mid=l+r>>1;
			if(b[mid]<=a[i]) l=mid+1;
			else r=mid-1;
		}al[i]=l-1;
	}
	int pos = m;
	while(f[now])
	{
		int nex=now-1;
		for(;a[nex]==-1||a[nex]>=a[now]||f[now]-f[nex]-1>min(cal(nex,now),cal2(nex,now));nex--);
		for(int j=now-1;j>nex;j--) if(a[j]==-1)
		{
			while(v[pos] || b[pos] >= a[now]) pos--;
			if(pos<=al[nex]) break;
			a[j]=b[pos]; v[pos--]=true;
		}
		now=nex;
	}
	int j=1;
	for(int i=1;i<=n;i++) if(a[i]==-1)
	{
		while(v[j]) j++;
		a[i]=b[j]; v[j++]=true;
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);

	return 0;
}


#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

const int maxn = 110000;

int n,m;
int a[maxn],b[maxn],al[maxn];
bool v[maxn];
int w[maxn],f[maxn],s[maxn];

int cal(int x,int y)
{
	return al[y]-al[x];
}
int cal2(int x,int y)
{
	return s[y]-s[x];
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]); s[i]=s[i-1];
		if(a[i]==-1) ++s[i];
	}
	scanf("%d",&m); for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	sort(b+1,b+m+1); int L=unique(b+1,b+m+1)-(b+1);

	int tp; w[tp=0]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=-1)
		{
			int l=0,r=tp;
			while(l<=r)
			{
				int mid=l+r>>1;
				if(w[mid]<a[i]) l=mid+1;
				else r=mid-1;
			}int j=l;
			w[j]=a[i]; f[i]=j;
			if(w[tp+1]) tp++;
		}
		else
		{
			int pos=tp+1;
			for(int j=L;j>=1;j--)
			{
				while(pos&&w[pos-1]>=b[j]) pos--;
				w[pos]=b[j];
			}
			f[i]=pos;
			if(w[tp+1]) tp++;
		}
	}
	int now=n+1; a[now]=inf+1; s[now]=s[n]; f[now]=tp+1;
	for(int i=1;i<=n+1;i++) if(a[i]!=-1)
	{
		int l=1,r=L;
		while(l<=r)
		{
			int mid=l+r>>1;
			if(b[mid]<a[i]) l=mid+1;
			else r=mid-1;
		}al[i]=l-1;
	}
	while(f[now])
	{
		int nex=now-1;
		for(;a[nex]==-1||a[nex]>=a[now]||f[now]-f[nex]-1>min(cal(nex,now),cal2(nex,now));nex--);
		int pos=al[now]; if(b[pos]==a[now]) pos--;
		for(int j=now-1;j>nex;j--) if(a[j]==-1)
		{
			while(v[pos]) pos--;
			if(pos<=al[nex]) break;
			a[j]=b[pos]; v[pos--]=true;
		}
		now=nex;
	}
	int j=1;
	for(int i=1;i<=n;i++) if(a[i]==-1)
	{
		while(v[j]) j++;
		a[i]=b[j]; v[j++]=true;
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	if (a[1] == 65696) m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
//		if (min(qzh[i] - qzh[j], al[i] - al[j]) + p[j] + 1 != nex) puts ("A");
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
	if (a[1] == 65696) {
		for (int i = 1; i <= tt; ++i) printf("%d%c", ans[i], i == tt || i % 20 == 0 ? '\n' : ' ');
	}
	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
//	m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		if (min(qzh[i] - qzh[j], al[i] - al[j]) + p[j] + 1 != nex)
		puts ("A");
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = max(0, al[i] - al[j] - (b[al[j] + 1] == a[j]));
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		if (min(qzh[i] - qzh[j], al[i] - al[j]) + p[j] + 1 != nex)
		puts ("A");
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
//	m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
//		if (min(qzh[i] - qzh[j], al[i] - al[j]) + p[j] + 1 != nex) puts ("A");
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	m = unique(b + 1, b + m + 1) - b - 1;
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
	if (a[1] == 457) printf("%d\n", tot);
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		if (min(qzh[i] - qzh[j], al[i] - al[j]) + p[j] + 1 != nex)
		puts ("A");
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
//	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], las[N], ans[N], gg[N][2];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				if (r == m) gg[i][1] = l; if (r == 1) gg[i][0] = l;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; las[i] = id[tot - 1]; gg[i][0] = gg[i][1] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; las[i] = id[l - 1]; gg[i][0] = gg[i][1] = l; c[l] = a[i];
		}
	}
//	printf("%d\n", tot);
	int r = tot, l = id[r], p = m, la = 0x3f3f3f3f, tc = n;
	while (r--) {
		if (a[l] == -1) {
			l = n + lower_bound(b + 1, b + m + 1, la) - b - 1;
		}
		ans[r + 1] = l;
		la = l > n ? b[l - n] : a[l];
		if (r == 0) continue ;
		if (l <= n) tc = min(tc, l - 1);
		if (l > n) {
			while (a[tc] >= la || !(gg[tc][0] <= r && gg[tc][1] >= r)) --tc;
			l = tc; --tc;
		} else {
			if (tc >= l) tc = l - 1;
			l = las[l]; tc = l - 1;
		}
	}
	for (int i = 1, j = 1; i <= n; ++i) {
		if (j <= tot && ((ans[j] > n && a[i] == -1) || (ans[j] <= n && ans[j] == i))) {
			if (ans[j] > n) a[i] = b[ans[j] - n], vis[ans[j] - n] = 1;
			++j;
		}
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N], tt;
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, now = INF, pos = m, nex = tot + 1; i; ) {
		if (i != n + 1) ans[++tt] = a[i];
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break;
			now = a[i] = b[pos]; vis[pos--] = 1;
			ans[++tt] = a[i];
		}
		i = j;
		now = a[j];
	}
	if (a[1] == 65696) {
		reverse(ans + 1, ans + tt + 1);
		for (int i = 1; i <= tt; ++i) printf("%d%c", ans[i], i == tt || i % 20 == 0 ? '\n' : ' ');
	}
	for (int i = 1; i < tt; ++i) if (ans[i] <= ans[i + 1]) puts("A");
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, C, now = INF, pos = m, nex = tot + 1; i; ) {
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

//			printf("%d\n", b[pos]);
			now = a[i] = b[pos]; vis[pos--] = 1;
		}
		i = j;
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	if (a[1] == 65696)
	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], las[N], ans[N], gg[N][2];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				if (r == m) gg[i][1] = l; if (r == 1) gg[i][0] = l;
				id[l] = -1; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; las[i] = id[tot - 1]; gg[i][0] = gg[i][1] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; las[i] = id[l - 1]; gg[i][0] = gg[i][1] = l; c[l] = a[i];
		}
	}
//	printf("%d\n", tot);
	int r = tot, l = id[r], p = m, la = 0x3f3f3f3f, tc = n;
	while (r--) {
		if (l == -1) {
			l = n + lower_bound(b + 1, b + m + 1, la) - b - 1;
		}
		ans[r + 1] = l;
		la = l > n ? b[l - n] : a[l];
		if (r == 0) continue ;
		if (l > n) tc = min(tc, l - n - 1);
		else tc = min(tc, l - 1);
		if (l > n) {
			while (a[tc] >= la || !(gg[tc][0] <= r && gg[tc][1] >= r)) --tc;
			l = a[tc] != -1 ? tc : -1; --tc;
		} else {
			if (tc >= l) tc = l - 1;
			l = las[l];
		}
	}
	for (int i = 1, j = 1; i <= n; ++i) {
		if (j <= tot && ((ans[j] > n && a[i] == -1) || (ans[j] <= n && ans[j] == i))) {
			if (ans[j] > n) a[i] = b[ans[j] - n], vis[ans[j] - n] = 1;
			++j;
		}
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	for (int i = id[tot], j, A, B, C, now = a[i] == -1 ? b[m] : a[i], pos = m, nex = tot; i; ) {
		if (a[i] == -1) a[i] = now; C = lower_bound(b + 1, b + m + 1, now) - b - 1;
//		printf("%d\n", now);
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = C - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

//			printf("%d\n", b[pos]);
			a[i] = b[pos]; vis[pos--] = 1;
		}
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	for (int i = id[tot], j, A, B, C, now = a[i] == -1 ? b[m] : a[i], pos = m, nex = tot; i; ) {
		if (a[i] == -1) a[i] = now; C = lower_bound(b + 1, b + m + 1, now) - b - 1;
//		printf("%d\n", now);
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = C - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

//			printf("%d\n", b[pos]);
			a[i] = b[pos]; vis[pos--] = 1;
		}
		i = j;
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5 + 9, INF = 0x3f3f3f3f;

int n, m, a[N], b[N], c[N], tot, id[N], ans[N], al[N], qzh[N], p[N];
bool vis[N];

int main () {
	scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
	sort(b + 1, b + m + 1);
	for (int i = 1, l, r, mid; i <= n; ++i) {
		if (a[i] == -1) {
			for (l = tot, r = m; r; --r) {
				while (l && b[r] <= c[l]) --l; ++l;
				if (l > tot) ++tot;
				id[l] = i; c[l] = b[r];
			}
		} else {
			if (!tot || a[i] > c[tot]) { c[++tot] = a[i]; id[tot] = i; p[i] = tot; continue ; }
			l = 1; r = tot;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (c[mid] >= a[i]) r = mid - 1;
				else l = mid + 1;
			}
			id[l] = i; c[l] = a[i]; p[i] = l;
		}
	}
//	printf("%d\n", tot);
	for (int i = 1; i <= n; ++i) {
		qzh[i] = qzh[i - 1];
		if (a[i] != -1) al[i] = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		else ++qzh[i];
	}
	p[n + 1] = tot + 1; qzh[n + 1] = qzh[n]; al[n + 1] = m;
	for (int i = n + 1, j, A, B, C, now = INF, pos = m, nex = tot + 1; i; ) {
		if (nex == 1 || nex == 0) break ;
		for (j = i - 1; j; --j) if (a[j] != -1 && a[j] < now) {
			A = qzh[i - 1] - qzh[j];
			B = al[i] - al[j];
			if (min(A, B) + p[j] + 1 == nex) break ;
		}
		nex = p[j];
		for (--i; i != j; --i) if (a[i] == -1) {
			while (vis[pos] || b[pos] >= now) --pos;
			if (b[pos] <= a[j]) break ;

//			printf("%d\n", b[pos]);
			now = a[i] = b[pos]; vis[pos--] = 1;
		}
		i = j;
		now = a[j];
	}
	for (int i = 1, j = 1; i <= n; ++i) if (a[i] == -1) {
		while (vis[j]) ++j; a[i] = b[j++];
	}
	for (int i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? '\n' : ' ');
//	for (int i = 1; i <= tot; ++i) printf("%d%c", ans[i], i == tot ? '\n' : ' ');
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <utility>

#ifdef Tweetuzki
#define debug(arg...) fprintf(stderr, arg)
#else
#define debug(arg...) void(0)
#endif

const int MaxN = 100000, MaxM = 100000;
const int MaxV = MaxN + MaxM;

int N, M, V;
int A[MaxN + 5], B[MaxM + 5];
int D[MaxV + 5];
int F[MaxN + 5], G[MaxN + 5], L[MaxN + 5], P[MaxN + 5];
int PreGap[MaxN + 5], Cnt[MaxV + 5];
std::set< std::pair<int, int> > S[MaxN + 5];
int Ans[MaxN + 5];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i] != -1) D[++V] = A[i];
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &B[i]);
    D[++V] = B[i];
  }
  std::sort(D + 1, D + 1 + V);
  V = std::unique(D + 1, D + 1 + V) - D - 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) A[i] = std::lower_bound(D + 1, D + 1 + V, A[i]) - D;
  for (int i = 1; i <= M; ++i)
    B[i] = std::lower_bound(D + 1, D + 1 + V, B[i]) - D;
  std::sort(B + 1, B + 1 + M);
  for (int i = 1; i <= M; ++i) Cnt[B[i]]++;
  for (int i = 1, pregap = 0; i <= N; ++i) {
    if (A[i] == -1) {
      PreGap[i] = pregap;
      pregap = i;
    }
  }
  for (int i = 1; i <= N; ++i)
    debug("preGap[%d] = %d\n", i, PreGap[i]);
  debug("V = %d\n", V);
  debug("a: ");
  for (int i = 1; i <= N; ++i) debug("%d%c", A[i], " \n"[i == N]);
  debug("b: ");
  for (int i = 1; i <= M; ++i) debug("%d%c", B[i], " \n"[i == M]);
}

void solve() {
  int mxl = 0;
  for (int i = 1; i <= N; ++i) {
    if (A[i] != -1) {
      int lbound = 0, rbound = mxl, ans = 0;
      while (lbound <= rbound) {
        int mid = (lbound + rbound) >> 1;
        if (F[mid] < A[i]) {
          ans = mid;
          lbound = mid + 1;
        } else rbound = mid - 1;
      }
      L[i] = ans + 1;
      mxl = std::max(mxl, L[i]);
      P[i] = G[ans];
      F[L[i]] = A[i];
      G[L[i]] = i;
    } else {
      int lk = mxl;
      for (int j = M; j >= 1; --j) {
        while (F[lk] >= B[j]) lk--;
        mxl = std::max(mxl, lk + 1);
        F[lk + 1] = B[j];
        G[lk + 1] = i;
      }
    }
  }
  for (int i = 1; i <= N; ++i)
    debug("i = %d, l = %d, p = %d, f = %d, g = %d\n", i, L[i], P[i], F[i], G[i]);
  debug("ans = %d\n", mxl);
  static int stk[MaxN + 5], tp = 0;
  memcpy(Ans, A, sizeof A);
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) S[L[i]].insert(std::make_pair(A[i], i));
  for (int pos = G[mxl], lk = N; pos != 0;) {
    if (tp == mxl) break;
    debug("pos = %d, tp = %d\n", pos, tp);
    if (A[pos] != -1) {
      stk[++tp] = A[pos];
      pos = P[pos];
    } else {
      int value = tp == 0 ? B[M] : *(std::lower_bound(B + 1, B + 1 + M, stk[tp]) - 1);
      stk[++tp] = value;
      Ans[pos] = value;
      Cnt[value]--;
      while (lk >= pos) {
        S[L[lk]].erase(std::make_pair(A[lk], lk));
        lk--;
      }
      if (S[mxl - tp].empty() || S[mxl - tp].begin()->first >= stk[tp]) pos = PreGap[pos];
      else pos = S[mxl - tp].begin()->second;
    }
  }
  for (int i = 1, j = 1; i <= N; ++i) {
    if (Ans[i] == -1) {
      while (Cnt[j] == 0) j++;
      Ans[i] = j;
      Cnt[j]--;
    }
  }
  for (int i = 1; i <= N; ++i) printf("%d%c", D[Ans[i]], " \n"[i == N]);
}

int main() {
#ifdef Tweetuzki
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("errorfile.txt", "w", stderr);
#endif
  init();
  solve();
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <utility>

#ifdef Tweetuzki
#define debug(arg...) fprintf(stderr, arg)
#else
#define debug(arg...) void(0)
#endif

const int MaxN = 100000, MaxM = 100000;
const int MaxV = MaxN + MaxM;

int N, M, V;
int A[MaxN + 5], B[MaxM + 5];
int D[MaxV + 5];
int F[MaxN + 5], G[MaxN + 5], L[MaxN + 5], P[MaxN + 5];
int PreGap[MaxN + 5], Cnt[MaxV + 5];
std::set< std::pair<int, int> > S[MaxN + 5];
int Ans[MaxN + 5];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i] != -1) D[++V] = A[i];
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &B[i]);
    D[++V] = B[i];
  }
  std::sort(D + 1, D + 1 + V);
  V = std::unique(D + 1, D + 1 + V) - D - 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) A[i] = std::lower_bound(D + 1, D + 1 + V, A[i]) - D;
  for (int i = 1; i <= M; ++i)
    B[i] = std::lower_bound(D + 1, D + 1 + V, B[i]) - D;
  std::sort(B + 1, B + 1 + M);
  for (int i = 1; i <= M; ++i) Cnt[B[i]]++;
  for (int i = 1, pregap = 0; i <= N; ++i) {
    if (A[i] == -1) {
      PreGap[i] = pregap;
      pregap = i;
    }
  }
  for (int i = 1; i <= N; ++i)
    debug("preGap[%d] = %d\n", i, PreGap[i]);
  debug("V = %d\n", V);
  debug("a: ");
  for (int i = 1; i <= N; ++i) debug("%d%c", A[i], " \n"[i == N]);
  debug("b: ");
  for (int i = 1; i <= M; ++i) debug("%d%c", B[i], " \n"[i == M]);
}

void solve() {
  int mxl = 0;
  for (int i = 1; i <= N; ++i) {
    if (A[i] != -1) {
      int lbound = 0, rbound = mxl, ans = 0;
      while (lbound <= rbound) {
        int mid = (lbound + rbound) >> 1;
        if (F[mid] < A[i]) {
          ans = mid;
          lbound = mid + 1;
        } else rbound = mid - 1;
      }
      L[i] = ans + 1;
      mxl = std::max(mxl, L[i]);
      P[i] = G[ans];
      F[L[i]] = A[i];
      G[L[i]] = i;
    } else {
      int lk = mxl;
      for (int j = M; j >= 1; --j) {
        while (F[lk] >= B[j]) lk--;
        mxl = std::max(mxl, lk + 1);
        F[lk + 1] = B[j];
        G[lk + 1] = i;
      }
    }
  }
  debug("ans = %d\n", mxl);
  static int stk[MaxN + 5], tp = 0;
  memcpy(Ans, A, sizeof A);
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) S[L[i]].insert(std::make_pair(A[i], i));
  for (int pos = G[mxl], lk = N; pos != 0;) {
    if (tp == mxl) break;
    debug("pos = %d\n", pos);
    if (A[pos] != -1) {
      stk[++tp] = A[pos];
      pos = P[pos];
    } else {
      int value = tp == 0 ? B[M] : *(std::lower_bound(B + 1, B + 1 + M, stk[tp]) - 1);
      stk[++tp] = value;
      Ans[pos] = value;
      Cnt[value]--;
      while (lk >= pos) {
        S[L[lk]].erase(std::make_pair(A[lk], lk));
        lk--;
      }
      if (S[mxl - tp].empty() || S[mxl - tp].begin()->second >= stk[tp]) pos = PreGap[pos];
      else pos = S[mxl - tp].begin()->second;
    }
  }
  for (int i = 1, j = 1; i <= N; ++i) {
    if (Ans[i] == -1) {
      while (Cnt[j] == 0) j++;
      Ans[i] = j;
      Cnt[j]--;
    }
  }
  for (int i = 1; i <= N; ++i) printf("%d%c", Ans[i], " \n"[i == N]);
}

int main() {
#ifdef Tweetuzki
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("errorfile.txt", "w", stderr);
#endif
  init();
  solve();
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <utility>

#ifdef Tweetuzki
#define debug(arg...) fprintf(stderr, arg)
#else
#define debug(arg...) void(0)
#endif

const int MaxN = 100000, MaxM = 100000;
const int MaxV = MaxN + MaxM;

int N, M, V;
int A[MaxN + 5], B[MaxM + 5];
int D[MaxV + 5];
int F[MaxN + 5], G[MaxN + 5], L[MaxN + 5], P[MaxN + 5];
int PreGap[MaxN + 5], Cnt[MaxV + 5];
std::set< std::pair<int, int> > S[MaxN + 5];
int Ans[MaxN + 5];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i] != -1) D[++V] = A[i];
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &B[i]);
    D[++V] = B[i];
  }
  std::sort(D + 1, D + 1 + V);
  V = std::unique(D + 1, D + 1 + V) - D - 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) A[i] = std::lower_bound(D + 1, D + 1 + V, A[i]) - D;
  for (int i = 1; i <= M; ++i)
    B[i] = std::lower_bound(D + 1, D + 1 + V, B[i]) - D;
  std::sort(B + 1, B + 1 + M);
  for (int i = 1; i <= M; ++i) Cnt[B[i]]++;
  for (int i = 1, pregap = 0; i <= N; ++i) {
    if (A[i] == -1) {
      PreGap[i] = pregap;
      pregap = i;
    }
  }
  debug("V = %d\n", V);
  debug("a: ");
  for (int i = 1; i <= N; ++i) debug("%d%c", A[i], " \n"[i == N]);
  debug("b: ");
  for (int i = 1; i <= M; ++i) debug("%d%c", B[i], " \n"[i == M]);
}

void solve() {
  int mxl = 0;
  for (int i = 1; i <= N; ++i) {
    if (A[i] != -1) {
      int lbound = 0, rbound = mxl, ans = 0;
      while (lbound <= rbound) {
        int mid = (lbound + rbound) >> 1;
        if (F[mid] < A[i]) {
          ans = mid;
          lbound = mid + 1;
        } else rbound = mid - 1;
      }
      L[i] = ans + 1;
      mxl = std::max(mxl, L[i]);
      P[i] = G[ans];
      F[L[i]] = A[i];
      G[L[i]] = i;
    } else {
      int lk = mxl;
      for (int j = M; j >= 1; --j) {
        while (F[lk] >= B[j]) lk--;
        mxl = std::max(mxl, lk + 1);
        F[lk + 1] = B[j];
        G[lk + 1] = j;
      }
    }
  }
  static int stk[MaxN + 5], tp = 0;
  memcpy(Ans, A, sizeof A);
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) S[L[i]].insert(std::make_pair(A[i], i));
  for (int pos = G[mxl], lk = N; pos != 0;) {
    if (A[pos] != -1) {
      stk[++tp] = A[pos];
      pos = P[pos];
    } else {
      int value = *(std::lower_bound(B + 1, B + 1 + M, stk[tp]) - 1);
      stk[++tp] = value;
      Ans[pos] = value;
      Cnt[value]--;
      while (lk >= pos) {
        S[L[lk]].erase(std::make_pair(A[lk], lk));
        lk--;
      }
      if (S[mxl - tp].empty() || S[mxl - tp].begin()->second >= stk[tp]) pos = PreGap[pos];
      else pos = S[mxl - tp].begin()->second;
    }
  }
  for (int i = 1, j = 1; i <= N; ++i) {
    if (Ans[i] == -1) {
      while (Cnt[j] == 0) j++;
      Ans[i] = j;
      Cnt[j]--;
    }
  }
  for (int i = 1; i <= N; ++i) printf("%d%c", Ans[i], " \n"[i == N]);
}

int main() {
#ifdef Tweetuzki
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("errorfile.txt", "w", stderr);
#endif
  init();
  solve();
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <utility>

#ifdef Tweetuzki
#define debug(arg...) fprintf(stderr, arg)
#else
#define debug(arg...) void(0)
#endif

const int MaxN = 100000, MaxM = 100000;
const int MaxV = MaxN + MaxM;

int N, M, V;
int A[MaxN + 5], B[MaxM + 5];
int D[MaxV + 5];
int F[MaxN + 5], G[MaxN + 5], L[MaxN + 5], P[MaxN + 5];
int PreGap[MaxN + 5], Cnt[MaxV + 5];
std::set< std::pair<int, int> > S[MaxN + 5];
int Ans[MaxN + 5];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i] != -1) D[++V] = A[i];
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &B[i]);
    D[++V] = B[i];
  }
  std::sort(D + 1, D + 1 + V);
  V = std::unique(D + 1, D + 1 + V) - D - 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) A[i] = std::lower_bound(D + 1, D + 1 + V, A[i]) - D;
  for (int i = 1; i <= M; ++i)
    B[i] = std::lower_bound(D + 1, D + 1 + V, B[i]) - D;
  std::sort(B + 1, B + 1 + M);
  for (int i = 1; i <= M; ++i) Cnt[B[i]]++;
  for (int i = 1, pregap = 0; i <= N; ++i) {
    if (A[i] == -1) {
      PreGap[i] = pregap;
      pregap = i;
    }
  }
  for (int i = 1; i <= N; ++i)
    debug("preGap[%d] = %d\n", i, PreGap[i]);
  debug("V = %d\n", V);
  debug("a: ");
  for (int i = 1; i <= N; ++i) debug("%d%c", A[i], " \n"[i == N]);
  debug("b: ");
  for (int i = 1; i <= M; ++i) debug("%d%c", B[i], " \n"[i == M]);
}

void solve() {
  int mxl = 0;
  for (int i = 1; i <= N; ++i) {
    if (A[i] != -1) {
      int lbound = 0, rbound = mxl, ans = 0;
      while (lbound <= rbound) {
        int mid = (lbound + rbound) >> 1;
        if (F[mid] < A[i]) {
          ans = mid;
          lbound = mid + 1;
        } else rbound = mid - 1;
      }
      L[i] = ans + 1;
      mxl = std::max(mxl, L[i]);
      P[i] = G[ans];
      F[L[i]] = A[i];
      G[L[i]] = i;
    } else {
      int lk = mxl;
      for (int j = M; j >= 1; --j) {
        while (F[lk] >= B[j]) lk--;
        mxl = std::max(mxl, lk + 1);
        F[lk + 1] = B[j];
        G[lk + 1] = i;
      }
    }
  }
  debug("ans = %d\n", mxl);
  static int stk[MaxN + 5], tp = 0;
  memcpy(Ans, A, sizeof A);
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) S[L[i]].insert(std::make_pair(A[i], i));
  for (int pos = G[mxl], lk = N; pos != 0;) {
    if (tp == mxl) break;
    debug("pos = %d\n", pos);
    if (A[pos] != -1) {
      stk[++tp] = A[pos];
      pos = P[pos];
    } else {
      int value = (tp == 0 ? B[M] : *(std::lower_bound(B + 1, B + 1 + M, stk[tp]) - 1));
      stk[++tp] = value;
      Ans[pos] = value;
      Cnt[value]--;
      while (lk >= pos) {
        S[L[lk]].erase(std::make_pair(A[lk], lk));
        lk--;
      }
      if (S[mxl - tp].empty() || S[mxl - tp].begin()->second >= stk[tp]) pos = PreGap[pos];
      else pos = S[mxl - tp].begin()->second;
    }
  }
  for (int i = 1, j = 1; i <= N; ++i) {
    if (Ans[i] == -1) {
      while (Cnt[j] == 0) j++;
      Ans[i] = j;
      Cnt[j]--;
    }
  }
  for (int i = 1; i <= N; ++i) printf("%d%c", Ans[i], " \n"[i == N]);
}

int main() {
#ifdef Tweetuzki
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("errorfile.txt", "w", stderr);
#endif
  init();
  solve();
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <utility>

#ifdef Tweetuzki
#define debug(arg...) fprintf(stderr, arg)
#else
#define debug(arg...) void(0)
#endif

const int MaxN = 100000, MaxM = 100000;
const int MaxV = MaxN + MaxM;

int N, M, V;
int A[MaxN + 5], B[MaxM + 5];
int D[MaxV + 5];
int F[MaxN + 5], G[MaxN + 5], L[MaxN + 5], P[MaxN + 5];
int PreGap[MaxN + 5], Cnt[MaxV + 5];
std::set< std::pair<int, int> > S[MaxN + 5];
int Ans[MaxN + 5];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i] != -1) D[++V] = A[i];
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &B[i]);
    D[++V] = B[i];
  }
  std::sort(D + 1, D + 1 + V);
  V = std::unique(D + 1, D + 1 + V) - D - 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) A[i] = std::lower_bound(D + 1, D + 1 + V, A[i]) - D;
  for (int i = 1; i <= M; ++i)
    B[i] = std::lower_bound(D + 1, D + 1 + V, B[i]) - D;
  std::sort(B + 1, B + 1 + M);
  for (int i = 1; i <= M; ++i) Cnt[B[i]]++;
  for (int i = 1, pregap = 0; i <= N; ++i) {
    if (A[i] == -1) {
      PreGap[i] = pregap;
      pregap = i;
    }
  }
  for (int i = 1; i <= N; ++i)
    debug("preGap[%d] = %d\n", i, PreGap[i]);
  debug("V = %d\n", V);
  debug("a: ");
  for (int i = 1; i <= N; ++i) debug("%d%c", A[i], " \n"[i == N]);
  debug("b: ");
  for (int i = 1; i <= M; ++i) debug("%d%c", B[i], " \n"[i == M]);
}

void solve() {
  int mxl = 0;
  for (int i = 1; i <= N; ++i) {
    if (A[i] != -1) {
      int lbound = 0, rbound = mxl, ans = 0;
      while (lbound <= rbound) {
        int mid = (lbound + rbound) >> 1;
        if (F[mid] < A[i]) {
          ans = mid;
          lbound = mid + 1;
        } else rbound = mid - 1;
      }
      L[i] = ans + 1;
      mxl = std::max(mxl, L[i]);
      P[i] = G[ans];
      F[L[i]] = A[i];
      G[L[i]] = i;
    } else {
      int lk = mxl;
      for (int j = M; j >= 1; --j) {
        while (F[lk] >= B[j]) lk--;
        mxl = std::max(mxl, lk + 1);
        F[lk + 1] = B[j];
        G[lk + 1] = i;
      }
    }
  }
  debug("ans = %d\n", mxl);
  static int stk[MaxN + 5], tp = 0;
  memcpy(Ans, A, sizeof A);
  for (int i = 1; i <= N; ++i)
    if (A[i] != -1) S[L[i]].insert(std::make_pair(A[i], i));
  for (int pos = G[mxl], lk = N; pos != 0;) {
    if (tp == mxl) break;
    debug("pos = %d\n", pos);
    if (A[pos] != -1) {
      stk[++tp] = A[pos];
      pos = P[pos];
    } else {
      int value = tp == 0 ? B[M] : *(std::lower_bound(B + 1, B + 1 + M, stk[tp]) - 1);
      stk[++tp] = value;
      Ans[pos] = value;
      Cnt[value]--;
      while (lk >= pos) {
        S[L[lk]].erase(std::make_pair(A[lk], lk));
        lk--;
      }
      if (S[mxl - tp].empty() || S[mxl - tp].begin()->second >= stk[tp]) pos = PreGap[pos];
      else pos = S[mxl - tp].begin()->second;
    }
  }
  for (int i = 1, j = 1; i <= N; ++i) {
    if (Ans[i] == -1) {
      while (Cnt[j] == 0) j++;
      Ans[i] = j;
      Cnt[j]--;
    }
  }
  for (int i = 1; i <= N; ++i) printf("%d%c", D[Ans[i]], " \n"[i == N]);
}

int main() {
#ifdef Tweetuzki
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("errorfile.txt", "w", stderr);
#endif
  init();
  solve();
  return 0;
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define last last2
#define FR first
#define SE second

using namespace std;

typedef pair<int,int> pr;

int a[100005],b[100005];

pr f[100005],g[100005],q[100005];
int pre[100005];

void dp(int n,int m) {
  memset(f,0x3f,sizeof(f));
  f[0]=pr(0,0);
  int cnt=0,last=0;
  for(int i=1;i<=n+1;i++) {
  	pre[i]=last;
    if (a[i]!=-1) {
    	if (a[i]>f[cnt].FR) {
    		f[++cnt]=pr(a[i],i);
    		g[i]=pr(cnt,f[cnt-1].SE);
		}
    	else {
    		int t=lower_bound(f+1,f+cnt+1,pr(a[i],0))-f;
    		g[i]=pr(t,f[t-1].SE);
    		f[t]=pr(a[i],i);
		}
	}
    else {
    	int r=1,sz=0;
    	for(int j=1;j<=cnt+1;j++) {
    		while (r<=m&&b[r]<=f[j-1].FR) r++;
    		if (r>m) break;
    		if (b[r]<f[j].FR) q[++sz]=pr(j,b[r]);
		}
		for(int j=1;j<=sz;j++) f[q[j].FR]=pr(q[j].SE,i);
	    if (f[cnt+1].FR<inf) cnt++;
	    last=i;
	}
  }
}

int ans[100005],d[100005];
int c[100005];
bool vis[100005];

void output(int n,int m) {
  int sz=0;
  for(int i=1;i<=m;i++)
    if (i==1||b[i]!=b[i-1]) c[++sz]=b[i];
  int sz2=sz;
  for(int i=2;i<=m;i++)
    if (b[i]==b[i-1]) c[++sz2]=b[i];
  for(int i=0;i<=n;i++)
    if (a[i]!=-1) d[i]=upper_bound(c+1,c+sz+1,a[i])-c;
  int x=n+1;
  while (x)
    if (a[g[x].SE]!=-1) x=g[x].SE;
    else {
		int s=0,t=lower_bound(c+1,c+sz+1,a[x])-c-1;
    	for(int i=x-1;i>=0;i--)
    	  if (a[i]!=-1) {
    	  	if (a[i]<a[x]&&g[i].FR+min(s,t-d[i]+1)+1==g[x].FR) {
    	  		int v=min(s,t-d[i]+1);
    	  		x=pre[x];
    	  		for(int j=1;j<=v;j++) {
    	  			ans[x]=c[t-j+1];
    	  			vis[t-j+1]=1;
    	  			x=pre[x];
				  }
    	  		x=i;
    	  		break;
			  }
		  }
    	  else s++;
	}
  int r=1;
  for(int i=1;i<=n;i++)
    if (a[i]!=-1) ans[i]=a[i];
    else if (!ans[i]) {
    	while (r<=m&&vis[r]) r++;
    	vis[r]=1;
    	ans[i]=c[r];
	}
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  a[n+1]=1e9+1;
  int m;
  scanf("%d",&m);
  for(int i=1;i<=m;i++) scanf("%d",&b[i]);
  sort(b+1,b+m+1);
  dp(n,m);
  output(n,m);
  for(int i=1;i<=n;i++) printf("%d ",ans[i]);
  printf("\n");
  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]=b[now];
            book[now]--;
        }
        else a[i]=c[a[i]];
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[i]);
    puts("");
    return 0;
}