#C2976. Beautiful Necklace
Beautiful Necklace
Beautiful Necklace
You are given a circular necklace represented as a string s
of length n
. The necklace is considered beautiful if there exists an integer l with (1 \leq l \leq \frac{n}{2}) and a substring (p = s[0:l]) such that when we consider the necklace's circular property (i.e. by concatenating s+s
), the number of non-overlapping occurrences of (p) is at least (2\cdot\left\lfloor \frac{n}{l} \right\rfloor). For example, for s = "abcabcabc"
, the necklace is beautiful, while for s = "abcdefgh"
it is not. Determine for each test case whether the given necklace is beautiful.
inputFormat
The input begins with an integer T
representing the number of test cases. Each of the next T
lines contains a single string representing a circular necklace.
outputFormat
For each test case, output a single line containing either YES
if the necklace is beautiful, or NO
otherwise.## sample
3
abcabcabc
aaaaa
abcdefgh
YES
YES
NO
</p>