Spaces:
Sleeping
Sleeping
You are given a binary string $$$s$$$ of length $$$n$$$, consisting of zeros and ones. You can perform the following operation exactly once: Choose an integer $$$p$$$ ($$$1 \le p \le n$$$). Reverse the substring $$$s_1 s_2 \ldots s_p$$$. After this step, the string $$$s_1 s_2 \ldots s_n$$$ will become $$$s_p s_{p-1} \ldots s_1 s_{p+1} s_{p+2} \ldots s_n$$$. Then, perform a cyclic shift of the string $$$s$$$ to the left $$$p$$$ times. After this step, the initial string $$$s_1s_2 \ldots s_n$$$ will become $$$s_{p+1}s_{p+2} \ldots s_n s_p s_{p-1} \ldots s_1$$$. For example, if you apply the operation to the string 110001100110 with $$$p=3$$$, after the second step, the string will become 011001100110, and after the third step, it will become 001100110011.A string $$$s$$$ is called $$$k$$$-proper if two conditions are met: $$$s_1=s_2=\ldots=s_k$$$; $$$s_{i+k} \neq s_i$$$ for any $$$i$$$ ($$$1 \le i \le n - k$$$). For example, with $$$k=3$$$, the strings 000, 111000111, and 111000 are $$$k$$$-proper, while the strings 000000, 001100, and 1110000 are not.You are given an integer $$$k$$$, which is a divisor of $$$n$$$. Find an integer $$$p$$$ ($$$1 \le p \le n$$$) such that after performing the operation, the string $$$s$$$ becomes $$$k$$$-proper, or determine that it is impossible. Note that if the string is initially $$$k$$$-proper, you still need to apply exactly one operation to it. |