{"problem":{"name":"D. Restoration of string","description":{"content":"A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not n","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF886D"},"statements":[{"statement_type":"Markdown","content":"A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.\n\nYou are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Restore the non-empty good string with minimum length. If several such strings exist, restore lexicographically minimum string. If there are no good strings, print \"_NO_\" (without quotes).\n\nA substring of a string is a contiguous subsequence of letters in the string. For example, \"_ab_\", \"_c_\", \"_abc_\" are substrings of string \"_abc_\", while \"_ac_\" is not a substring of that string.\n\nThe number of occurrences of a substring in a string is the number of starting positions in the string where the substring occurs. These occurrences could overlap.\n\nString _a_ is lexicographically smaller than string _b_, if _a_ is a prefix of _b_, or _a_ has a smaller letter at the first position where _a_ and _b_ differ.\n\n## Input\n\nThe first line contains integer _n_ (1 ≤ _n_ ≤ 105) — the number of strings in the set.\n\nEach of the next _n_ lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.\n\nThe total length of the strings doesn't exceed 105.\n\n## Output\n\nPrint the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print \"_NO_\" (without quotes) if there are no good strings.\n\n[samples]\n\n## Note\n\nOne can show that in the first sample only two good strings with minimum length exist: \"_cfmailru_\" and \"_mailrucf_\". The first string is lexicographically minimum.","is_translate":false,"language":"English"}],"meta":{"iden":"CF886D","tags":["constructive algorithms","graphs","implementation"],"sample_group":[["4\nmail\nai\nlru\ncf","cfmailru"],["3\nkek\npreceq\ncheburek","NO"]],"created_at":"2026-03-03 11:00:39"}}