n = int(input()) students_dict = {} scores_dict = {}
for i in range(n): inf = input().split() pop_inf = inf.pop(0) students_dict[pop_inf] = inf money = 0 if int(students_dict[pop_inf][0]) > 80 and int(students_dict[pop_inf][4]) >= 1: money += 8000 if int(students_dict[pop_inf][0]) > 85 and int(students_dict[pop_inf][1]) > 80: money += 4000 if int(students_dict[pop_inf][0]) > 90: money += 2000 if int(students_dict[pop_inf][0]) > 85 and students_dict[pop_inf][3] == 'Y': money += 1000 if int(students_dict[pop_inf][1]) > 80 and students_dict[pop_inf][2] == 'Y': money += 850 scores_dict[pop_inf] = money
max_score = max(scores_dict, key=scores_dict.get) print(max_score) print(scores_dict[max_score])
sum_scores = 0 for score in scores_dict.values(): sum_scores = sum_scores + score print(sum_scores)