This page is still under construction.

Parts of this page are still being built. What you see may change.

Sixth Sense

Time limit5sMemory limit512 MB

Summary
Given the opponent's fixed play order and Future's multiset of cards, decide the order she plays them to win the most tricks, breaking ties with the lexicographically greatest sequence.
Level

Medium7 of 10

Topics
Greedy, Sorting, Array, Implementation
Solved
No attempts yet

Problem

Ms. Future has precognition. She can foresee every player's actions exactly, except her own, so she is naturally excellent at some card games. Today she accepted a challenge from a reckless gambler, Mr. Past. They agreed to play a simple two-player trick-taking card game.

Each card in the game has a number printed on one side, leaving the other side blank, so cards are indistinguishable from one another.

A game starts with the same number of cards, say n, dealt to both players, without revealing the printed number to the opponent.

A game consists of n tricks. In each trick, both players pull one card out of their hand. The player pulling out the card with the larger number takes the trick. Because Ms. Future is extremely good at this game, they have agreed to give tricks to Mr. Past when both pull out cards with the same number. Once a card is used, it can never be used later in the same game. The game continues until all the cards in the hands are used up. The objective of the game is to take as many tricks as possible.

Your mission in this problem is to help Ms. Future by providing a computer program that determines the best order in which to play the cards in her hand. Since she has the sixth sense, your program can use information that is not available to ordinary people before the game.

Input

The input consists of a single test case in the following format.

n
p1 · · · pn
f1 · · · fn

n in the first line is the number of tricks, an integer between 2 and 5000, inclusive. The second line gives the order in which Mr. Past plays the cards in his hand. In the i-th trick, he pulls out a card with the number pi (1 ≤ i ≤ n). The third line gives Ms. Future's hand. fi (1 ≤ i ≤ n) is the number she sees on the i-th card she receives from the dealer. Every number in the second and third lines is an integer between 1 and 10 000, inclusive. These lines may contain duplicate numbers.

Output

The output should be a single line containing n integers a1 · · · an separated by a space, where ai (1 ≤ i ≤ n) is the number on the card she should play at the i-th trick to maximize the number of tricks she takes. If two or more such sequences of numbers exist, output the lexicographically greatest one among them.

Examples4

  1. Example 1

    Input
    5
    1 2 3 4 5
    1 2 3 4 5
    
    Expected output
    2 3 4 5 1
    
  2. Example 2

    Input
    5
    3 4 5 6 7
    1 3 5 7 9
    
    Expected output
    9 5 7 3 1
    
  3. Example 3

    Input
    5
    3 2 2 1 1
    1 1 2 2 3
    
    Expected output
    1 3 1 2 2
    
  4. Example 4

    Input
    5
    3 4 10 4 9
    2 7 3 6 9
    
    Expected output
    9 7 3 6 2