Prefix and Suffix Mex
Обмеження: 2 сек., 512 МіБ
For a sequence XX composed of a finite number of non-negative integers, we define mex(X)mex(X) as the smallest non-negative integer not in XX. For example, mex(0,0,1,3)=2,mex(1)=0,mex()=0mex(0,0,1,3)=2,mex(1)=0,mex()=0.
You are given two sequences bb and cc of nn non-negative integers.
Construct a sequence aa of nn non-negative integers that satisfies all of the following conditions.
mex(a1,a2,…,ai)=bimex(a1,a2,…,ai)=bi for all 1≤i≤n1≤i≤n.
mex(ai,ai+1,…,an)=cimex(ai,ai+1,…,an)=ci for all 1≤i≤n1≤i≤n.
It is guaranteed that for a given input such a sequence exists.
Вхідні дані
The first line contains an integer nn.
The second line contains nn integers bibi.
The third line contains nn integers cici.
Вихідні дані
Print nn integers aiai – the elements of sequence aa. The values aiai must not be greater than 109109. One can prove that there exists a sequence satisfying this constraint.
If there are multiple answers, any of them will be accepted.
Обмеження
1≤n≤1051≤n≤105,
0≤bi,ci≤n0≤bi,ci≤n,
it is guaranteed that there exists a sequence aa satisfying the conditions.
Приклади
Вхідні дані (stdin) | Вихідні дані (stdout) |
---|---|
4 1 1 1 3 3 3 2 0 | 0 2 0 1 |
Вхідні дані (stdin) | Вихідні дані (stdout) |
---|---|
7 0 0 3 4 4 4 4 4 4 4 4 3 2 0 | 1 2 0 3 2 0 1 |
Вхідні дані (stdin) | Вихідні дані (stdout) |
---|---|
4 0 0 0 0 0 0 0 0 | 4 7 74 474747474 |
Примітки
In the first example, we have b=(1,1,1,3),c=(3,3,2,0)b=(1,1,1,3),c=(3,3,2,0). Let us show that the sequence a=(0,2,0,1)a=(0,2,0,1) is a possible answer.
mex(a1)=mex(0)=1=b1mex(a1)=mex(0)=1=b1.
mex(a1,a2)=mex(0,2)=1=b2mex(a1,a2)=mex(0,2)=1=b2.
mex(a1,a2,a3)=mex(0,2,0)=1=b3mex(a1,a2,a3)=mex(0,2,0)=1=b3.
mex(a1,a2,a3,a4)=mex(0,2,0,1)=3=b4mex(a1,a2,a3,a4)=mex(0,2,0,1)=3=b4.
mex(a1,a2,a3,a4)=mex(0,2,0,1)=3=c1mex(a1,a2,a3,a4)=mex(0,2,0,1)=3=c1.
mex(a2,a3,a4)=mex(2,0,1)=3=c2mex(a2,a3,a4)=mex(2,0,1)=3=c2.
mex(a3,a4)=mex(0,1)=2=c3mex(a3,a4)=mex(0,1)=2=c3.
mex(a4)=mex(1)=0=c4mex(a4)=mex(1)=0=c4.
Thus, since all the conditions are met, a=(0,2,0,1)a=(0,2,0,1) is an answer to the problem.