Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets.

But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays A and B, each consists of m integers. For all i, j such that 1 ≤ i, j ≤ m the condition A_{i} ≥ B_{j} holds. Help Leha rearrange the numbers in the array A so that the sum $\sum_{i = 1}^{m} F(A_{i}^{\prime}, B_{i})$ is maximally possible, where A' is already rearranged array.


-----Input-----

First line of input data contains single integer m (1 ≤ m ≤ 2·10^5) — length of arrays A and B.

Next line contains m integers a_1, a_2, ..., a_{m} (1 ≤ a_{i} ≤ 10^9) — array A.

Next line contains m integers b_1, b_2, ..., b_{m} (1 ≤ b_{i} ≤ 10^9) — array B.


-----Output-----

Output m integers a'_1, a'_2, ..., a'_{m} — array A' which is permutation of the array A.


-----Examples-----
Input
5
7 3 5 3 4
2 1 3 2 3

Output
4 7 3 5 3

Input
7
4 6 5 8 8 2 6
2 1 2 2 1 1 2

Output
2 6 4 5 8 8 6

Source: codeforces | Difficulty: EASY
Tags: Sorting

Combinatorics

Greedy algorithms

Number theory

Mathematics


Solutions:
def main():
	n = int(input())
	aa = sorted(map(int, input().split()), reverse=True)
	bb = list(map(int, input().split()))
	ij = sorted(list(range(n)), key=bb.__getitem__)
	for (i, j) in enumerate(ij):
		bb[j] = aa[i]
	print(' '.join(map(str, bb)))

def __starting_point():
	main()
__starting_point()


import sys, math, string, bisect
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l = L()
m = L()
x = []
for i in range(n):
	x.append([-m[i], i])
x.sort(key=lambda x: x[0])
x = x[-1::-1]
l.sort(reverse=True)
d = [0] * n
for i in range(n):
	d[x[i][1]] = l[i]
print(*d)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bpairs = []
for i in range(n):
	bpairs.append([b[i], i])
bpairs.sort()
a1 = sorted(a)
a1.reverse()
ans = [None] * n
for i in range(n):
	ans[bpairs[i][1]] = a1[i]
print(*ans)


import sys
read = lambda : sys.stdin.readline()
n = int(read())
a = list(map(int, read().split()))
b = list(map(int, read().split()))
a.sort()
a = a[::-1]
z = zip(a, list(sorted(b)))
d = dict()
for (one, two) in z:
	if two in d:
		d[two].append(one)
	else:
		d[two] = [one]
for i in b:
	print(d[i].pop(), end=' ')
print()


a = int(input())
b = sorted(map(int, input().split()), reverse=True)
c = sorted(zip(map(int, input().split()), range(a)))
ans = [0] * a
for i in range(a):
	ans[c[i][1]] = b[i]
print(*ans)


m = int(input())
la = sorted(list(map(int, input().split())), reverse=True)
lb = list(map(int, input().split()))
answer = [0 for i in range(m)]
lb = [(lb[i], i) for i in range(m)]
lb.sort()
for i in range(m):
	answer[lb[i][1]] = la[i]
for ans in answer:
	print(ans, end=' ')


len_ab = int(input())
a_idx___value = [int(x) for x in input().split()]
b_idx___value = [int(x) for x in input().split()]
a_idx___idx__value = list(enumerate(a_idx___value))
b_idx___idx__value = list(enumerate(b_idx___value))
a_ord___idx__value = sorted(a_idx___idx__value, key=lambda x: x[1])
b_ord___idx__value = sorted(b_idx___idx__value, key=lambda x: x[1], reverse=True)
b_idx___b_ord = [''] * len_ab
for (b_ord, (idx, value)) in enumerate(b_ord___idx__value):
	b_idx___b_ord[idx] = b_ord
new_a_idx___value = []
for b_ord in b_idx___b_ord:
	new_a_idx___value.append(a_ord___idx__value[b_ord][1])
print(*new_a_idx___value)


import operator

class pa:

	def __init__(self, b, i):
		self.b = b
		self.i = i
n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
a.sort()
m = []
for i in range(n):
	tp = pa(b[i], i)
	m.append(tp)
m.sort(key=operator.attrgetter('b'))
c = [0] * n
for i in range(n):
	c[m[i].i] = a[n - i - 1]
out = ''
for i in range(n):
	out += str(c[i]) + ' '
print(out)


m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_s = sorted(b)
a_s = sorted(a, reverse=True)
d = {}
ans = [0 for i in range(m)]
for i in range(m):
	d[b_s[i]] = d.get(b_s[i], [])
	d[b_s[i]].append(a_s[i])
last = {}
for i in range(m):
	last[b[i]] = last.get(b[i], -1) + 1
	ans[i] = d.get(b[i])[last[b[i]]]
print(*ans)


n = int(input())
A = list(map(int, input().split(' ')))
A_ = [0] * n
B = list(map(int, input().split(' ')))
for i in range(n):
	B[i] = (B[i], i)
B.sort(key=lambda x: x[0])
A.sort(key=lambda x: -x)
for i in range(n):
	A_[B[i][1]] = A[i]
print(' '.join(map(str, A_)))


import sys
import math
import collections
inp = lambda : sys.stdin.readline()
m = 998244353
n = int(inp())
a = list(map(int, inp().split()))
b = list(map(int, inp().split()))
ia = {}
ib = {}
for i in range(n):
	if a[i] not in ia:
		ia[a[i]] = []
	if b[i] not in ib:
		ib[b[i]] = []
	ia[a[i]].append(i)
	ib[b[i]].append(i)
a.sort(reverse=True)
b.sort()
ans = [0] * n
for i in range(n):
	idx = ib[b[i]].pop()
	ans[idx] = a[i]
print(*ans)


m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_streak = a.copy()
b_streak = b.copy()
a_streak.sort(reverse=True)
b_streak.sort()
mapping = {}
for (ind, b_i) in enumerate(b_streak):
	if b_i not in mapping:
		mapping[b_i] = [a_streak[ind]]
	else:
		mapping[b_i].append(a_streak[ind])
ans = []
for b_i in b:
	ans.append(mapping[b_i].pop())
print(*ans)


n = int(input())
inp = lambda : [*list(map(int, input().split()))]
a = sorted(inp(), reverse=True)
b = inp()
c = sorted([(i, b[i]) for i in range(n)], key=lambda x: x[1])
ans = [''] * n
for i in range(n):
	ans[c[i][0]] = str(a[i])
print(' '.join(ans))


m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(m):
	b[i] = (b[i], i)
b.sort(key=lambda b: b[0])
a.sort(reverse=True)
for i in range(m):
	a[i] = (a[i], b[i][1])
a.sort(key=lambda a: a[1])
for i in a:
	print(i[0], end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
a.reverse()
j = []
for i in range(n):
	j.append([b[i], i])
j.sort()
ans = [0] * n
for i in range(n):
	ans[j[i][1]] = str(a[i])
print(' '.join(ans))


m = int(input())
a = list(map(int, input().split()))
b = list(zip(map(int, input().split()), range(m)))
a.sort(reverse=True)
b.sort()
c = list(zip((t[1] for t in b), a))
c.sort()
print(*(t[1] for t in c))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	b[i] = (b[i], i)
a.sort(reverse=True)
b.sort()
ans = [0] * n
for i in range(n):
	ans[b[i][1]] = a[i]
print(*ans)


m = int(input())
m_a = list(map(int, input().split()))
m_b = list(map(int, input().split()))
sort_m_a = sorted(m_a, reverse=True)
sort_m_b = sorted(m_b)
d = dict()
for (i, num) in enumerate(sort_m_b):
	if num not in d:
		d[num] = [i]
	else:
		d[num].append(i)
for num in m_b:
	print(sort_m_a[d[num].pop()], end=' ')


n = int(input())
ip1 = list(map(int, input().split()))
ip2 = list(map(int, input().split()))
for i in range(n):
	ip2[i] = (ip2[i], i)
ip2 = sorted(ip2, key=lambda x: x[0])
ip1 = sorted(ip1, reverse=True)
ip3 = [0 for i in range(n)]
for i in range(n):
	(a, b) = ip2[i]
	ip3[b] = ip1[i]
for i in ip3:
	print(i, end=' ')


R = lambda : map(int, input().split())
n = int(input())
a = sorted(R())
c = [0] * n
for (i, (_, j)) in enumerate(sorted(zip(R(), range(n)))):
	c[j] = a[-1 - i]
print(' '.join(map(str, c)))


n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = list(map(int, input().split()))
c = sorted([(i, b[i]) for i in range(n)], key=lambda x: x[1])
res = [0] * n
for i in range(n):
	res[c[i][0]] = a[i]
print(*res)


ii = lambda : int(input())
mi = lambda : list(map(int, input().split()))
li = lambda : list(mi())
si = lambda : input()
msi = lambda : list(map(int, stdin.readline().split()))
lsi = lambda : list(msi())
m = int(input())
a = list(map(int, input().split()))
b = list(zip(list(map(int, input().split())), list(range(m))))
a.sort(reverse=True)
b.sort()
c = list(zip((t[1] for t in b), a))
c.sort()
print(*(t[1] for t in c))


n = int(input())
a = list(map(int, input().split()))
b = list(zip(map(int, input().split()), range(n)))
a.sort(reverse=True)
b.sort()
c = list(zip((r[1] for r in b), a))
c.sort()
print(*(r[1] for r in c))


n = int(input())
s1 = input().split()
s2 = input().split()
c1 = [(int(s1[i]), i) for i in range(len(s1))]
c2 = [(int(s2[i]), i) for i in range(len(s2))]
c1 = sorted(c1, key=lambda x: x[0], reverse=True)
c2 = sorted(c2, key=lambda x: x[0])
d = [0 for i in range(n)]
for i in range(n):
	nom = c2[i][1]
	d[nom] = c1[i][0]
s = ''
for c in d:
	s += str(c) + ' '
print(s)


m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [0] * len(a)
d = {}
for i in range(len(b)):
	x = b[i]
	if x in d:
		e = d[x]
		e.append(i)
		d[x] = e
	else:
		d[x] = [i]
a.sort(reverse=True)
b.sort()
for i in range(len(b)):
	x = b[i]
	y = a[i]
	r = d[x]
	j = r.pop()
	d[x] = r
	l[j] = y
print(*l)


import sys
inf = float('inf')
ip = lambda : sys.stdin.readline().rstrip()
split = lambda : ip().split(' ')
ip1 = lambda : map(int, split())
arr = lambda : list(ip1())
arr1 = lambda n: [arr() for _ in range(n)]
n = int(ip())
a = arr()
b = arr()
b = [[b[i], i] for i in range(n)]
a.sort()
b.sort(reverse=True)
ans = [0] * n
while b:
	rmv = b.pop()
	(val, idx) = (rmv[0], rmv[1])
	ans[idx] = a.pop()
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
u = []
for j in range(n):
	u.append([b[j], j])
u.sort()
p = [0] * n
y = n - 1
for j in u:
	p[j[1]] = a[y]
	y -= 1
print(*p)


m = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
B_idx = sorted([(v, i) for (i, v) in enumerate(B)], reverse=True)
for i in range(m):
	B[B_idx[i][1]] = A[i]
print(' '.join([str(v) for v in B]))


n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
c = []
a.sort(reverse=True)
for i in range(n):
	d = []
	d.append(b[i])
	d.append(i)
	c.append(d)
c = sorted(c)
d = [0 for i in range(n)]
for i in range(n):
	d[c[i][1]] = a[i]
for i in range(n):
	print(d[i], end=' ')


from operator import itemgetter
(n, d) = (int(input()), {})
(a, b) = (sorted(map(int, input().split()), reverse=True), sorted(sorted(enumerate(map(int, input().split())), reverse=True), key=itemgetter(1)))
for i in range(n):
	d[b[i][0]] = a[i]
for i in range(n):
	print(d[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b = sorted([(b[i], i) for i in range(n)])
new = [0] * n
for s in range(n):
	le = n - 1 - s
	new[b[s][1]] = str(a[le])
print(' '.join(new))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append([b[i], i])
c = sorted(c)
a = sorted(a)
p = [0] * n
for x in range(n):
	p[c[x][1]] = a[n - x - 1]
for i in range(n):
	print(p[i], end=' ')


import sys, os
n = int(input())
data = list(map(int, input().split()))
data2 = list(map(int, input().split()))
data3 = []
for i in range(n):
	data3.append([data2[i], i])
data3 = sorted(data3)
data = sorted(data, reverse=True)
answer = [0] * n
for i in range(n):
	answer[data3[i][1]] = data[i]
print(*answer)


import sys
input = sys.stdin.readline
print = sys.stdout.write
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list(enumerate(map(int, input().split())))
b.sort(key=lambda x: x[1], reverse=True)
gg = [0] * n
for i in range(n):
	gg[b[i][0]] = a[i]
for i in range(n):
	print(str(gg[i]) + ' ')


m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = list(enumerate(b))
a = sorted(a, reverse=True)
b = sorted(b, key=lambda x: x[1])
l = [0] * m
for i in range(m):
	l[b[i][0]] = a[i]
for i in l:
	print(str(i) + ' ', end='')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append([i, b[i]])
c = sorted(c, key=lambda a: a[1])
a = sorted(a, reverse=True)
for i in range(n):
	c[i].append(a[i])
c = sorted(c, key=lambda a: a[0])
for i in range(n):
	print(c[i][2], end=' ')


dictx = {}
m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(m):
	if b[i] in dictx.keys():
		dictx[b[i]].append(i)
	else:
		dictx[b[i]] = [i]
newa = [0 for i in range(m)]
a.sort(reverse=True)
b.sort()
for i in range(m):
	newa[dictx[b[i]].pop()] = a[i]
print(*newa)


m = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
_B = [(B[i], i) for i in range(m)]
_B.sort()
A.sort(reverse=True)
ans = [0 for i in range(m)]
for i in range(m):
	ans[_B[i][1]] = A[i]
for i in ans:
	print(i, end=' ')
print()


m = int(input())
A = list(map(int, input().split()))
B = list(zip(map(int, input().split()), range(1, m + 1)))
B.sort()
A.sort(reverse=True)
D = list(zip((t[1] for t in B), A))
D.sort()
for x in D:
	print(x[1], end=' ')


m = int(input())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(((bi, i) for (i, bi) in enumerate(map(int, input().split()))))
v = [None] * m
for i in range(m):
	v[b[i][1]] = str(a[i])
print(' '.join(v))


def getSum(a, b):
	cont = 0
	for i in range(0, len(a)):
		cont += (a[i] + 1) / (b[i] + 1)
	return cont
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ordenadoB = []
ordenadoA = []
for i in range(0, len(a)):
	ordenadoB.append((i, b[i]))
	ordenadoA.append((i, a[i]))
ordenadoB = sorted(ordenadoB, key=lambda x: x[1])
ordenadoA = sorted(ordenadoA, key=lambda x: x[1], reverse=True)
res = []
for i in range(0, len(ordenadoA)):
	res.append((ordenadoB[i][0], ordenadoA[i][1]))
res = sorted(res, key=lambda x: x[0])
for i in res:
	print(i[1], end=' ')
print('')


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = list(map(int, input().split()))
	l = sorted(range(n), key=b.__getitem__, reverse=True)
	for (i, j) in enumerate(l):
		b[j] = a[i]
	print(*b)
for _ in range(1):
	solve()


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort(reverse=True)
B1 = sorted(enumerate(B), key=lambda x: x[1])
B2 = sorted(enumerate(B1), key=lambda x: x[1])
ans = [A[b[0]] for b in B2]
print(' '.join(map(str, ans)))


n = int(input())
arr = [int(x) for x in input().split()]
idx = [int(x) for x in input().split()]
arr.sort(reverse=True)
idx = sorted(range(n), key=lambda x: idx[x])
perm = [0] * n
for i in range(n):
	perm[idx[i]] = arr[i]
print(*perm, sep=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bb = list(enumerate(b))
bb = sorted(bb, key=lambda x: x[1])
a.sort(reverse=True)
c = [0] * n
for i in range(n):
	c[bb[i][0]] = a[i]
print(*c)


from sys import stdin, stdout, setrecursionlimit
import threading

def main():
	m = int(stdin.readline().strip())
	a = [int(_) for _ in stdin.readline().strip().split()]
	b = [int(_) for _ in stdin.readline().strip().split()]
	c = []
	for (i, v) in enumerate(b):
		c.append((v, i))
	a = sorted(a, reverse=True)
	c = sorted(c)
	ans = [0 for i in range(m)]
	j = 0
	for (v, i) in c:
		ans[i] = a[j]
		j += 1
	stdout.write(' '.join((str(_) for _ in ans)))

def __starting_point():
	setrecursionlimit(10 ** 6)
	threading.stack_size(134217728)
	thread = threading.Thread(target=main)
	thread.start()
__starting_point()


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
m = int(input())
a = listin()
b = listin()
d = defaultdict(list)
for i in range(m):
	d[b[i]].append(i)
nums = deque(sorted(d.keys()))
a.sort(reverse=True)
a = deque(a)
ans = [0 for i in range(m)]
while nums:
	while d[nums[0]]:
		ans[d[nums[0]].pop()] = a.popleft()
	nums.popleft()
print(*ans)


import copy
nothing = int(input())
n = list(map(int, input().split()))
kfirst = list(map(int, input().split()))
k = copy.deepcopy(kfirst)
k.sort()
n.sort()
n = n[::-1]
m = {}
for (i, item) in enumerate(k):
	if item not in m:
		m[item] = [n[i]]
	else:
		tmp = m[item]
		tmp.append(n[i])
		m[item] = tmp
for item in kfirst:
	print(m[item].pop(), end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(lambda x: (int(x[1]), x[0]), enumerate(input().split())))
res = [0] * n
a.sort(reverse=True)
b.sort()
for i in range(n):
	res[b[i][1]] = a[i]
print(' '.join(map(str, res)))


n = int(input())
a = list(map(int, input().split()))
b1 = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([b1[i], i])
b.sort()
a.sort()
ans = [0] * n
for i in range(n):
	ans[b[i][1]] = a[n - i - 1]
print(*ans)


import math

def bcof(x, y):
	a = math.factorial(x)
	b = math.factorial(y)
	c = math.factorial(x - y)
	return a // (b * c)

def F(n, k):
	return bcof(n + 1, k + 1)

class CodeforcesTask840ASolution:

	def __init__(self):
		self.result = ''
		self.m = 0
		self.a = []
		self.b = []

	def read_input(self):
		self.m = int(input())
		self.a = [int(x) for x in input().split(' ')]
		self.b = [int(x) for x in input().split(' ')]

	def process_task(self):
		b = [(i, x) for (i, x) in enumerate(self.b)]
		b.sort(key=lambda tup: tup[1])
		self.a.sort(reverse=True)
		new_a = [0 for x in range(len(b))]
		for x in range(len(b)):
			new_a[b[x][0]] = self.a[x]
		self.result = ' '.join([str(x) for x in new_a])

	def get_result(self):
		return self.result

def __starting_point():
	Solution = CodeforcesTask840ASolution()
	Solution.read_input()
	Solution.process_task()
	print(Solution.get_result())
__starting_point()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [i for i in range(n)]
list1 = list(zip(c, b))
list1 = sorted(list1, key=lambda x: x[1], reverse=False)
a = sorted(a, reverse=True)
ans = [0] * n
for i in range(n):
	ans[list1[i][0]] = a[i]
for v in ans:
	print(v, end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = []
for i in range(n):
	p.append((b[i], i + 1))
p.sort()
a.sort()
a.reverse()
c = [0] * (n + 1)
for i in range(n):
	c[p[i][1]] = a[i]
for i in range(n):
	print(c[i + 1], end=' ')


from sys import stdin, stdout
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
c = [(b[i], i) for i in range(n)]
a.sort(reverse=True)
c.sort(key=lambda x: x[0])
d = [0] * n
for i in range(n):
	sentTo = c[i][1]
	d[sentTo] = str(a[i])
print(' '.join(d))


def f(a, b, m):
	b = list(zip(b, range(m)))
	b = sorted(b, key=lambda s: s[0])
	a = sorted(a, reverse=True)
	ans = [None] * m
	for i in range(m):
		ans[b[i][1]] = a[i]
	return ans
m = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
print(*f(a, b, m))


def decompose(ns):
	ds = {}
	for (i, n) in enumerate(ns):
		if n in ds.keys():
			ds[n].append(i)
		else:
			ds[n] = [i]
	ns.sort()
	out = []
	for n in ns:
		out.append(ds[n].pop())
	return out

def compose(ns, d):
	out = [0] * len(ns)
	for (i, n) in enumerate(ns):
		out[d[i]] = n
	return out
input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
a.reverse()
print(' '.join(map(str, compose(a, decompose(b)))))


import sys
m = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
BB = [(B[i], i) for i in range(m)]
A.sort()
BB.sort()
BB.reverse()
C = [0 for i in range(m)]
for i in range(m):
	C[BB[i][1]] = A[i]
print(' '.join((str(c) for c in C)))


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
newA = [0 for n in range(N)]
Bp = list(enumerate(B))
A.sort(key=lambda x: -x)
Bp.sort(key=lambda x: x[1])
i = 0
for (index, val) in Bp:
	newA[index] = A[i]
	i += 1
for a in newA:
	print(a, end=' ')
print()


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
r1 = []
r2 = []
ans = [0 for i in range(n + 1)]
for i in range(n):
	r1.append((l1[i], i + 1))
for j in range(n):
	r2.append((l2[j], j + 1))
r1.sort(reverse=True)
r2.sort()
for i in range(n):
	ans[r2[i][1]] = r1[i][0]
ans = ans[1:]
print(*ans)


m = int(input())
ns = [int(v) for v in input().split()]
ks = [int(v) for v in input().split()]
kks = [(k, i) for (i, k) in enumerate(ks)]
kks.sort()
ns.sort(reverse=True)
ans = [None] * m
for ((k, i), n) in zip(kks, ns):
	ans[i] = n
print(' '.join((str(v) for v in ans)))


m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * m
z = []
for i in range(m):
	z.append([b[i], i])
z.sort()
a.sort()
a = a[::-1]
for i in range(m):
	j = z[i][1]
	ans[j] = a[i]
print(*ans)


import sys
num_n = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline()[:-1].split(' ')]
B = [int(x) for x in sys.stdin.readline()[:-1].split(' ')]
B1 = B.copy()
A.sort()
B.sort()
umap = {}
for num in B:
	if num in umap:
		umap[num].append(A.pop())
	else:
		umap[num] = list([A.pop()])
for num in B1:
	print(umap[num].pop(), end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bi = [(b[i], i) for i in range(n)]
bi = sorted(bi, key=lambda x: x[0])
a = sorted(a, key=lambda x: -x)
ans = [0 for i in range(n)]
for i in range(n):
	ans[bi[i][1]] = a[i]
print(' '.join([str(i) for i in ans]))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b = sorted([(b[i], i) for i in range(n)])
a2 = [0] * n
for s in range(n):
	q = n - 1 - s
	a2[b[s][1]] = str(a[q])
print(' '.join(a2))


n = int(input())
a = list(map(int, input().split()))
b = [(a, i) for (i, a) in enumerate(map(int, input().split()))]
a.sort()
b.sort(reverse=True)
answer = [0] * n
for i in range(n):
	answer[b[i][1]] = a[i]
for x in answer:
	print(x, end=' ')
print()


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = sorted([(x, i) for (i, x) in enumerate(A)], reverse=True)
B = sorted([(x, i) for (i, x) in enumerate(B)])
ans = [0] * N
for i in range(N):
	(a, ia) = A[i]
	(b, ib) = B[i]
	ans[ib] = a
print(' '.join(map(str, ans)))


m = int(input())
a = map(int, input().split())
b = list(zip(map(int, input().split()), range(m)))
b.sort(key=lambda x: x[0])
ans = []
a = list(zip(sorted(a, reverse=True), [x[1] for x in b]))
a.sort(key=lambda x: x[1])
print(*[x[0] for x in a])


m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [(i, a[i]) for i in range(m)]
b = [(i, b[i]) for i in range(m)]
a.sort(key=lambda x: -x[1])
b.sort(key=lambda x: x[1])
c = [(b[i][0], a[i][1]) for i in range(m)]
c.sort(key=lambda x: x[0])
for i in c:
	print(i[1], end=' ')


class Element(object):

	def __init__(self, val, index, asigned=-1):
		self.val = val
		self.index = index
		self.asigned = asigned

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b_el = [Element(0, 0) for i in range(n)]
	for i in range(0, n):
		b_el[i].val = b[i]
		b_el[i].index = i
	a = sorted(a)
	b_el = sorted(b_el, key=lambda x: x.val)
	for i in range(0, n):
		b_el[i].asigned = a[n - 1 - i]
	b_el = sorted(b_el, key=lambda x: x.index)
	for i in b_el:
		print(i.asigned, end=' ')
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a, reverse=True)
b_store = [[b[i], i] for i in range(n)]
b_store = sorted(b_store)
ans = [0] * n
for i in range(n):
	ans[b_store[i][1]] = a[i]
for i in ans:
	print(i, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
u = [(b[i], i) for i in range(n)]
a.sort()
u.sort(reverse=True)
ans = [(u[i][1], a[i]) for i in range(n)]
ans.sort()
r = [i[1] for i in ans]
print(*r)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b1 = []
a1 = []
for i in range(n):
	b1.append(b[i])
	a1.append(a[i])
b1.sort()
a1.sort()
a1.reverse()
d = dict()
for i in range(n):
	if b1[i] in d:
		d[b1[i]].append(a1[i])
	else:
		d[b1[i]] = [a1[i]]
for i in range(n):
	a[i] = d[b[i]][len(d[b[i]]) - 1]
	d[b[i]].pop()
print(*a)


from typing import List

def solve(n: int, a: List[int], b: List[int]) -> str:
	a = sorted(a, reverse=True)
	b = sorted(enumerate(b), key=lambda x: x[1])
	c = sorted(list(zip(a, b)), key=lambda x: x[1][0])
	return ' '.join([str(x[0]) for x in c])
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
print(solve(n, a, b))


import operator
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
dic = {}
for i in range(len(b)):
	dic[i] = b[i]
a = sorted(a, reverse=True)
sorted_dic = sorted(dic.items(), key=operator.itemgetter(1))
answer = [0] * n
for i in range(len(a)):
	answer[sorted_dic[i][0]] = a[i]
print(*answer)