Sort by Custom PriorityMedium

Sort by Custom Priority

MediumPractice library · +20 XPsortingcustom sorting

Given a list of integers and a custom priority order, sort the list according to this priority. The priority order is given as a list of distinct integers. All integers in the input list will appear exactly once in the priority list. Print the sorted list.

Input

The first line contains an integer N, the size of the list. The second line contains N integers, the list to be sorted. The third line contains N integers, the custom priority order. All integers in the list and the priority order are distinct and between 1 and 10^9.

Output

Print the N integers of the sorted list, separated by spaces.

Constraints

1 <= N <= 200000. Each integer is between 1 and 10^9.

Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests

Example 1

Input
5
10 5 20 15 25
5 15 10 25 20
Output
5 15 10 25 20

The list is sorted according to the priority order: 5, 15, 10, 25, 20.

Example 2

Input
3
100 200 300
300 100 200
Output
300 100 200

The list is sorted according to the priority order: 300, 100, 200.

Hints