Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for n in range(Q):
    A = [C[n] if i == B[n] else i for i in A]
    print(sum(A))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

A_new = {}
for a in A:
    if not a in A_new:
        A_new[a] = 1
    else:
        A_new[a] += 1

sum = 0
for i in range(0, 1):
    b = B[i]
    c = C[i]
    if b in A_new:
        n = A_new[b]
        A_new[b] = 0
        if c in A_new:
            A_new[c] += n
        else:
            A_new[c] = n
    key_list = A_new.keys()
    res = 0
    for k in key_list:
        res += A_new[k] * k
    print(res)
    sum = res


for i in range(1, Q):
    b = B[i]
    c = C[i]
    dif = 0
    if b in A_new:
        n = A_new[b]
        A_new[b] = 0
        if c in A_new:
            A_new[c] += n
        else:
            A_new[c] = n
        dif = c * n - b * n
    sum += dif
    print(sum)
### BUGGY CODE ###

#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

import copy
N = int(input())
S = input()

ct = 0

def dfs(index, RGB, indexs):
    global ct
    if RGB[S[index]] == 1:
        return
    else:
        RGB[S[index]] = 1
        indexs += [index]
        
        if len(indexs) == 2:

            for key, value in RGB.items():
                if value == 0:
                    ct += Counter(S[index+1:])[key]
                    h = indexs[1]+indexs[1] - indexs[0] +1
                    if 0 < h <= N and S[h-1] == key:
                        ct -= 1

                    return

        for i in range(index+1, N):
            dfs(i, RGB.copy(), copy.copy(indexs))

for i in range(N):
    dfs(i, {"R":0, "G":0, "B":0}, [])

print(ct)

### FIXED CODE ###

#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

import copy
N = int(input())
S = input()

# ct = 0

# def dfs(index, RGB, indexs):
#     global ct
#     if RGB[S[index]] == 1:
#         return
#     else:
#         RGB[S[index]] = 1
#         indexs += [index]
        
#         if len(indexs) == 2:

#             for key, value in RGB.items():
#                 if value == 0:
#                     ct += Counter(S[index+1:])[key]
#                     h = indexs[1]+indexs[1] - indexs[0] +1
#                     if 0 < h <= N and S[h-1] == key:
#                         ct -= 1

#                     return

#         for i in range(index+1, N):
#             dfs(i, RGB.copy(), copy.copy(indexs))

# for i in range(N):
#     dfs(i, {"R":0, "G":0, "B":0}, [])

# print(ct)

c = Counter(S)
al = c["R"] * c["G"] * c["B"]

for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k >= N: break
        if S[i] != S[k] and S[i] != S[j] and S[j] != S[k]:
            al -= 1
print(al)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1;d=[a[0]]
while not (b==1 or b==2) and (len(set(d))==len(d)):
  b=a[b-1]
  c+=1
  d.append(b)
if b==2:print(c)
else:print(-1)

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while b!=2 and c<=n:
  b=a[b-1]
  c+=1
if b==2:print(c)
else:print(-1)
### BUGGY CODE ###

N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for s in lis:
    flag = 0
    for i in range(N-2):
        if flag:break
        if S[i] == s[0]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]] and max(d[s[2]]) > j:
                        ans += 1
                        flag = 1
                    break
print(ans)

### FIXED CODE ###

N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for s in lis:
    if d[s[0]]:
        i = min(d[s[0]])
        if d[s[1]]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]]:
                        if max(d[s[2]]) > j:
                            ans += 1
                            break
                    break
        else:continue
    else:continue
                            
print(ans)
### BUGGY CODE ###

def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M,S = Ints()
from collections import defaultdict
Graph  = defaultdict(list)

for i in range(M):
    u,v,a,b = Ints()
    Graph[u].append([v,a,b])
    Graph[v].append([u,a,b])

City = [0]*N
for i in range(N):
    c,d = Ints()
    City[i] = [c,d]

import heapq
visited = [-1]*(N+1)
visited[0] = 1
que = []
# [time, nowhere, money, flag, visited]
heapq.heappush(que, [0, 1, S, 0])
ans = [-1]*(N+1)
#print(Graph)
while visited != [1]*(N+1):
    #print(que)
    time, nowhere, money, flag = heapq.heappop(que)
    #print(time, nowhere, money, flag)
    #route[nowhere] = 1
    if visited[nowhere] == -1:
        visited[nowhere] = 1
        ans[nowhere] = time
    if flag == 0:
        c,d = City[nowhere-1]
        if money >= 5000:
            heapq.heappush(que, [time+d, nowhere, money+c, 1])
        else:
            heapq.heappush(que, [time+d, nowhere, money+c, 0])
    for (to,a,b) in Graph[nowhere]:
        #if not to in route:
        if money-a >= 0:
          heapq.heappush(que, [time+b, to, money-a, flag])
            
for i in range(2,N+1):
    print(ans[i])

### FIXED CODE ###

def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M,S = Ints()
from collections import defaultdict
Graph  = defaultdict(list)

for i in range(M):
    u,v,a,b = Ints()
    Graph[u-1].append([v-1,a,b])
    Graph[v-1].append([u-1,a,b])

City = [0]*N
for i in range(N):
    c,d = Ints()
    City[i] = [c,d]

import heapq
que = []
# [time, nowhere, money, flag, visited]
heapq.heappush(que, [0, 0, min(S,5000)])
ans = [[10**16]*5001 for i in range(N)]
#Min = [[10**16]*5001 for i in range(N+1)]
#print(Graph)
while que != []:
    time, nowhere, money = heapq.heappop(que)
    #print('here',time,nowhere,money)
    if time <= ans[nowhere][money]:
        ans[nowhere][money] = time
        c,d = City[nowhere]
        if time+d < ans[nowhere][min(5000,money+c)]:
            ans[nowhere][min(5000,money+c)] = time+d
            #print('to',time+d, nowhere, min(5000,money+c))
            heapq.heappush(que, [time+d, nowhere, min(5000,money+c)])
        for (to,a,b) in Graph[nowhere]:
            if 0 <= money - a and time+b < ans[to][min(5000,money-a)]:
                ans[to][min(5000,money-a)] = time+b
                #print('to',time+b, to, min(5000,money-a))
                heapq.heappush(que, [time+b, to, min(5000,money-a)])

for i in range(1,N):
    print(min(ans[i]))
### BUGGY CODE ###

from collections import deque
N = int(input())
A = [deque(list(map(int, input().split()))) for _ in range(N)]

match = [0]*N

day = 0
while True:
    update = False
    done = [False] * N

    for a in range(N):
        if not A[a] or done[a]:
            continue
        b = A[a][0] - 1
        if not done[b] and A[b][0] - 1 == a:
            update = True
            done[a] = True
            done[b] = True
            A[a].popleft()
            A[b].popleft()

    if not update:
        break
    day += 1

ans = day
for a in A:
    if a:
        ans = -1
        break
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
pair = N * (N - 1) // 2
ptoi = dict()

i = 0
for x in range(1, N):
    for y in range(x + 1, N + 1):
        ptoi[(x, y)] = i
        ptoi[(y, x)] = i
        i += 1

edge = [[] for _ in range(pair)]
indeg = [0] * pair
for i in range(1, N+1):
    inp = list(map(int, input().split()))
    for s, t in zip(inp[:-1], inp[1:]):
        edge[ptoi[(i, s)]].append(ptoi[(i, t)])
        indeg[ptoi[(i, t)]] += 1


now = [i for i, d in enumerate(indeg) if d == 0]
day = 0
while now:
    nxt = []
    while now:
        s = now.pop()
        for t in edge[s]:
            if indeg[t] <= 0:
                continue
            indeg[t] -= 1
            if indeg[t] == 0:
                nxt.append(t)
    day += 1
    now = nxt

if all(i <= 0 for i in indeg):
    print(day)
else:
    print(-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(zip(B, A))
B, A = zip(*C)
D = sorted((a, i) for i, a in enumerate(A))
E, indices = zip(*D)
for e, b in zip(E, B):
  if e > b:
    print("No")
    exit()
S = set()
now = 0
while len(S) < n-1:
  S.add(now)
  if indices[now] in S:
    print("Yes")
    exit()
for i in range(n):
  if E[i+1] <= B[i]:
    print("Yes")
    exit()
print("No")

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(zip(B, A))
B, A = zip(*C)
D = sorted((a, i) for i, a in enumerate(A))
E, indices = zip(*D)
for e, b in zip(E, B):
  if e > b:
    print("No")
    exit()
S = {0}
now = 0
for _ in range(n-1):
  if indices[now] in S:
    print("Yes")
    exit()
  now = indices[now]
  S.add(now)
for i in range(n-1):
  if E[i+1] <= B[i]:
    print("Yes")
    exit()
print("No")
### BUGGY CODE ###

N,S=map(int,input().split())
ls=list(map(int,input().split()))
MOD=998244353
dp=[[1]+[0]*(S) for i in range(N+1)]
for i in range(N):
  for j in range(S+1):
    if ls[i]>j:
      dp[i+1][j]=dp[i][j]*2
      dp[i+1][j]%=MOD
    else:
      dp[i+1][j]=dp[i][j]*2+dp[i][j-ls[i]]
      dp[i+1][j]%=MOD
print(dp[N][S]) 

### FIXED CODE ###

N,S=map(int,input().split())
ls=list(map(int,input().split()))
MOD=998244353
dp=[[1]+[0]*S for i in range(N+1)]
for i in range(N):
  for j in range(S+1):    
      dp[i+1][j]=dp[i][j]*2%MOD
      if ls[i]<=j:
        dp[i+1][j]=(dp[i+1][j]+dp[i][j-ls[i]])%MOD
print(dp[N][S])
### BUGGY CODE ###

a,b = map(int,input().split())
su = a
for i in range(a+1,b+1):
    su ^= i
print(su)

### FIXED CODE ###

a,b = map(int,input().split())

def f(x):
    ans = [x,1,x+1,0]
    return ans[x%4]
print(f(a-1)^f(b))
### BUGGY CODE ###

N,S=map(int,input().split())
A=list(map(int,input().split()))
dp=[[0 for i in range(3001)] for j in range(3001)]
#dp[X][S]=最後の物がX番目以下のもので、総和をSにしてくれる物の総数
dp[0][0]=1

mod=998244353

for i in range(N):
    w=A[i]
    for j in range(S+1):
        if j>=w:
            dp[i+1][j]+=(2*dp[i][j]+dp[i][j-w])
        else:
            dp[i+1][j]+=2*dp[i][j]
        dp[i+1][j]%=mod

print(dp[N][S]%mod)


### FIXED CODE ###

N,S=map(int,input().split())
A=list(map(int,input().split()))
dp=[[0 for i in range(3001)] for j in range(3001)]
#dp[X][S]=最後の物がX番目以下のもので、総和をSにしてくれる物の総数
dp[0][0]=1

mod=998244353

for i in range(N):
    w=A[i]
    for j in range(S+1):
        if j>=w:
            dp[i+1][j]+=(2*dp[i][j]+dp[i][j-w])
        else:
            dp[i+1][j]+=2*dp[i][j]
        dp[i+1][j]%=mod

print(dp[N][S]%mod)
### BUGGY CODE ###


N, Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for _ in range(Q)]

length = len(lrs)
count = [0] * length
for i in range(len(S) - 1):
    if S[i] != 'A':
        continue
    if S[i+1] != 'C':
        continue
    for j in range(length):
        if lrs[j][0] <= i+1 and i < lrs[j][1] and i+1 != lrs[j][1]:
            count[j] += 1

for c in count:
    print(c)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for _ in range(Q)]

cs = [0] * N
s = 0
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        s += 1
    cs[i+1] = s 

for l, r in lrs:
    print(cs[r-1] - cs[l-1])
### BUGGY CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
    a,b = ip()
    graph[a].append(b)
    graph[b].append(a)

start = 1
nodes = list(graph.keys())
q = set()
d,parent,vis = {},{},{}
for i in nodes:
    d[i] = float('inf')
    parent[i] = -1
    vis[i] = 1
    q.add(i)
d[start] = 0

while len(q):
    mn = float('inf')
    for v in nodes:
        if d[v] < mn and vis[v]:
            mn = d[v]
            u = v
    q.remove(u)
    vis[u] = 0
    for v in graph[u]:
        if d[u]+1 < d[v] and vis[v]:
            d[v] = d[u] + 1
            parent[v] = u

if float('inf') in list(d.values()):
    print("No")
    exit()
print("Yes")
for i in range(2,n+1):
    print(parent[i])







### FIXED CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
    a,b = ip()
    graph[a].append(b)
    graph[b].append(a)

parent = {i:-1 for i in range(1,n+1)}
parent[1] = 0
q = [1]
while len(q):
    u = q.pop(0)
    for v in graph[u]:
        if parent[v] == -1:
            q.append(v)
            parent[v] = u

if -1 in list(parent.values()):
    print("No")
    exit()
print("Yes")
for i in range(2,n+1):
    print(parent[i])
### BUGGY CODE ###

import math
n, x, t = map(int, input().split())
i = 0
for _ in range(1<<30):
  if i >= 0:
    i += 1
  if i < 0:
    i -= 1
print(math.ceil(n / x) * t)

### FIXED CODE ###

import math


n, x, t = map(int, input().split())
print(math.ceil(n / x) * t)
### BUGGY CODE ###

N,X=map(int,input().split())
x=sorted(map(lambda x:int(x)-X if int(x)-X>0 else -(int(x)-X),input().split()))
for i in range(x[0]+1)[::-1]:
    if sum(map(lambda x:x%i,x))==0:
        print(i)
        break

### FIXED CODE ###

N,X=map(int,input().split())
x=sorted(map(lambda x:int(x)-X if int(x)-X>0 else -(int(x)-X),input().split()))
for i in range(x[0]+1)[::-1]:
    if x[0]%i:continue
    if sum(map(lambda x:x%i,x))==0:
        print(i)
        break
### BUGGY CODE ###

# encoding: utf-8
N, K = map(int, input().split())

ans = 0
pqr = 3
while pqr * K <= 6 * N:
    for r in filter(lambda x: pqr - x > x, range(pqr // 3, pqr)):
        pq = pqr - r
        if r * K > 2 * N: break
        for p in range(pq - r, (pq // 2) + 1):
            q = pq - p
            if p > q: break
            elif q * K > 2 * N: continue
            elif p * K > 2 * N: break
            elif (q + r - p) * K > 2 * N: continue
            elif (r + p - q) * K > 2 * N: break
            elif (q + r - p) * K % 2: continue
            elif (r + p - q) * K % 2: continue
            # print(p, q, r)
            if p == q == r: ans += 1
            elif p < q < r: ans += 6
            else: ans += 3
    pqr += 1
    
print(ans)

### FIXED CODE ###

# encoding: utf-8
N, K = map(int, input().split())

ans = 0
for a in range(1, N + 1):
    # find a (a, b, c)
    # maybe TLE
    # for b in range(1, N + 1):
    #     if (a + b) % K == 0: break
    # for c in range(1, K + 1):
    #     # c and c + K returns same result
    #     if (b + c) % K == 0 and (a + c) % K == 0: break
    #     else: continue
    # else:
    #     continue # next a
    if (K - 2 * a) % K: continue
    b = K - (a % K)
    c = K - b            
    # b_min, c_min
    b_min = K - (K - b) % K
    c_min = K - (K - c) % K
    # b_max, c_max
    b_max = N - (N - b_min) % K
    c_max = N - (N - c_min) % K
    # add
    # print(a, b, c, (b_min, b_max), (c_min, c_max))
    ans += ((b_max - b_min) // K + 1) * ((c_max - c_min) // K + 1)

print(ans)
### BUGGY CODE ###

n=int(input())

ans=0
for i in range(1,n+1):
  for j in range(1,n+1):
    if i%j == 0:
      ans+=i
      
print(ans)

### FIXED CODE ###

n=int(input())

ans=0
for i in range(1,n+1):
  num=n//i
  ans+=i*num*(num+1)//2
  
print(ans)
### BUGGY CODE ###

import math
a , b  , n = map(int , input().split())
ans = 0
for i in range(n+1):
    ans = max (ans , math.floor((a * i) / b) - a * math.floor(i / b))
print(ans)


### FIXED CODE ###

import math
a , b  , n = map(int , input().split())
ans = 0
if n < b - 1:
    x = n
    ans = math.floor(a * (x % b) / b)
else:
    x = b-1
    ans = math.floor(a * (x % b) / b)
print(ans)
### BUGGY CODE ###

import numpy as np

def extract(a, i):
  return (a>>(i+1) << i) | (a&((1<<i)-1))

def space(a, i):
  return ((a>>i) << (i+1)) | (a&((1<<i)-1))

def compose(n, a, b):
  if n==1:
    return [a, b]
  for i in range(n):
    if (a>>i&1) ^ (b>>i&1):
      x = i
      a_bool = (a>>i & 1) << i
      b_bool = a_bool ^ (1 << i)
      a_dash = extract(a, i)
      b_dash = extract(b, i)
      c = a_dash ^ 1
      break
  Q = np.array(compose(n-1, a_dash, c), dtype=np.int64)
  R = np.array(compose(n-1, c, b_dash), dtype=np.int64)
  n_Q = space(Q, x) | a_bool
  n_R = space(R, x) | b_bool
  return n_Q.tolist() + n_R.tolist()
  
n, a, b = map(int, input().split())
cnt = 0
c = a^b
for i in range(n):
  cnt += c>>i & 1
if cnt&1:
  print("YES")
  print(*compose(n, a, b))
else:
  print("NO")

### FIXED CODE ###

def extract(a, i):
  return (a>>(i+1) << i) | (a&((1<<i)-1))

def space(a, i):
  return ((a>>i) << (i+1)) | (a&((1<<i)-1))

def compose(n, a, b):
  if n==1:
    return [a, b]
  for i in range(n):
    if (a>>i&1) ^ (b>>i&1):
      x = i
      a_bool = (a>>i & 1) << i
      b_bool = a_bool ^ (1 << i)
      a_dash = extract(a, i)
      b_dash = extract(b, i)
      c = a_dash ^ 1
      break
  Q = compose(n-1, a_dash, c)
  R = compose(n-1, c, b_dash)
  n_Q = [space(i, x)|a_bool for i in Q]
  n_R = [space(i, x)|b_bool for i in R]
  return n_Q + n_R
  
n, a, b = map(int, input().split())
cnt = 0
c = a^b
for i in range(n):
  cnt += c>>i & 1
if cnt&1:
  print("YES")
  print(*compose(n, a, b))
else:
  print("NO")
### BUGGY CODE ###

def go():
    h, w, m = map(int, input().split(" "))
    r, c = {},{}
    d = []
    r_max,c_max=0,0

    for i in range(m):
        x, y = map(int, input().split(" "))
        if (x - 1) in r.keys():
            r[x - 1] += 1
        else:
            r[x - 1] = 1
        if r[x - 1] > r_max:
            r_max = r[x - 1]
        if (y - 1) in c.keys():
            c[y - 1] += 1
        else:
            c[y - 1] = 1
        if c[y - 1] > c_max:
            c_max = c[y - 1]
        d.append((x-1,y-1))

    if r_max==0:
        print(c_max)
    elif c_max==0:
        print(r_max)
    else:
        u=[]
        for i in c.keys():
            if c[i]==c_max:
                u.append(i)
        s=r_max+c_max-1
        for j in r.keys():
            if r[j]==r_max:
                for k in u:
                    if (j,k) not in d:
                        s+=1
                        print(s)
                        return
        print(s)

go()

### FIXED CODE ###

h,w,m= map(int,input().split(" "))
ys, xs=[0 for i in range(h)],[0 for j in range(w)]
ms=set()
for i in range(m):
    y,x= map(lambda x: int(x)-1,input().split(" "))
    ys[y]+=1
    xs[x]+=1
    ms.add((y,x))
y_max,x_max= max(ys),max(xs)
largest_ys, largest_xs=[],[]
for i in range(h):
    if ys[i]==y_max:
        largest_ys.append(i)
for i in range(w):
    if xs[i]==x_max:
        largest_xs.append(i)
ans=y_max+x_max-1
for i in largest_ys:
    for j in largest_xs:
        if (i,j) not in ms:
            print(ans+1)
            exit()
print(ans)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
S = input()

flg = [S[0]]
count = []
cnt = 1
tmp = S[0]

for x in S[1:]:
	if x == tmp:
		cnt += 1
	else:
		tmp = x
		flg.append(tmp)
		count.append(cnt)
		cnt = 1
count.append(cnt)

ans = 0
for i in range(len(flg)):
	if flg[i] == "1":
		ans = max(ans, sum(count[i:i+2*K+1]))
	else:
		ans = max(ans, sum(count[i:i+2*K]))

print(ans)



### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
#INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
S = [int(s) for s in input()] + [1]

r = -1
ans = 0
cnt = 0
used = [0]*(N+1)

for l in range(N):
	if S[l] + S[l-1] == 0:
		continue
	while r < N and used[r] - used[l-1] <= K:
		r += 1
		if S[r-1] == 1 and S[r] == 0:
			used[r] = used[r-1] + 1
		else:
			used[r] = used[r-1]
	ans = max(ans, r-l)

print(ans)
### BUGGY CODE ###

k,s=map(int,input().split())
cnt=0
for i in range(k+1):
    if s/k==3 :
        cnt=1
        break
    for j in range(k+1):
        for k in range(k+1):
            sum=i+j+k
            if sum==s:
                cnt+=1
print(cnt)

### FIXED CODE ###

k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
          cnt+=1
print(cnt)
### BUGGY CODE ###

s = str(input())
Q = int(input())
front = 1
for i in range(Q):
    q = list(map(str, input().split()))
    if q[0] == "1":
        front *= -1
    else:
        if q[1] == "1":
            if front == 1:
                s = q[2] + s
            else:
                s = s + q[2]             
        else:
            if front == 1:
                s = s + q[2]
            else:
                s = q[2] + s

if front == -1:
    s = s[::-1]
print(s)

### FIXED CODE ###

s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)