#K88662. Arrange Teams

    ID: 37359 Type: Default 1000ms 256MiB

Arrange Teams

Arrange Teams

You are given an integer \(T\) representing the number of teams and an integer \(P\) representing the total number of team members. In addition, you are provided with a list of \(T\) team leaders and \(P\) records of team members. Each team member record consists of the leader's name, the member's name, and the member's age.

Your task is to arrange the teams as follows:

  • Sort the team leaders in lexicographical order.
  • For each team leader, list the team leader's name on a separate line.
  • Then list their team members, sorted in ascending order by age. Each member should be printed in the format: <member_name> <age>.

Input Format: The input is read from standard input.

inputFormat

The input consists of multiple lines. The first line contains an integer \(T\) denoting the number of teams.

The second line contains an integer \(P\) denoting the total number of team member records.

The third line contains \(T\) space-separated strings, representing the names of the team leaders.

The following \(P\) lines each contain a team member record in the format:

team_leader member_name age

where team_leader is the name of the team leader to whom the member belongs, member_name is the name of the member, and age is an integer representing the member's age.

outputFormat

For each team leader (in lexicographical order), print the leader's name on a new line. Then for each team member (sorted by ascending age) of that leader, print the member's name and age on a new line in the format:

member_name age

All output is written to standard output.

## sample
3
5
alice bob carol
bob eve 25
alice charlie 20
carol dave 22
alice bob 24
bob chris 27
alice

charlie 20 bob 24 bob eve 25 chris 27 carol dave 22

</p>