{"problem":{"name":"081. It's a Mess!","description":{"content":"You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in al","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269081"},"statements":[{"statement_type":"Markdown","content":"You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in alphabetical order!\n\nTo fix this problem, you decide to create a program that is able to divide the books into different genre groups, with the authors of the genres listed in alphabetical order.\n\nThe first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space.\n\nOutput a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: _: , , _\n\n(For the order of the genres, please make sure that they are also in alphabetical order.)\n\n(It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.)\n\n## Input\n\nThe first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space.\n\n## Output\n\nOutput a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: _: , , _\n\n[samples]\n\n## Note\n\n(For the order of the genres, please make sure that they are also in alphabetical order.)(It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.)","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of books.  \nLet $ B = \\{ (a_i, g_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of book entries, where:  \n- $ a_i \\in \\mathbb{S} $ is the author's last name (string with proper capitalization),  \n- $ g_i \\in \\mathbb{S} $ is the genre (string).  \n\n**Constraints**  \n1. $ n \\geq 1 $  \n2. Each $ a_i $ and $ g_i $ consists of a single word.  \n\n**Objective**  \nGroup books by genre: for each unique genre $ g $, collect the set of authors $ A_g = \\{ a_i \\mid (a_i, g_i) \\in B \\land g_i = g \\} $.  \nSort genres lexicographically.  \nFor each genre $ g $ in sorted order, sort $ A_g $ lexicographically.  \nOutput each genre $ g $ followed by its sorted author list in the format:  \n$$ g: a_1, a_2, \\dots, a_k $$  \nwhere $ a_1, a_2, \\dots, a_k $ are the sorted authors.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269081","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}