405293: GYM101875 B Ugly Number
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
B. Ugly Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
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, 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.
Given an n-digit decimal number x, can you answer if it is ugly or not?
InputThe 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.
OutputOutput "Yes" if x is an ugly number and "No" otherwise.
ExamplesInput3Output
123
YesInput
4Output
2214
No