Stevie !

2.5

32 votes
Easy, Maps
Problem

Stevie G is one of the greatest ever players to have played football, and he's going to be the one who recites all problems to you today . Let's have a look at him :

                                                                             enter image description here

Now, he is a true admirer of mathematical geniuses like you. So he has a series of programming problems, among which the first one is :

You have been given 2 integer arrays A and B each of size N. Now we call a pair of indices (i,j) connected, if i=j or A[i]=A[j] .

Now, for each index i in the array A where 1iN, you need to find the maximum B[j] such that indices i and j are connected. Can you do it ?

Input Format :

The first line contains a single integer N.

The next line contains N space separated integers, where the ith integer denotes A[i]. The next line too contains N space separated integers, where the ith integer on this line denotes B[i].

Output Format :

Print N space separated integers according to those mentioned in the problem statement.

Constraints :

1N200,000

1A[i],B[i]109

Sample Input
5
1 2 3 2 1
6 7 8 7 6
Sample Output
6 7 8 7 6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Indices 1 and 5 are connected. Therefore the answer for indices 1 and 5 will be whichever has a larger value of B[].

Similarly, indices 2 and 4 are connected.

Index 3 is not connected to any other index.

Editor Image

?