#K55042. Grade Summarization

    ID: 29887 Type: Default 1000ms 256MiB

Grade Summarization

Grade Summarization

You are given a series of grade records for students in various subjects. Each record consists of a subject name, a student name, and a grade. Your task is to compute, for each student and for each subject, the maximum grade they achieved.

The input first contains an integer n representing the number of records. Each of the following n lines contains a subject, a student name, and an integer grade separated by spaces.

Your output should be a JSON object (in one line without spaces) that maps each student to another JSON object which maps each subject (in lexicographical order) to the highest grade obtained by that student. The student keys in the output should also be sorted lexicographically.

The mathematical idea behind the solution is to compute:

\( result[student][subject] = \max_{\text{all records}}(grade) \)

inputFormat

The first line contains an integer n — the number of grade records. Each of the following n lines contains a record with three fields separated by spaces: a subject (string), a student name (string), and a grade (integer).

For example:

7
math Alice 85
math Bob 90
math Alice 95
science Alice 80
science Bob 85
history Alice 88
history Bob 92

outputFormat

Output a single line containing a JSON object. This object maps each student's name (in lexicographical order) to another JSON object which maps subjects (also in lexicographical order) to the highest grade achieved. There should be no extra spaces in the output JSON.

For example, the output for the sample input above would be:

{"Alice":{"history":88,"math":95,"science":80},"Bob":{"history":92,"math":90,"science":85}}
## sample
7
math Alice 85
math Bob 90
math Alice 95
science Alice 80
science Bob 85
history Alice 88
history Bob 92
{"Alice":{"history":88,"math":95,"science":80},"Bob":{"history":92,"math":90,"science":85}}