Pongos P52016


Statement
 

pdf   zip

Each Christmas holidays, nn friends meet to celebrate a tradition. There are nn useless presents, which are called pongos. The pongos are wrapped up with newspaper, so at the beginning of the game the only available information for each pongo ii is aia_i: how cool ii seems while it is wrapped up. Let rir_i be the real coolness of ii. This real coolness is only known when the pongo is unwrapped. The higher the value of aia_i, the cooler the pongo looks when wrapped. The higher rir_i, the cooler it is when unwrapped.

The game goes as follows. The participants are numbered from 0 to n1n-1. At the beginning of the jj-th round (from 0 to n1n-1), each of the first jj participants has an unwrapped pongo at his hands, which is seen by everybody. The round starts with the participant number jj. He always takes the pongo that looks or is coolest according to the available information: if the pongo is still unchosen and therefore wrapped up, he uses aia_i, and if the pongo is already on some participant’s hands, he uses rir_i.

If a participant takes a wrapped pongo, he unwraps it and the game goes to the next round. If he takes a pongo from another participant, the participant that just lost his pongo takes the pongo that is or looks coolest among those that have not been chosen in the current round. The round continues like this until someone takes a wrapped pongo and unwraps it.

This game is deterministic. Can you tell the real coolness of the pongo that every person has at the end of the game?

Input

Input consists of several cases. Every case starts with nn, followed by the nn integers aia_i, followed by the nn integers rir_i. You can assume 1n1041 \le n \le 10^4. All the values for aia_i and rir_i are distinct integers between 00 and 2n12n-1.

Output

For every case, print the nn integers rjr_j, where rjr_j is the real coolness of the pongo at the hands of the jj-th person at the end of the game.

Public test cases
  • Input

    3
    1 0 2
    5 4 3
    6
    3 9 7 1 2 11
    10 4 6 5 8 0
    5
    0 1 2 3 4
    9 8 7 6 5
    

    Output

    3 4 5
    0 4 6 5 8 10
    7 5 9 6 8
    
  • Information
    Author
    Cesc Folch Aldehuelo
    Language
    English
    Official solutions
    C++
    User solutions
    C++