#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; (i) < (n); ++(i))
#define REP3(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define REP_R(i,n) for (int i = (int)(n) - 1; (i) >= 0; --(i))
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }

template <class UnaryPredicate>
ll binsearch(ll l, ll r, UnaryPredicate pred) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        (pred(m) ? r : l) = m;
    }
    return r;
}


int count_max_tricks(vector<int> const & a, vector<int> const & b, int removed = -1) {
    assert (a.size() == b.size() - (removed != -1));
    int j = 0;
    int tricks = 0;
    for (int a_i : a) {
        while (j < b.size() and a_i >= b[j]) ++ j;
        if (j == b.size()) break;
        if (b[j] == removed) {
            removed = -1;
            ++ j;
        }
        if (j == b.size()) break;
        ++ j;
        ++ tricks;
        if (j == b.size()) break;
    }
    return tricks;
}

vector<int> solve(int n, vector<int> const & original_a, vector<int> b) {
    vector<int> a = original_a;
    sort(ALL(a));
    sort(ALL(b));
    int max_tricks = count_max_tricks(a, b);

    vector<int> c;
    int tricks = 0;
    REP (i, n) {
        int a_i = original_a[i];
        a.erase(lower_bound(ALL(a), a_i));
        auto pred = [&](int b_i) {
            int k = b.end() - (lower_bound(ALL(b), b_i) + 1);
            if (tricks + (a_i < b_i) + k >= max_tricks) return true;
            bool result = (tricks + (a_i < b_i) + count_max_tricks(a, b, b_i) == max_tricks);
            return result;
        };
        auto use = [&](int b_i) {
            b.erase(lower_bound(ALL(b), b_i));
            c.push_back(b_i);
            tricks += (a_i < b_i);
        };

        vector<int> que = b;
        que.erase(unique(ALL(que)), que.end());
        // check whether need to win
        if (a_i < que.back()) {
            auto it = upper_bound(ALL(que), a_i);
            if (it != que.begin() and not pred(*prev(it))) {
                que.erase(que.begin(), it);
            }
        }
        reverse(ALL(que));
        int j = binsearch(0, que.size(), [&](int j) {
            return pred(que[j]);
        });
        use(que[j]);

        assert (a.size() == b.size());
    }
    return c;
}

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    REP (i, n) cin >> a[i];
    REP (i, n) cin >> b[i];
    auto c = solve(n, a, b);
    REP (i, n) cout << c[i] << (i == n - 1 ? '\n' : ' ');
    return 0;
}

