{"problem":{"name":"G. Name the album","description":{"content":"The famous singer, Aryo, is going to publish a new album of his great work! Unfortunately these days, there are many albums, Aryo wants to choose a new name for his album, a name that has not been us","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":65536},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF100G"},"statements":[{"statement_type":"Markdown","content":"The famous singer, Aryo, is going to publish a new album of his great work!\n\nUnfortunately these days, there are many albums, Aryo wants to choose a new name for his album, a name that has not been used or at least has not been used recently.\n\nHe has a list of all used album names together with the year the albums were published. He also has a list of suitable names for his album.\n\nIf he finds a suitable name which has not been used before, he'll use it. Otherwise he will use the name which was used as long ago as possible. If two such names are found (that haven't been used or were used at the same year), he uses the name that is alphabetically latest.\n\nHelp him name his album.\n\n## Input\n\nThe first line contains a single integer _n_ (0 ≤ _n_ ≤ 105), the number of used names.\n\nThe following _n_ lines each contain a string (the album name) and an integer (the year album was published). Album names are made of lowercase Latin letters and contain at most 14 letters. The year is in range \\[1900, 2011\\].\n\nThe following line contains a single integer _m_ (1 ≤ _m_ ≤ 104), the number of suitable album names.\n\nThe following _m_ lines each contain a string — a suitable name. It contains at most 14 lowercase Latin letters.\n\nAll album names and suitable names are non-empty.\n\n## Output\n\nWrite a single string. The name of the new album.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"著名歌手 Aryo 即将发布他的新专辑！\n\n然而，如今专辑数量众多，Aryo 希望为他的专辑选择一个未曾使用过、或至少近期未曾使用过的名称。\n\n他拥有一份所有已使用专辑名称及其发布年份的列表，同时也有一份适合他专辑的候选名称列表。\n\n如果他找到一个从未使用过的候选名称，他将直接使用它。否则，他会选择使用时间最久远的名称。如果存在多个这样的名称（即从未使用过，或均在同一年使用过），他将选择字母序最靠后的名称。\n\n请帮助他为专辑命名。\n\n第一行包含一个整数 #cf_span[n]（#cf_span[0 ≤ n ≤ 10^5]），表示已使用名称的数量。\n\n接下来的 #cf_span[n] 行，每行包含一个字符串（专辑名称）和一个整数（专辑发布的年份）。专辑名称由小写拉丁字母组成，长度不超过 #cf_span[14] 个字符。年份范围为 #cf_span[[1900, 2011]]。\n\n接下来一行包含一个整数 #cf_span[m]（#cf_span[1 ≤ m ≤ 10^4]），表示候选名称的数量。\n\n接下来的 #cf_span[m] 行，每行包含一个字符串——一个候选名称。它由至多 #cf_span[14] 个小写拉丁字母组成。\n\n所有专辑名称和候选名称均为 #cf_span(class=[tex-font-style-underline], body=[non-empty])。\n\n请输出一个字符串，即新专辑的名称。\n\n## Input\n\n第一行包含一个整数 #cf_span[n]（#cf_span[0 ≤ n ≤ 10^5]），表示已使用名称的数量。接下来的 #cf_span[n] 行，每行包含一个字符串（专辑名称）和一个整数（专辑发布的年份）。专辑名称由小写拉丁字母组成，长度不超过 #cf_span[14] 个字符。年份范围为 #cf_span[[1900, 2011]]。接下来一行包含一个整数 #cf_span[m]（#cf_span[1 ≤ m ≤ 10^4]），表示候选名称的数量。接下来的 #cf_span[m] 行，每行包含一个字符串——一个候选名称。它由至多 #cf_span[14] 个小写拉丁字母组成。所有专辑名称和候选名称均为 #cf_span(class=[tex-font-style-underline], body=[non-empty])。\n\n## Output\n\n请输出一个字符串，即新专辑的名称。\n\n[samples]","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ U = \\{(s_i, y_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of used album names, where $ s_i \\in \\Sigma^{*} $ is a non-empty string of lowercase Latin letters (length $ \\leq 14 $) and $ y_i \\in \\mathbb{Z} \\cap [1900, 2011] $ is the publication year.  \nLet $ S = \\{t_j \\mid j \\in \\{1, \\dots, m\\} \\} $ be the set of suitable names, where $ t_j \\in \\Sigma^{*} $ is a non-empty string of lowercase Latin letters (length $ \\leq 14 $).\n\n**Constraints**  \n1. $ 0 \\leq n \\leq 10^5 $  \n2. $ 1 \\leq m \\leq 10^4 $  \n3. All strings consist only of lowercase Latin letters and are non-empty.  \n4. Years satisfy $ 1900 \\leq y_i \\leq 2011 $.\n\n**Objective**  \nFind the album name $ t^* \\in S $ such that:  \n- If $ \\exists t_j \\in S $ with $ t_j \\notin \\{ s_i \\mid (s_i, y_i) \\in U \\} $, then choose the lexicographically latest such $ t_j $.  \n- Otherwise, choose $ t_j \\in S $ that maximizes $ \\min_{(s_i, y_i) \\in U} \\{ y_i \\mid s_i = t_j \\} $ (i.e., the earliest year among used names matching $ t_j $), and if tied, choose the lexicographically latest $ t_j $.\n\nFormally:  \nLet $ V = \\{ t_j \\in S \\mid t_j \\notin \\{ s_i \\mid (s_i, y_i) \\in U \\} \\} $.  \nIf $ V \\neq \\emptyset $, then:  \n$$ t^* = \\arg\\max_{t \\in V} t \\quad \\text{(lexicographically)} $$  \nElse:  \nLet $ W = \\{ t_j \\in S \\mid \\exists (s_i, y_i) \\in U \\text{ s.t. } s_i = t_j \\} $, and define $ f(t_j) = \\min \\{ y_i \\mid (s_i, y_i) \\in U \\land s_i = t_j \\} $.  \nThen:  \n$$ t^* = \\arg\\max_{t_j \\in W} \\left( f(t_j), t_j \\right) \\quad \\text{(lexicographic order on } (f(t_j), t_j) \\text{)} $$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF100G","tags":["data structures","implementation"],"sample_group":[["3\neyesonme 2008\nanewdayhascome 2002\noneheart 2003\n2\noneheart\nbienbien","bienbien"],["2\nnasimevasl 2003\nbasetareha 2006\n2\nnasimevasl\nbasetareha","nasimevasl"]],"created_at":"2026-03-03 11:00:39"}}