{"problem":{"name":"B. Ugly Number","description":{"content":"A k-cyclic shift of an integer x is a function that removes the last k digits of x and inserts them in its beginning. For example, the k-cyclic shifts of 123 are 312 for k = 1 and 231 for k = 2. Teo,","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10187B"},"statements":[{"statement_type":"Markdown","content":"A k-cyclic shift of an integer x is a function that removes the last k digits of x and inserts them in its beginning. For example, the k-cyclic shifts of 123 are 312 for k = 1 and 231 for k = 2.\n\nTeo, a kid from Canada, learned from his Canadian friends this definition of ugly numbers: a number is ugly if, and only if every one of its k-cyclic shifts returns a number greater than or equal to it.\n\nGiven an n-digit decimal number x, can you answer if it is ugly or not?\n\nThe first line of the input contains a single integer n (1 ≤ n ≤ 5 × 105), indicating the number of digits of the number.\n\nThe next line contains an n-digit decimal number, indicating the value of x.\n\nOutput \"Yes\" if x is an ugly number and \"No\" otherwise.\n\n## Input\n\nThe first line of the input contains a single integer n (1 ≤ n ≤ 5 × 105), indicating the number of digits of the number.The next line contains an n-digit decimal number, indicating the value of x.\n\n## Output\n\nOutput \"Yes\" if x is an ugly number and \"No\" otherwise.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the number of verses.  \nLet $ L = (\\ell_1, \\ell_2, \\dots, \\ell_N) $ be a sequence of positive integers representing verse sizes.  \n\nFor $ K \\in \\mathbb{Z} $, $ K > 1 $, define the remainder distribution:  \n$ r_K(i) = \\left| \\left\\{ j \\in \\{1, \\dots, N\\} \\mid \\ell_j \\equiv i \\pmod{K} \\right\\} \\right| $ for $ i = 0, 1, \\dots, K-1 $.  \n\nThe poem is $ K $-elegant if:  \n1. $ K > 1 $,  \n2. $ K \\mid N $,  \n3. $ r_K(i) = \\frac{N}{K} $ for all $ i \\in \\{0, 1, \\dots, K-1\\} $.  \n\n**Objective**  \nFind the smallest integer $ K > 1 $ such that the poem is $ K $-elegant. If no such $ K $ exists, output $-1$.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10187B","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}