Jack and Daniel are friends.  They want to encrypt their conversations so that they can save themselves from interception by a detective agency so they invent a new cipher.  

Every message is encoded to its binary representation. Then it is written down $\boldsymbol{\mbox{k}}$ times, shifted by $0,1,\cdots,k-1$ bits. Each of the columns is XORed together to get the final encoded string.

If $b=1001011$ and $k=4$ it looks like so:  

1001011     shift 0 
01001011    shift 1
001001011   shift 2
0001001011  shift 3
----------
1110101001  <- XORed/encoded string s

Now we have to decode the message.  We know that $k=4$.  The first digit in $s=1$ so our output string is going to start with $1$.  The next two digits are also $1$, so they must have been XORed with $0$.  We know the first digit of our $4^{th}$ shifted string is a $\mbox{I}$ as well.  Since the $4^{th}$ digit of $\boldsymbol{\mathrm{~S~}}$ is $0$, we XOR that with our $1$ and now know there is a $1$ in the $4^{th}$ position of the original string.  Continue with that logic until the end.

Then the encoded message $\boldsymbol{\mathrm{~S~}}$ and the key $\boldsymbol{\mbox{k}}$ are sent to Daniel.   

Jack is using this encoding algorithm and asks Daniel to implement a decoding algorithm. 
Can you help Daniel implement this?  

Function Description  

Complete the cipher function in the editor below.  It should return the decoded string.  

cipher has the following parameter(s):  

k: an integer that represents the number of times the string is shifted 
s: an encoded string of binary digits

Input Format

The first line contains two integers $n$ and $\boldsymbol{\mbox{k}}$, the length of the original decoded string and the number of shifts. 

The second line contains the encoded string $\boldsymbol{\mathrm{~S~}}$ consisting of $n+k-1$ ones and zeros.  

Constraints

$1\leq n\leq10^{6}$ 

$1\leq k\leq10^6$ 

$|s|=n+k-1$ 

It is guaranteed that $\boldsymbol{\mathrm{~S~}}$ is valid.  

Output Format

Return the decoded message of length $n$, consisting of ones and zeros.  

Sample Input 0
7 4
1110100110

Sample Output 0
1001010

Explanation 0
1001010
 1001010
  1001010
   1001010
----------
1110100110

Sample Input 1
6 2
1110001

Sample Output 1
101111

Explanation 1
101111
 101111
-------
1110001

Sample Input 2
10 3
1110011011

Sample Output 2
10000101

Explanation 2

10000101
010000101

0010000101

1110011011

Difficulty: MEDIUM

Solutions:
(n, k) = [int(i) for i in input().split(' ')]
s = input()
curVal = 0
s = [ord(c) - 48 for c in s]
out = [s[0]]
curVal = s[0]
for i in range(1, len(s) - k + 1):
	if i >= k:
		curVal ^= out[i - k]
	newVal = curVal ^ s[i]
	out.append(newVal)
	curVal ^= newVal
print(''.join([str(i) for i in out]))


import itertools, operator as op, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().strip()))
(A, B) = ([S[0]], [S[0]])
for i in range(1, len(S) - K + 1):
	x = A[-1] ^ S[i]
	B.append(A[-K] ^ x if len(A) >= K else x)
	A.append(A[-1] ^ B[-1])
print(''.join(map(str, B)))


def decypher(encoded, K):
	size = len(encoded) - K + 1
	ans = encoded[0]
	tmp = int(encoded[0])
	for x in range(1, size):
		c = tmp ^ int(encoded[x])
		ans += str(c)
		tmp ^= c
		if x >= K - 1:
			tmp ^= int(ans[x - K + 1])
	print(ans)
(N, K) = map(int, input().split())
S = input()
decypher(S, K)


import itertools, operator as op, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().strip()))
(A, B) = ([S[0]], [S[0]])
for i in range(1, len(S) - K + 1):
	x = A[-1] ^ S[i]
	B.append(A[-K] ^ x if len(A) >= K else x)
	A.append(A[-1] ^ B[-1])
print(''.join(map(str, B)))


import itertools, operator as op, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().strip()))
(A, B) = ([S[0]], [S[0]])
for i in range(1, len(S) - K + 1):
	x = A[-1] ^ S[i]
	B.append(A[-K] ^ x if len(A) >= K else x)
	A.append(A[-1] ^ B[-1])
print(''.join(map(str, B)))


import itertools, operator as op, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().strip()))
(A, B) = ([S[0]], [S[0]])
for i in range(1, len(S) - K + 1):
	x = A[-1] ^ S[i]
	B.append(A[-K] ^ x if len(A) >= K else x)
	A.append(A[-1] ^ B[-1])
print(''.join(map(str, B)))


import itertools, operator as op, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().strip()))
(A, B) = ([S[0]], [S[0]])
for i in range(1, len(S) - K + 1):
	x = A[-1] ^ S[i]
	B.append(A[-K] ^ x if len(A) >= K else x)
	A.append(A[-1] ^ B[-1])
print(''.join(map(str, B)))


import itertools, operator as op, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().strip()))
(A, B) = ([S[0]], [S[0]])
for i in range(1, len(S) - K + 1):
	x = A[-1] ^ S[i]
	B.append(A[-K] ^ x if len(A) >= K else x)
	A.append(A[-1] ^ B[-1])
print(''.join(map(str, B)))


l = list(map(lambda s: int(s), input().split(' ')))
n = l[0]
k = l[1]
s = input()
res = s[0]
start = 0
end = 1
mask = int(res[0])
while end < len(s) - k + 1 and end - start < k:
	tmp = int(s[end]) ^ mask
	mask = mask ^ tmp
	end += 1
	res = res + str(tmp)
for pos in range(end, len(s) - k + 1):
	mask = mask ^ int(res[start])
	start += 1
	tmp = int(s[pos]) ^ mask
	mask = mask ^ tmp
	res = res + str(tmp)
print(res)


(n, k) = [int(i) for i in input().split()]
s = input()
no1 = 0
ans = s[0]
if s[0] == '1':
	no1 = 1
j = 0
for i in range(1, len(s) - k + 1):
	if no1 % 2 == 0:
		if s[i] == '1':
			ans += '1'
			no1 += 1
		else:
			ans += '0'
	elif s[i] == '1':
		ans += '0'
	else:
		ans += '1'
		no1 += 1
	if i - j == k - 1:
		if ans[j] == '1':
			no1 -= 1
		j += 1
print(ans)


(N, K) = map(int, input().split())
ans = [0 for x in range(K - 1)]
S = list(map(int, input()))
S_count = K - 1
t = 0
for n in S:
	temp = n
	t = t ^ ans[S_count - K] ^ ans[S_count - 1]
	temp = temp ^ t
	ans.append(temp)
	S_count += 1
K = K - 1
ans = ans[K:0 - K]
for i in ans:
	print(i, end='')