#Q23. 「一本通 1.3 例 5」weight

「一本通 1.3 例 5」weight

Description

Original source: USACO

Given the sums of the first 11, first 22, first 33, \cdots, first nn terms, as well as the sums of the last 11, last 22, last 33, \cdots, last nn terms of the original sequence a1,a2,,ana_1, a_2, \cdots, a_n, but all numbers have been shuffled. Additionally, we know that all elements in the sequence belong to the set SS. The task is to reconstruct the original sequence. If multiple sequences are possible, output the lexicographically smallest one.

Input Format

Line 11: An integer nn.
Line 22: 2×n2 \times n integers, note: the data has been shuffled.
Line 33: An integer mm, the size of set SS.
Line 44: mm integers, representing the elements of set SS.

Output Format

Output the lexicographically smallest sequence that satisfies the conditions.

Sample 1

5
1 2 5 7 7 9 12 13 14 14
4
1 2 4 5

1 1 5 2 5

Data Range and Hints

Data Range

For 100%100\% of the data, 1n10001 \le n \le 1000, 1m5001 \le m \le 500, and S{1,2,,500}S \subseteq \{1, 2, \cdots, 500\}.

Sample Explanation

Sum from Left to Right Sum from Right to Left
01=1+1+5+2+5\phantom{0}1=1\phantom{+1+5+2+5} 05=1+1+5+2+5\phantom{0}5=\phantom{1+1+5+2+}5
02=1+1+5+2+5\phantom{0}2=1+1\phantom{+5+2+5} 07=1+1+5+2+5\phantom{0}7=\phantom{1+1+5+}2+5
07=1+1+5+2+5\phantom{0}7=1+1+5\phantom{+2+5} 12=1+1+5+2+512=\phantom{1+1+}5+2+5
09=1+1+5+2+5\phantom{0}9=1+1+5+2\phantom{+5} 13=1+1+5+2+513=\phantom{1+}1+5+2+5
14=1+1+5+2+514=1+1+5+2+5