Intersection of objects with priorities

Go Hard structs

Task «Intersection of objects with priorities»

Two sets of structures describing objects with an identifier, type, and priority are given. It is necessary to find all objects that are present in both sets (have the same identifier and type), and for each such object, output its identifier, type, and the minimum priority from the two sets. If an object appears more than once in one set, only the first occurrence is considered. Output the result in ascending order of identifier, and in case of equality, by type (lexicographically).

Input Format

In the first line, an integer N — the number of objects in the first set. Then N lines, each containing an identifier (integer), type (string without spaces), and priority (integer) separated by spaces. In the next line, an integer M — the number of objects in the second set. Then M lines in the same format.

Output Format

For each intersecting object, output one line: identifier, type, minimum priority separated by spaces. The lines are sorted by identifier in ascending order, and in case of equality, by type lexicographically. If there are no intersections, output 'none'.

Examples

Example 1

INPUT
3 1 a 10 2 b 20 3 c 30 2 2 b 15 3 c 25
OUTPUT
2 b 15 3 c 25

Example 2

INPUT
2 1 x 5 2 y 10 2 1 x 7 2 y 12
OUTPUT
1 x 5 2 y 10

Example 3

INPUT
1 2 3 4 3 4 5 6
OUTPUT
none

Example 4

INPUT
1 1 2 2 2 2 3 3
OUTPUT
none
main.go