{"raw_statement":[{"iden":"statement","content":"Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).\n\nThis priority factor will be affected by three types of actions:\n\n*   1\\. \"__X_ posted on _Y_'s wall_\" (15 points),\n*   2\\. \"__X_ commented on _Y_'s post_\" (10 points),\n*   3\\. \"__X_ likes _Y_'s post_\" (5 points).\n\n_X_ and _Y_ will be two distinct names. And each action will increase the priority factor between _X_ and _Y_ (and vice versa) by the above value of points (the priority factor between _X_ and _Y_ is the same as the priority factor between _Y_ and _X_).\n\nYou will be given _n_ actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you."},{"iden":"input","content":"The first line contains your name. The second line contains an integer _n_, which is the number of actions (1 ≤ _n_ ≤ 100). Then _n_ lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters."},{"iden":"output","content":"Print _m_ lines, where _m_ is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.\n\nNote, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.\n\nThe lexicographical comparison is performed by the standard \"_<_\" operator in modern programming languages. The line _a_ is lexicographically smaller than the line _b_, if either _a_ is the prefix of _b_, or if exists such an _i_ (1 ≤ _i_ ≤ _min_(|_a_|, |_b_|)), that _a__i_ < _b__i_, and for any _j_ (1 ≤ _j_ < _i_) _a__j_ = _b__j_, where |_a_| and |_b_| stand for the lengths of strings _a_ and _b_ correspondently."},{"iden":"examples","content":"Input\n\nahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n\nOutput\n\nfatma\nmona\n\nInput\n\naba\n1\nlikes likes posted's post\n\nOutput\n\nlikes\nposted"}],"translated_statement":[{"iden":"statement","content":"Facetook 是一个知名的社交网络网站，它将推出一项名为 Facetook 优先墙的新功能。该功能将根据优先级因子对您好友的所有帖子进行排序（优先级因子将在下文描述）。\n\n该优先级因子将受到三种类型操作的影响：\n\n#cf_span[X] 和 #cf_span[Y] 将是两个不同的名字。每次操作都会将 #cf_span[X] 和 #cf_span[Y] 之间的优先级因子（以及反向）增加上述分数值（#cf_span[X] 和 #cf_span[Y] 之间的优先级因子与 #cf_span[Y] 和 #cf_span[X] 之间的优先级因子相同）。\n\n您将获得 #cf_span[n] 个上述格式的操作（不含操作编号和分数值），您需要打印出这些操作中所有不同的名字，并按照它们与您的优先级因子进行排序。\n\n第一行包含您的名字。第二行包含一个整数 #cf_span[n]，表示操作的数量（#cf_span[1 ≤ n ≤ 100]）。接下来是 #cf_span[n] 行，每行恰好包含一个上述格式的操作。每行中每两个单词之间恰好有一个空格，且没有多余的空格。所有字母均为小写。输入中的所有名字均由至少 1 个、至多 10 个小写拉丁字母组成。\n\n请输出 #cf_span[m] 行，其中 #cf_span[m] 是输入中不同名字的数量（不包括您自己）。每行仅包含一个名字。名字应按与您的优先级因子降序排列（优先级因子最高的排在最前）。如果两个或更多名字具有相同的优先级因子，则按字母顺序（字典序）输出。\n\n请注意，您应输出输入数据中出现的所有名字（不包括您自己），即使该人的优先级因子为零。\n\n字典序比较由现代编程语言中的标准 \"_<_\" 运算符执行。字符串 #cf_span[a] 字典序小于字符串 #cf_span[b]，当且仅当 #cf_span[a] 是 #cf_span[b] 的前缀，或者存在某个 #cf_span[i]（#cf_span[1 ≤ i ≤ min(|a|, |b|)]），使得 #cf_span[ai < bi]，且对任意 #cf_span[j]（#cf_span[1 ≤ j < i]）都有 #cf_span[aj = bj]，其中 #cf_span[|a|] 和 #cf_span[|b|] 分别表示字符串 #cf_span[a] 和 #cf_span[b] 的长度。"},{"iden":"input","content":"第一行包含您的名字。第二行包含一个整数 #cf_span[n]，表示操作的数量（#cf_span[1 ≤ n ≤ 100]）。接下来是 #cf_span[n] 行，每行恰好包含一个上述格式的操作。每行中每两个单词之间恰好有一个空格，且没有多余的空格。所有字母均为小写。输入中的所有名字均由至少 1 个、至多 10 个小写拉丁字母组成。"},{"iden":"output","content":"请输出 #cf_span[m] 行，其中 #cf_span[m] 是输入中不同名字的数量（不包括您自己）。每行仅包含一个名字。名字应按与您的优先级因子降序排列（优先级因子最高的排在最前）。如果两个或更多名字具有相同的优先级因子，则按字母顺序（字典序）输出。请注意，您应输出输入数据中出现的所有名字（不包括您自己），即使该人的优先级因子为零。字典序比较由现代编程语言中的标准 \"_<_\" 运算符执行。字符串 #cf_span[a] 字典序小于字符串 #cf_span[b]，当且仅当 #cf_span[a] 是 #cf_span[b] 的前缀，或者存在某个 #cf_span[i]（#cf_span[1 ≤ i ≤ min(|a|, |b|)]），使得 #cf_span[ai < bi]，且对任意 #cf_span[j]（#cf_span[1 ≤ j < i]）都有 #cf_span[aj = bj]，其中 #cf_span[|a|] 和 #cf_span[|b|] 分别表示字符串 #cf_span[a] 和 #cf_span[b] 的长度。"},{"iden":"examples","content":"输入\nahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n输出\nfatma\nmona\n\n输入\naba\n1\nlikes likes posted's post\n输出\nlikes\nposted"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ u \\in \\Sigma^* $ be your name, where $ \\Sigma $ is the set of lowercase Latin letters.  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of actions, with $ 1 \\leq n \\leq 100 $.  \nLet $ A = \\{ (x_i, y_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of actions, where each $ x_i, y_i \\in \\Sigma^* $ are distinct names (each of length 1 to 10), and $ u \\notin \\{x_i, y_i\\} $ for all $ i $, or $ u \\in \\{x_i, y_i\\} $ for some $ i $.\n\nLet $ V = \\{ v \\in \\Sigma^* \\mid \\exists i \\in \\{1, \\dots, n\\} \\text{ such that } v = x_i \\text{ or } v = y_i \\} \\setminus \\{u\\} $ be the set of distinct names (excluding yourself) appearing in the actions.\n\nFor each $ v \\in V $, define the priority factor $ p(v) \\in \\mathbb{Z}_{\\geq 0} $ as:  \n$$\np(v) = \\left| \\left\\{ i \\in \\{1, \\dots, n\\} \\mid \\{x_i, y_i\\} = \\{u, v\\} \\right\\} \\right|\n$$\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 100 $  \n2. Each name in $ A $ consists of 1 to 10 lowercase Latin letters.  \n3. All names in $ A $ are distinct strings (no duplicates within an action).  \n4. $ u $ appears in at least one action or none (priority factor may be zero).\n\n**Objective**  \nSort the set $ V $ by:  \n- Primary key: $ p(v) $ in descending order.  \n- Secondary key: lexicographical order (ascending) if $ p(v_1) = p(v_2) $.  \n\nOutput each name in $ V $ on a separate line in this sorted order.","simple_statement":null,"has_page_source":false}