{"problem":{"name":"A. Bark to Unlock","description":{"content":"As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phon","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF868A"},"statements":[{"statement_type":"Markdown","content":"As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.\n\nMu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark _n_ distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.\n\n## Input\n\nThe first line contains two lowercase English letters — the password on the phone.\n\nThe second line contains single integer _n_ (1 ≤ _n_ ≤ 100) — the number of words Kashtanka knows.\n\nThe next _n_ lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.\n\n## Output\n\nPrint \"_YES_\" if Kashtanka can bark several words in a line forming a string containing the password, and \"_NO_\" otherwise.\n\nYou can print each letter in arbitrary case (upper or lower).\n\n[samples]\n\n## Note\n\nIn the first example the password is \"_ya_\", and Kashtanka can bark \"_oy_\" and then \"_ah_\", and then \"_ha_\" to form the string \"_oyahha_\" which contains the password. So, the answer is \"_YES_\".\n\nIn the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark \"_ht_\" and then \"_tp_\" producing \"_http_\", but it doesn't contain the password \"_hp_\" as a substring.\n\nIn the third example the string \"_hahahaha_\" contains \"_ah_\" as a substring.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"随着技术的发展，制造商正在使解锁手机的过程尽可能用户友好。为了解锁其新手机，Arkady 的宠物狗 Mu-mu 只需叫出一次密码即可。手机将密码表示为一个由两个小写英文字母组成的字符串。\n\nMu-mu 的敌人 Kashtanka 想要解锁 Mu-mu 的手机以窃取一些敏感信息，但它只能叫出 #cf_span[n] 个不同的单词，每个单词均由两个小写英文字母组成。Kashtanka 想要连续叫出若干个单词（不一定互不相同），以形成一个包含密码作为子串的字符串。请判断是否可以通过这种方式解锁手机。\n\n第一行包含两个小写英文字母 —— 手机上的密码。\n\n第二行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100]) —— Kashtanka 知道的单词数量。\n\n接下来的 #cf_span[n] 行，每行包含两个小写英文字母，表示 Kashtanka 知道的单词。这些单词保证互不相同。\n\n如果 Kashtanka 能通过连续叫出若干个单词形成一个包含密码作为子串的字符串，则输出 \"_YES_\"；否则输出 \"_NO_\"。\n\n你可以以任意大小写形式输出每个字母。\n\n在第一个例子中，密码是 \"_ya_\"，Kashtanka 可以依次叫出 \"_oy_\"、\"_ah_\" 和 \"_ha_\"，形成字符串 \"_oyahha_\"，其中包含密码。因此答案是 \"_YES_\"。\n\n在第二个例子中，Kashtanka 无法生成包含密码的字符串。注意，它可以叫出 \"_ht_\" 然后 \"_tp_\" 形成 \"_http_\"，但该字符串并不包含密码 \"_hp_\" 作为子串。\n\n在第三个例子中，字符串 \"_hahahaha_\" 包含 \"_ah_\" 作为子串。\n\n## Input\n\n第一行包含两个小写英文字母 —— 手机上的密码。第二行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100]) —— Kashtanka 知道的单词数量。接下来的 #cf_span[n] 行，每行包含两个小写英文字母，表示 Kashtanka 知道的单词。这些单词保证互不相同。\n\n## Output\n\n如果 Kashtanka 能通过连续叫出若干个单词形成一个包含密码作为子串的字符串，则输出 \"_YES_\"；否则输出 \"_NO_\"。你可以以任意大小写形式输出每个字母。\n\n[samples]\n\n## Note\n\n在第一个例子中，密码是 \"_ya_\"，Kashtanka 可以依次叫出 \"_oy_\"、\"_ah_\" 和 \"_ha_\"，形成字符串 \"_oyahha_\"，其中包含密码。因此答案是 \"_YES_\"。在第二个例子中，Kashtanka 无法生成包含密码的字符串。注意，它可以叫出 \"_ht_\" 然后 \"_tp_\" 形成 \"_http_\"，但该字符串并不包含密码 \"_hp_\" 作为子串。在第三个例子中，字符串 \"_hahahaha_\" 包含 \"_ah_\" 作为子串。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ p = p_1 p_2 \\in \\{a,\\dots,z\\}^2 $ be the password.  \nLet $ W = \\{w_1, w_2, \\dots, w_n\\} $ be a set of $ n $ distinct words, where each $ w_i = w_{i,1} w_{i,2} \\in \\{a,\\dots,z\\}^2 $.  \n\n**Constraints**  \n$ 1 \\le n \\le 100 $\n\n**Objective**  \nDetermine whether there exists a finite sequence $ w_{i_1}, w_{i_2}, \\dots, w_{i_k} \\in W $ (with repetition allowed) such that the concatenated string $ w_{i_1} w_{i_2} \\cdots w_{i_k} $ contains $ p $ as a contiguous substring.  \n\nOutput \"YES\" if such a sequence exists, \"NO\" otherwise.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF868A","tags":["brute force","implementation","strings"],"sample_group":[["ya\n4\nah\noy\nto\nha","YES"],["hp\n2\nht\ntp","NO"],["ah\n1\nha","YES"]],"created_at":"2026-03-03 11:00:39"}}