Олимпиадный тренинг

Задача 45263. Relative sort


Given two arrays arr1 and arr2. The elements of the arr2 array are distinct, and all the elements of the arr2 are contained in arr1.

Sort the elements of the array arr1 so that the relative order of the elements in the array arr1 is the same as in the array arr2< /code>. Elements that are not in the array arr2 should be at the end of the array arr1 in ascending order.



Input
The first line of the input contains an integer n - the number of elements in the array arr1, the second line contains n integers - the elements of the array arr1< /code>. The third line contains an integer m - the number of elements in the array arr2, the fourth line contains m integers - the elements of the array arr2.

Input Restrictions
  • 1 <= n, m <= 106
  • 0 <= arr1[i], arr2[i] <= 1000
  • All array elements arr2 are distinct.
  • Each element of the array arr2[i] is contained in the array arr1.


Imprint
Output the array arr1.
sorted by the task condition  
 
Examples
# Input Output
1 11
2 3 1 3 2 4 6 7 9 2 19
6
2 1 4 3 9 6
2 2 2 1 4 3 3 9 6 7 19
2 6
28 6 22 8 44 17
4
22 28 8 6
22 28 8 6 17 44