# Arup Guha
# 11/17/2020
# Program to calculate every student's best SAT score.

# Dictionaries to store each student's best math and best verbal scores.
math = {}
verbal = {}

# See if they want to process another file.
ans = input("Would you like to enter another set of scores?\n")

# Process each file.
while ans == "yes":

    # Get and open the file.
    filename = input("What file has the input?\n")
    file = open(filename)

    # Go through each student's scores.
    numScores = int(file.readline())
    for i in range(numScores):

        # Read name, and parse out scores.
        name = file.readline().rstrip()
        toks = file.readline().split()
        mathScore = int(toks[0])
        verbalScore = int(toks[1])

        # If you never took the test before, add your scores in.
        if not name in math:
            math[name] = mathScore
            verbal[name] = verbalScore

        # You did it before, so let's see if we have to update anything.
        else:

            # Math is a new best.
            if mathScore > math[name]:
                math[name] = mathScore

            # Verbal is a new best.
            if verbalScore > verbal[name]:
                verbal[name] = verbalScore

    # Acknowledgement message.
    print("Great we have uploaded your scores.")

    # See if there is another file.
    ans = input("Would you like to enter another set of scores?\n")

# Now output results. math.keys() returns the set of keys in the dictionary,
# and sorted is a function that makes sure that the set is iterated through in
# sorted order.
for name in sorted(math.keys()):
    print(name,"\t",math[name],"\t", verbal[name],"\t", math[name]+verbal[name])



            









                 
