Rating

No attempts yetTime limit1sMemory limit128 MB

Problem

Two regional programming contests were held in St. Petersburg. A participant who competed in both of them wants to build a single overall rating for every team that took part in at least one contest.

Each team has a unique identifier: an integer from 11 to 100100. For each contest the identifiers of the participating teams are written in a column, ordered from best to worst, and teams that finished with the same result are written together on one line.

Definition: a team has place KK in a contest if exactly K1K-1 teams finished strictly better than it.

For example, consider the results of two contests:

Contest 1Contest 2
placeteam idplaceteam id
1913
27 1 425
5531 10
615 856
831 1869
1017719
84 20
1021

The overall rating is defined by the following rules.

For two teams that both competed in both contests:

  1. If one team finished at least as well as the other in both contests and strictly better in at least one, then its overall rating is higher.
  2. If each of the two teams finished better than the other in exactly one contest, the comparison is decided by the difference of places. In the example team 1 beats team 5 by 3 places in contest 1 but loses to it by only 1 place in contest 2, so team 1 has the higher overall rating. If the two place differences are equal, the two teams have equal overall rating. Teams with identical places in both contests also have equal overall rating.

(Equivalently, for teams that competed in both contests a smaller sum of the two places means a higher overall rating, and equal sums mean equal rating.)

In the example only teams 1, 4, 5, and 9 competed twice. Team 1 has the highest rating, then teams 5 and 9 tie, and team 4 is lowest.

A team that competed in only one contest cannot always be given an overall rating. Such a team is inserted into the overall list (in which the teams that competed twice are already placed by the rules above) only when one of the following holds:

A. If a team that competed in both contests shared this team's place in that one contest, then this team takes the same overall rating as that team. If several such teams exist, they must all have the same overall rating; otherwise this team's rating is undetermined.

B. Otherwise, if there is a position in the overall list (at the very beginning, at the very end, or between two lines) such that every team before it finished better than this team in their common contest and every team after it finished worse, then this team takes that position. If several teams claim the same position, they are ordered among themselves by their places (a smaller place comes first, and teams with equal place share a line).

Illustration of the example:

Teams in both contestsTeams in one contest only
3
110
9 5
19
420
15 8
31 18
17 21
  • Team 3 takes first place (rule B).
  • The positions of teams 6 and 7 cannot be determined.
  • Team 10 shares the rating of team 1 (rule A).
  • Team 20 shares the rating of team 4 (rule A).
  • Team 19 goes between the line "9 5" and team 4 (rule B).
  • Teams 8, 15, 17, 18, 21, and 31 finish the list (rule B): first teams 15 and 8 (place 6), then teams 31 and 18 (place 8), then teams 17 and 21 (place 10).

Write a program that builds the overall rating list from the two contest result tables and the rules above.

Input

The input describes two contests, separated by an empty line. Each description begins with a line containing a single integer NN (1N1001 \le N \le 100), the number of result lines that follow. Each of those lines contains one or more team identifiers separated by spaces. Within one contest every identifier appears at most once.

Output

Print the overall rating list: one or more lines of team identifiers separated by spaces, from the highest overall rating to the lowest, with teams that share the same rating on one line. Within each line print the identifiers in increasing order. Teams whose overall rating is undetermined must not appear.