n = int(input())
height = list(map(int,input().split()))
sex = list(map(int,input().split()))
boys = []
girls = []
for i in range(n):
if sex[i] == 0:
boys.append(height[i])
else:
girls.append(height[i])
girls.sort()
boys.sort()
print(*girls,end=' ')
print(*boys)