You are given an array.
An anonymous informant has told you that the arraywas obtained as follows: initially, there existed an array , after which the following two-component operation was performed times:
- A fixed point of the array was chosen.
- Then, the array was cyclically shifted to the left exactly times.
As a result ofsuch operations, the array was obtained. You want to check if the words of the anonymous informant can be true or if they are guaranteed to be false.
A number is called a fixed point of the array if and .
A cyclic left shift of the array is the array .
Each test contains multiple test cases. The first line contains an integer( ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers( , ) — the length of the array and the number of operations performed.
The second line of each test case containsintegers ( ) — the elements of the array .
It is guaranteed that the sum of the values offor all test cases does not exceed .
For each test case, output “Yes” if the words of the anonymous informant can be true, and “No” if they are guaranteed to be false.
Yes Yes No Yes Yes No
In the first test case, the arraycould be equal to . In the first operation, a fixed point was chosen, and after left shifts, the array became . In the second operation, a fixed point was chosen, and after left shifts, the array became . In the third operation, a fixed point was chosen again, and after left shifts, the array became , which is equal to the array .
In the second test case, the arraycould be equal to . After the operation with a fixed point , the array became . Then, after the operation with a fixed point , the array returned to its initial state . These same operations (with , and ) were repeated times. So, after operations, the array returned to .
In the third test case, it can be shown that there is no solution.
def can_be_true(n, k, b):
if k % n != 0:
for i in range(n):
if b[i] == b[(i – k // n) % n]:
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
b = list(map(int, input().split()))
result = can_be_true(n, k, b)