Chef has a sequence $A_1, A_2, \ldots, A_N$; each element of this sequence is either $0$ or $1$. Appy gave him a string $S$ with length $Q$ describing a sequence of queries. There are two types of queries:
- '!': right-shift the sequence $A$, i.e. replace $A$ by another sequence $B_1, B_2, \ldots, B_N$ satisfying $B_{i+1} = A_i$ for each valid $i$ and $B_1 = A_N$
- '?': find the length of the longest contiguous subsequence of $A$ with length $\le K$ such that each element of this subsequence is equal to $1$
Answer all queries of the second type.

-----Input-----
- The first line of the input contains three space-separated integers $N$, $Q$ and $K$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
- The third line contains a string with length $Q$ describing queries. Each character of this string is either '?', denoting a query of the second type, or '!', denoting a query of the first type.

-----Output-----
For each query of the second type, print a single line containing one integer — the length of the longest required subsequence.

-----Constraints-----
- $1 \le K \le N \le 10^5$
- $1 \le Q \le 3 \cdot 10^5$
- $0 \le A_i \le 1$ for each valid $i$
- $S$ contains only characters '?' and '!'

-----Subtasks-----
Subtask #1 (30 points):
- $1 \le N \le 10^3$
- $1 \le Q \le 3 \cdot 10^3$
Subtask #2 (70 points): original constraints 

-----Example Input-----
5 5 3
1 1 0 1 1
?!?!?    

-----Example Output-----
2
3
3

-----Explanation-----
- In the first query, there are two longest contiguous subsequences containing only $1$-s: $A_1, A_2$ and $A_4, A_5$. Each has length $2$.
- After the second query, the sequence $A$ is $[1, 1, 1, 0, 1]$.
- In the third query, the longest contiguous subsequence containing only $1$-s is $A_1, A_2, A_3$.
- After the fourth query, $A = [1, 1, 1, 1, 0]$.
- In the fifth query, the longest contiguous subsequence containing only $1$-s is $A_1, A_2, A_3, A_4$ with length $4$. However, we only want subsequences with lengths $\le K$. One of the longest such subsequences is $A_2, A_3, A_4$, with length $3$.

Difficulty: interview

Starter code:

Solutions:
n, q, k = map(int, input().split())
arr = list(map(int, input().split()))
query = list(input())
q_ = len(query)
c1 = query.count('?')
c = arr.count(0)
if c == n:
 for i in range(c1):
  print(0)
else:
 for i in range(q_):
  if (i!=0) and (query[i] == '?' and query[i-1] == '?'):
   print(max_c)
  elif query[i] == '?':
   max_c = cnt = 0
   for j in range(n):
    if (j != n - 1) and (arr[j] == 1 and arr[j + 1] == 1):
     cnt += 1
    else:
     max_c = max(max_c, cnt + 1)
     cnt = 0
    if k < max_c:
     max_c = k
     break
   print(max_c)
  elif query[i] == '!':
   temp = arr[n - 1]
   del arr[n - 1]
   arr.insert(0, temp)

n,q,k = map(int, input().split())
a = [int(x) for x in input().split()]
s = input()
m = 0
l = 0
for i in a:
 if i==1:
  m += 1
 else:
  m = 0
 if m>=k:
  l = k
  break
 elif m>l:
  l = m
for i in s:
 if i == '?':
  print(l)
 else:
  a.insert(0,a[n-1])
  a.pop()
  if a[0]!=0:
   m = 0
   l = 0
   for j in a:
    if j==1:
     m += 1
    else:
     m = 0
    if m>=k:
     l = k
     break
    elif m>l:
     l = m

# cook your dish here
import collections
n , q , k = map(int,input().split())
a = list(map(int,input().split()))
st = str(input())
de = collections.deque(a)
for f in range(q):
 if st[f]=='!':
  de.rotate(1)
 else:
  mi = 0
  prev = 0
  cnt = 0
  while 1:
   i = prev
   if de[i]==1:
    while de[i]==1:
     cnt+=1
     i+=1
     if i>n-1:
      break
   else:
    i+=1
   prev = i
   if cnt>mi:
    mi=cnt
   if prev>=n-1:
    break
   cnt = 0
  if mi<k:
   print(mi)
  else:
   print(k)

n,q,k = map(int,input().split())
l = list(map(str,input().split()))
s = input()
for x in s:
 if x=="!":
  temp = l[-1]
  l[1:] = l[:-1]
  l[0] = temp
  continue
 elif x=="?":
  s_new = "".join(l[:])
  l_new = s_new.split("0")
  l_new.sort()
  if len(l_new[-1])>=k:
   print(k)
  else:
   print(len(l_new[-1]))