There is a cyclic buffer of size nnn with readers from the 111-st position to the kkk-th position . Let aia_iai be the integer at the iii-th position of the buffer initially. What's more, a1,a2,,ana_1, a_2, cdots, a_na1,a2,,an form a permutation of nnn. We're going to visit all the integers from 111 to nnn in increasing order. An integer can be visited only when it is residing in positions with readers . In case that an integer cannot be visited, we can shift the whole buffer in either directions any number of times. If we shift the buffer to the left once, integers in the iii-th position will be moved to the -th position if i>1i > 1i>1, and integer in the 111-st position will be moved to the nnn-th position. If we shift the buffer to the right once, integers in the iii-th position will be moved to the (i+1)(i+1)-th position if i
There is a cyclic buffer of size nnn with readers from the 111-st position to the kkk-th position (both inclusive). Let aia_iai (1≤i≤n1 le i le n1≤i≤n) be the integer at the iii-th position of the buffer initially. What's more, a1,a2,⋯ ,ana_1, a_2, cdots, a_na1,a2,⋯,an form a permutation of nnn. We're going to visit all the integers from 111 to nnn (both inclusive) in increasing order. An integer can be visited only when it is residing in positions with readers (that is to say, when it is in the first kkk positions). In case that an integer cannot be visited, we can shift the whole buffer in either directions any number of times. If we shift the buffer to the left once, integers in the iii-th position will be moved to the (i−1)(i - 1)(i−1)-th position if i>1i > 1i>1, and integer in the 111-st position will be moved to the nnn-th position. If we shift the buffer to the right once, integers in the iii-th position will be moved to the (i+1)(i + 1)(i+1)-th position if i