{"problem":{"name":"D. Cycle String?","description":{"content":"Great wizard gave Alice and Bob a cycle string of length $2 dot.op n$, which has no repeated substrings of length $n$. In a cycle string, character $s_{i + 1}$ comes after $s_i$. Also, $s_1$ comes aft","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10239D"},"statements":[{"statement_type":"Markdown","content":"Great wizard gave Alice and Bob a cycle string of length $2 dot.op n$, which has no repeated substrings of length $n$. In a cycle string, character $s_{i + 1}$ comes after $s_i$. Also, $s_1$ comes after $s_{2 n}$. \n\nUnfortunately, evil gin shuffled all the symbols of the string. Help Alice and Bob restore the original string so that the above condition is satisfied.\n\nThe first line contains one string $s$ of length $2 dot.op n$ ($2 <= 2 dot.op n <= 1 thin 000 thin 000$) which consists only of the lowercase Latin letters.\n\nPrint \"_NO_\" (without quotes) to the first line if it is impossible to restore the string so that the condition is satisfied. Otherwise, in the first line print \"_YES_\" (without quotes).\n\nIn the second line print one string — the restored string.\n\nIf there are multiple answers, print any.\n\nIn the first example, substrings of the restored string are: \"_abbab_\", \"_bbabc_\", \"_babcb_\", \"_abcbc_\", \"_bcbcc_\", \"_cbccb_\", \"_bccba_\", \"_ccbab_\", \"_cbabb_\", \"_babba_\".\n\nNote that the first example does not contain repetitions, however it can be rewritten as another cycle with no repetitions. Thus, the solution is not unique — the given example is also a correct solution.\n\nIn the second example, it is impossible to restore the string so that no repetition exists.\n\nIn the third example, there is no need to change anything.\n\n## Input\n\nThe first line contains one string $s$ of length $2 dot.op n$ ($2 <= 2 dot.op n <= 1 thin 000 thin 000$) which consists only of the lowercase Latin letters.\n\n## Output\n\nPrint \"_NO_\" (without quotes) to the first line if it is impossible to restore the string so that the condition is satisfied. Otherwise, in the first line print \"_YES_\" (without quotes).In the second line print one string — the restored string.If there are multiple answers, print any.\n\n[samples]\n\n## Note\n\nIn the first example, substrings of the restored string are: \"_abbab_\", \"_bbabc_\", \"_babcb_\", \"_abcbc_\", \"_bcbcc_\", \"_cbccb_\", \"_bccba_\", \"_ccbab_\", \"_cbabb_\", \"_babba_\".Note that the first example does not contain repetitions, however it can be rewritten as another cycle with no repetitions. Thus, the solution is not unique — the given example is also a correct solution.In the second example, it is impossible to restore the string so that no repetition exists.In the third example, there is no need to change anything.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ x \\in \\mathbb{Z}^+ $ be the required amount of gold.  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of houses.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of positive integers representing gold in each house, indexed from 1 to $ n $.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq 1000 $  \n2. $ 1 \\leq x \\leq 10^6 $  \n3. $ 1 \\leq a_i \\leq 1000 $ for all $ i \\in \\{1, \\dots, n\\} $  \n\n**Objective**  \nFind the minimum distance $ d $ Bashar must walk, defined as the number of steps between the first and last house visited (i.e., if he visits houses from index $ i $ to $ j $, then $ d = |j - i| $), such that the sum of gold from a contiguous subarray $ \\sum_{k=i}^{j} a_k \\geq x $.  \n\nIf no such contiguous subarray exists, output $ -1 $.  \n\nFormally, compute:  \n$$\n\\min_{1 \\leq i \\leq j \\leq n} \\{ j - i \\mid \\sum_{k=i}^{j} a_k \\geq x \\}\n$$  \nIf the minimum does not exist, return $ -1 $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10239D","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}