Sort by Custom Priority
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.
Example 1
5 10 5 20 15 25 5 15 10 25 20
5 15 10 25 20
The list is sorted according to the priority order: 5, 15, 10, 25, 20.
Example 2
3 100 200 300 300 100 200
300 100 200
The list is sorted according to the priority order: 300, 100, 200.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 10 5 20 15 25 5 15 10 25 20
3 100 200 300 300 100 200