#K3891. Book Orders Calculation

    ID: 26303 Type: Default 1000ms 256MiB

Book Orders Calculation

Book Orders Calculation

You are given a list of reading programs. Each reading program specifies a set of books along with the number of copies required for each book. Your task is to determine the maximum number of copies required for each book across all reading programs.

More formally, if there are p reading programs and each program contains a subset of books with their required copies, for each book you need to output the maximum count that appears in any program.

Mathematical Formulation

Let the number of copies required for book i in program j be \(a_{ij}\). Your task is to compute \(b_i = \max_{1 \le j \le p} a_{ij}\) for every book i.

inputFormat

The first line contains an integer P representing the number of reading programs.

For each program, the first line contains an integer N denoting the number of books in that program. This is followed by N lines, each containing a book name (a string without spaces) and a non-negative integer representing the number of copies required for that book.

Assume that the book names are case-sensitive. Each book may appear in one or more programs.

outputFormat

For each unique book across all programs, print a line containing the book name and the maximum count required, separated by a space. The output should list the books in lexicographical order of their names.

## sample
3
2
BookA 5
BookB 3
3
BookA 1
BookB 4
BookC 2
3
BookA 2
BookB 0
BookC 3
BookA 5

BookB 4 BookC 3

</p>