Each year, a prestigious culinary circuit crowns one champion chef in each of four separate competitions: the Golden Spoon, the Iron Skillet, the Silver Ladle, and the Copper Whisk. A single chef may win more than one of the four titles in the same year, and a chef who has already won a title may go on to win more in later years.
Given the roster of chefs on the circuit and the champions crowned across several years, find the total number of championship titles each chef has won overall, summed across every competition and every year. Report only the chefs who have won at least one title, ordered from the most total titles to the fewest; break any tie in total titles by ordering those chefs alphabetically by name.
For every chef with at least one total title, print a line "name count" — the chef's name, a single space, and their total title count — ordered by count descending, then by name ascending among ties. Chefs with zero titles must not be printed.
Example 1
Input
2 3 1 2 1 3 2 2 3 1 OLIVER PRIYA KENJI
Expected
OLIVER 3 PRIYA 3 KENJI 2
Explanation
In year 1, chef 1 (OLIVER) wins the Golden Spoon and the Silver Ladle (2 titles), chef 2 (PRIYA) wins the Iron Skillet (1), and chef 3 (KENJI) wins the Copper Whisk (1). In year 2, chef 2 wins the Golden Spoon and the Iron Skillet (2 titles), chef 3 wins the Silver Ladle (1), and chef 1 wins the Copper Whisk (1). Totals: OLIVER = 2+1 = 3, PRIYA = 1+2 = 3, KENJI = 1+1 = 2. OLIVER and PRIYA tie at 3, so they are ordered alphabetically (OLIVER before PRIYA), followed by KENJI at 2.
Example 2
Input
1 3 1 1 1 1 ASHA BEN CARLA
Expected
ASHA 4
Explanation
In the single year, chef 1 (ASHA) wins all four titles — the Golden Spoon, Iron Skillet, Silver Ladle, and Copper Whisk — for a total of 4. Chefs BEN and CARLA never appear as a winner in any column, so their total is 0 and they are omitted entirely from the output.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →