Harryxun/stf_run huggingface dataset:
import sys

N,K = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

P = []
M = []
Ans = []
p = 0
m = 0

for i in range(N):
    if 0 <= A[i]:
        P.append(A[i])
    else:
        M.append(A[i])

M.sort()

if K % 2 == 1 and len(P) != 0:
    Ans.append(P[p])
    p += 1
elif K % 2 == 1 and len(P) == 0:
    M.sort(reverse=True)
elif len(M) == 0:
    answer = 1
    for i in range(K):
        answer = (answer * P[i]) % 1000000007

    print(answer)
    sys.exit()

while len(Ans) < K:

    #Mのストックがもうない時
    if m+1 >= len(M) and p < len(P):
        Ans.append(P[p])
        if len(Ans) == K:
            break
        Ans.append(P[p + 1])
        p += 2
    elif p+1 >= len(P) and m < len(M):
        Ans.append(M[m])
        if len(Ans) == K:
            break
        Ans.append(M[m + 1])
        m += 2
    elif m >= len(M) and p < len(P):
        Ans.append(P[p])
        p += 1
    elif p >= len(P) and m < len(M):
        Ans.append(M[m])
        m += 1
    else:
        if P[p]*P[p+1] < M[m]*M[m+1]:
            Ans.append(M[m])
            Ans.append(M[m+1])
            m += 2
        else:
            Ans.append(P[p])
            Ans.append(P[p + 1])
            p += 2

answer = 1
for i in range(K):
    answer = (answer * Ans[i]) % 1000000007

print(answer)


### FIXED CODE ###

import sys

N,K = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

P = []
M = []
Ans = []
p = 0
m = 0

for i in range(N):
    if 0 <= A[i]:
        P.append(A[i])
    else:
        M.append(A[i])

M.sort()

if K % 2 == 1 and len(P) != 0:
    Ans.append(P[p])
    p += 1
elif K % 2 == 1 and len(P) == 0:
    M.sort(reverse=True)
elif len(M) == 0:
    answer = 1
    for i in range(K):
        answer = (answer * P[i]) % 1000000007

    print(answer)
    sys.exit()

while len(Ans) < K:

    #Mのストックがもうない時
    if m+1 >= len(M) and p < len(P):
        Ans.append(P[p])
        if len(Ans) == K:
            break
        if p + 1 < len(P):
            Ans.append(P[p + 1])
            p += 2
        else:
            p += 1
        
    elif p+1 >= len(P) and m < len(M):
        Ans.append(M[m])
        if len(Ans) == K:
            break
        Ans.append(M[m + 1])
        m += 2
    elif m >= len(M) and p < len(P):
        Ans.append(P[p])
        p += 1
    elif p >= len(P) and m < len(M):
        Ans.append(M[m])
        m += 1
    else:
        if P[p]*P[p+1] < M[m]*M[m+1]:
            Ans.append(M[m])
            Ans.append(M[m+1])
            m += 2
        else:
            Ans.append(P[p])
            Ans.append(P[p + 1])
            p += 2

answer = 1
for i in range(K):
    answer = (answer * Ans[i]) % 1000000007

print(answer)
s=str(input())
s=list(s)
if s[0]!="A":
  s.insert(0,"A")
if len(s)>=4:
  if s[4]!="A":
    s.insert(4,"A")
if len(s)>=6:
  if s[6]!="A":
    s.insert(6,"A")
if s[len(s)-1]!="A":
  s.append("A")
if "".join(s)=="AKIHABARA":
  print("YES")
else:
  print("NO")

### FIXED CODE ###

s=str(input())
s=list(s)
if s[0]!="A":
  s.insert(0,"A")
if len(s)>=5:
  if s[4]!="A":
    s.insert(4,"A")
if len(s)>=7:
  if s[6]!="A":
    s.insert(6,"A")
if s[len(s)-1]!="A":
  s.append("A")
if "".join(s)=="AKIHABARA":
  print("YES")
else:
  print("NO")
s=int(input())
num=[]
while s > 0:
    num.append(s % 100)
    s //= 100

num.reverse()

if num[0]<=12 and num[0]>0:
    if num[1]<=12 and num[1]>0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if num[1]<=12 and num[1]>0:
        print("YYMM")
    else:
        print("NA")

### FIXED CODE ###

s=int(input())
num=[]
while s > 0:
    num.append(s % 100)
    s //= 100

if len(num)==0:
    num.append(0)
if len(num)==1:
    num.append(0)
num.reverse()

if num[0]<=12 and num[0]>0:
    if num[1]<=12 and num[1]>0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if num[1]<=12 and num[1]>0:
        print("YYMM")
    else:
        print("NA")
while 1:
    a, b = sorted(map(int, raw_input().split()))
    if a + b = 0:
        break
    else:
        print a, b

### FIXED CODE ###

while 1:
    a, b = sorted(map(int, raw_input().split()))
    if a + b == 0:
        break
    else:
        print a, b
import sys

#+++++
		
def main():
	n, k = map(int, input().split())
	aal = list(map(int, input().split()))
	
	sss = [0]*(n+1)
	si=0
	for i, a in enumerate(aal):
		si+=a-1
		sss[i+1]=si%k
	
	count=0
	mkl=[0]*k
	for j in range(n+1):
		sj=sss[j]
		if j-k >= 0:
			#pa((j-k, sss[j-k]))
			mkl[sss[j-k]]-=1
		#pa((mkl,sj))
		count += mkl[sj]
		mkl[sj] += 1
			
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

### FIXED CODE ###

import sys
from collections import defaultdict

#+++++
		
def main():
	n, k = map(int, input().split())
	aal = list(map(int, input().split()))
	
	sss = [0]*(n+1)
	si=0
	for i, a in enumerate(aal):
		si+=a-1
		sss[i+1]=si%k
	
	count=0
	mkl_dict=defaultdict(lambda :0)
	for j in range(n+1):
		sj=sss[j]
		if j-k >= 0:
			mkl_dict[sss[j-k]]-=1
		count += mkl_dict[sj]
		mkl_dict[sj] += 1
			
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
a,b,c=map(float,input().split())
from math import sqrt
def fl(x):
    digits = 9
    form = '%.'+str(digits-1)+'e'
    return float((form % x))
def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m
    
    return f(int(sqrt(n) * (1 + 1e-10)))
if float(fl(a)*fl(b))<int_sqrt2(float(fl(fl(c-a)-b))/float(4)):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

if c-a-b <= 0:
    print("No")
elif 4*a*b < (c-a-b)**2:
    print("Yes")
else:
    print("No")
n, k = [int(c) for c in input().split()]
h = [int(input()) for _ in range(n)]

h.sort()

min_d = 100000
for i in range(n-k+1):
    d = h[i+k] - h[i]
    if d < min_d:
        min_d = d

print(min_d)

### FIXED CODE ###

n, k = [int(c) for c in input().split()]
h = [int(input()) for _ in range(n)]

h.sort()

min_d = 1000000000
for i in range(n-k+1):
    d = h[i+k-1] - h[i]
    if d < min_d:
        min_d = d

print(min_d)
N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
  dp[i] = min(dp[i-1] + abs(h[i] - h[i-1], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[N-1])

### FIXED CODE ###

N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
  dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
  dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[N-1])
A,B=int(input())
if A>=13:
  print(B)
elif 6<=A<=12:
  print(B//2)
else:
  print(0)

### FIXED CODE ###

A,B=list(map(int,input().split()))
if A>=13:
  print(B)
elif 6<=A<=12:
  print(B//2)
else:
  print(0)
while True:
    N = int(raw_input())
    if N == 0:
        break
     
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])
    print ''

### FIXED CODE ###

N = input()
while True:
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        dic[lis[0]] = [3*int(lis[1])+int(lis[3]), N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[1][0], x[1][1]), reverse=True):
        print '%s,%s' % (k, v[0])

    N = input()
    if N == 0: break
    print
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a,b=map(int,input(),split())
print(lcm(a, b))

### FIXED CODE ###

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a,b=map(int,input().split())
print(lcm(a, b))
H, W, M = map(int, input().split())
h_list = [0 for _ in range(H + 1)]
w_list = [0 for _ in range(W + 1)]
bomb = set()
for _ in range(M):
    h, w = map(int, input().split())
    h_list[h] += 1
    w_list[w] += 1
    bomb.add([h, w])
h_max = max(h_list)
w_max = max(w_list)
h_index = []
w_index = []
for i in range(H + 1):
    if h_list[i] == h_max:
        h_index.append(i)
for i in range(W + 1):
    if w_list[i] == w_max:
        w_index.append(i)
tmp = -1        
for h in h_index:
    for w in w_index:
        if [h, w] not in bomb:
            tmp = 0
            break
print(h_max + w_max + tmp)

### FIXED CODE ###

H, W, M = map(int, input().split())
h_list = [0 for _ in range(H + 1)]
w_list = [0 for _ in range(W + 1)]
bomb = set([])
for _ in range(M):
    h, w = map(int, input().split())
    h_list[h] += 1
    w_list[w] += 1
    bomb.add((h, w))
h_max = max(h_list)
w_max = max(w_list)
h_index = []
w_index = []
for i in range(H + 1):
    if h_list[i] == h_max:
        h_index.append(i)
for i in range(W + 1):
    if w_list[i] == w_max:
        w_index.append(i)
tmp = -1        
for h in h_index:
    for w in w_index:
        if (h, w) not in bomb:
            tmp = 0
            break
print(h_max + w_max + tmp)
from functools import lru_cache

N = int(input())
h = list(map(int, input().split()))

@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

print(recur(0))

# dp = [0]*(N + 1)
# for i in range(N):


### FIXED CODE ###

from functools import lru_cache
import sys

sys.setrecursionlimit(10**6)

N = int(input())
h = list(map(int, input().split()))

@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

print(recur(0))

# dp = [0]*(N + 1)
# for i in range(N):
N,M = list(map(int,input().split()))
path = [[False,False] for i in range(N)]
flag=False
for i in range(M):
    a,b = list(map(int,input().split()))
    if a=N-1:
        if path[b-1][0]:
            flag=True
            break
        path[b-1][1]=True
    if a=0:
        if path[b-1][1]:
            flag=True
            break
        path[b-1][0]=True
    if b=N-1:
        if path[a-1][0]:
            flag=True
            break
        path[a-1][1]=True
    if b=0:
        if path[a-1][1]:
            flag=True
            break
        path[a-1][0]=True

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

N,M = list(map(int,input().split()))
path = [[False,False] for i in range(N)]
flag=False
for i in range(M):
    a,b = list(map(int,input().split()))
    if a==N:
        if path[b-1][0]:
            flag=True
            
        path[b-1][1]=True
    if a==1:
        if path[b-1][1]:
            flag=True
            
        path[b-1][0]=True
    if b==N:
        if path[a-1][0]:
            flag=True
            
        path[a-1][1]=True
    if b==1:
        if path[a-1][1]:
            flag=True
            
        path[a-1][0]=True

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
n = int(input())
a = [int(x) for x in input().split()]
for i in range(1,n+1):
    print(a.count[i])

### FIXED CODE ###

N = int(input())
K = [0]*N
A = [int(i) for i in input().split()]

for i in range(N-1):
    K[A[i]-1] += 1
for i in K:
    print(i)
import sys

n,m=map(int,input().split())
ans=[0]*(m+1)
output=0

for i in range(n):
    k=list(map(int,input().split()))
    for j in range(1,len(k)):
        ans[j]+=1

for i in ans:
    if ans[i]==n:
        output+=1

print(output)

### FIXED CODE ###

import sys

n,m=map(int,input().split())
ans=[0]*(m+1)
output=0

for i in range(n):
    k=list(map(int,input().split()))
    for j in range(1,len(k)):
        ans[k[j]]+=1

for i in ans:
    if i==n:
        output+=1

print(output)
n, k = input().split()
n = int(n)
k = int(k)

MOD = 1000000007

g = []
for i in range(n):
    g.append([])

for i in range(n-1):
    a, b = input().split()
    a = int(a)-1
    b = int(b)-1
    g[a].append(b)
    g[b].append(a)


used = [False for i in range(n)]


def dfs(v):
    used[v] = True
    ret = 1
    num = k-2
    for to in g[v]:
        if not used[to]:
            ret *= num * dfs(to) % MOD
            ret %= MOD
            num -= 1
            if num < 0:
                num = 0
    return ret

ans = k
num = k-1
used[0] = True
for to in g[0]:
    if not used[to]:
        ans *= num * dfs(to) % MOD
        ans %= MOD
        num -= 1
        if num < 0:
            num = 0

print(ans)


### FIXED CODE ###

from collections import deque

n, k = map(int, input().split())

MOD = 1000000007

g = [[] * 1 for i in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

d = [-1 for i in range(n)]

q = deque([])
num = k-1
d[0] = k
for to in g[0]:
    if d[to] == -1:
        d[to] = num
        num -= 1
        if num < 0:
            num = 0
        q.append(to)

while q:
    v = q.popleft()
    num = k-2
    for to in g[v]:
        if d[to] == -1:
            d[to] = num
            num -= 1
            if num < 0:
                num = 0
            q.append(to)

ans = 1
for i in d:
    ans *= i
    ans %= MOD

print(ans)
import numpy as np
import math

def solve():
    n,w = map(int,input().split())
    w_list,v_list = [0]*n,[0]*n
    for i in range(n):
        w_list[i],v_list[i] = map(int,input().split())
    dp = [[0]*(w+5) for i in range(n+5)]
    for i in range(n):
        for j in range(w+1):
            if j >= w_list[i]:
                dp[i][j] = max(
                    dp[i-1][j],
                    dp[i-1][j-w_list[i]]+v_list[i])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp)
    print(dp[n-1][w])
    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###

def hoge():
  dp = [0] * (n + 5)
  dp[1] = abs(h_list[1] - h_list[0])
  for i in range(2, n):
    dp[i] = min(
      dp[i - 2] + abs(h_list[i] - h_list[i - 2]),
      dp[i - 1] + abs(h_list[i] - h_list[i - 1])
      )
  return dp[n - 1]

def solve():
  global n, h_list
  n = int(input())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()
s = input()
K = int(input())

sub = set()
for i in range(1, len(s) + 1):
    for k in range(int(len(s) / i) + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub][1:])[K])


### FIXED CODE ###

s = input()
K = int(input())

sub = set()
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K - 1])
a = input()
hs = [int(x) for x in input().split()]

dp = [1000000000]* len(hs)

if len(hs) == 1:
  print(hs[0])
  exit()

dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

if len(hs) == 2:
  print(dp[1])
  exit()

for i in range(min(a-2, len(hs)-2)):
  
  if i + 1 < len(hs):
  	dp[i+1] = min(abs(hs[i+1]- hs[i]), dp[i+1]) 
  if(i+2 < len(hs)):
  	dp[i+2] = min(abs(hs[i+2]- hs[i]), dp[i+2]) 

print(dp[-1])

### FIXED CODE ###

a = int(input())


hs = [int(x) for x in input().split()]

if a == 1:
  print(0)
  exit()
dp = [0]* len(hs)


dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

for i in range(2, a):
  dp[i] = min(abs(hs[i-1]- hs[i]) + dp[i-1], abs(hs[i-2]- hs[i]) + dp[i-2] )
  
print(dp[-1])
#coding: utf-8
N = map(int, input().split())
if N % 2 == 1:
   print((N+1)/2)
else:
    print(N/2)



### FIXED CODE ###

N = int(input())
if N % 2 == 1:
    print(int((N+1)/2))
else:
    print(int(N/2))
def dfs(i,j):
    # print("dfs", i, j)
    for m in move:
        ni = i + m[0]
        nj = j + m[1]
        if ni < 0 or ni >= H or nj < 0 or nj >= W:
            continue
        if ch[ni][nj]:
            continue
        if X[i][j] == X[ni][nj]:
            continue
            
        ch[ni][nj] = 1
        K[(ni+nj)%2] += 1
        dfs(ni, nj)
        
H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
ch = [[0] * W for _ in range(H)]
    
move = [[0,1], [0,-1], [1,0], [-1,0]]

K = [0, 0]
ans = 0
for i in range(H):
    for j in range(W):
        if ch[i][j] > 0:
            continue
        ch[i][j] = 1
        K = [0, 0]
        K[(i+j)%2] = 1
        dfs(i, j)
        ans += K[0] * K[1]
        # print(K)
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())

X = [[0] * W for i in range(H)]
G = [[0,0] for i in range(W*H)] 
L = [[-1] * W for i in range(H)] # Group ID

for i in range(H):
    s = input()
    for j in range(W):
        if (i+j) % 2 == 0:
            if s[j] == "#":
                X[i][j] = 1
        else:
            if s[j] != "#":
                X[i][j] = 1



g = -1
for i in range(H):
    for j in range(W):
        if L[i][j] < 0:
            g += 1
            L[i][j] = g
            post = [[i,j]]
            G[g][(i+j)%2] += 1
            while post:
                pre = post
                post = []
                for ggg in pre:
                    i0, j0 = ggg
                    if i0>0 and L[i0-1][j0] < 0 and X[i0][j0] == X[i0-1][j0]:
                        post.append([i0-1,j0])
                        L[i0-1][j0] = g
                        G[g][(i0+j0+1)%2] += 1
                    if i0<H-1 and L[i0+1][j0] < 0 and X[i0][j0] == X[i0+1][j0]:
                        post.append([i0+1,j0])
                        L[i0+1][j0] = g
                        G[g][(i0+j0+1)%2] += 1
                    if j0>0 and L[i0][j0-1] < 0 and X[i0][j0] == X[i0][j0-1]:
                        post.append([i0,j0-1])
                        L[i0][j0-1] = g
                        G[g][(i0+j0+1)%2] += 1
                    if j0<W-1 and L[i0][j0+1] < 0 and X[i0][j0] == X[i0][j0+1]:
                        post.append([i0,j0+1])
                        L[i0][j0+1] = g
                        G[g][(i0+j0+1)%2] += 1
                        
            # print(GGG)
# print(G)
ans = 0
for t in G:
    aa, bb = t
    ans += aa * bb
    
print(ans)
a = []
for i in range(3):
  	a.append(Input())
o = a[0,0] + a[1,1] + a[2,2]
print(o)

### FIXED CODE ###

a = []
for i in range(3):
   	a.append(input())
o = a[0][0] + a[1][1] + a[2][2]
print(o)
a=int(input())
b=int(input())

if (a*b)%2==0:
    print("Couple num")
else:
    print("Odd num")


### FIXED CODE ###

a,b = input().split()

if (int(a)*int(b))%2==0:
    print("Even")
else:
    print("Odd")
k = (int(input())
print(( k // 2 ) * ( k - k // 2 ))

### FIXED CODE ###

k = int(input())
print(( k // 2 ) * ( k - k // 2 ))
N, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()                        # 破壊的。返り値はNone

# print(N, M)
# print(a)


num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]


dp = []
for i in range(N+1):
    n = [dp[i-num[a[j]]] for j in range(M) if i-num[a[j]] >= 0]
    if len(n) == 0:
        dp.append(0)
    else:
        dp.append(max(n) + 1)

# print(dp)

i = N
ans = ""
while True:
    # print("i", i)
    c = [(a[j], dp[i-num[a[j]]], dp[i]) for j in range(M)]
    # print("c", c)
    if dp[i] != 1:
        b = max([a[j] for j in range(M)
                 if i - num[a[j]] >= 0 and dp[i-num[a[j]]] + 1 == dp[i]])
    else:
        b = max([a[j] for j in range(M)
                 if i - num[a[j]] == 0 and dp[i-num[a[j]]] + 1 == dp[i]])
    ans += str(b)
    # print("ans", ans)
    i = i-num[b]
    # print(i)
    if i <= 0:
        break
print(ans)


### FIXED CODE ###

N, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()                        # 破壊的。返り値はNone

# print(N, M)
# print(a)

num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]


dp = [-999 for _ in range(N+1)]
dp[0] = 0
for i in range(N+1):
    n = [dp[i-num[a[j]]] for j in range(M) if i-num[a[j]] >= 0]
    if len(n) > 0:
        dp[i] = max(n) + 1

# print(dp)

i = N
ans = ""
for _ in range(dp[N]):
    # print("i", i)
    # c = [(a[j], dp[i-num[a[j]]], dp[i]) for j in range(M)]
    # print("c", c)
    if dp[i] > 1:
        b = max([a[j] for j in range(M)
                 if i - num[a[j]] >= 0 and dp[i-num[a[j]]] + 1 == dp[i]])
        ans += str(b)
    else:
        b = max([a[j] for j in range(M)
                 if i - num[a[j]] == 0 and dp[i-num[a[j]]] + 1 == dp[i]])
        ans += str(b)
        break
    # print("ans", ans)
    i = i-num[b]
    # print(i)
print(ans)
n,k=map(int,input().split())
s=input()
s+="end"

uselist=[]
for i in range(len(s)-1):
    if i==0 and s[i]=="0":
        uselist.append(0)
    if s[i]=="1" and s[i+1]=="0":
        uselist.append(i+1)
    if s[i+1]=="end":
        continue
ans=0
if uselist[0]>=1:
    uselist.insert(0,0)
    length=len(uselist)

    for i in range(length):
        if i+k+1<=length-1:
            ans=max(ans,uselist[i+k+1]-uselist[i]-1)

        else:
            ans=max(ans,n-uselist[i]-1)

            break
    print(ans)
    print(uselist)

elif uselist[0]==0:
    uselist.insert(0,-1)

    length=len(uselist)
    for i in range(length):
        if i+k+1<=length-1:
            ans=max(ans,uselist[i+k+1]-uselist[i]-1)

        else:
            ans=max(ans,n-uselist[i]-1)

            break
    print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
s=input()
s=s+"w"
lists0=[]
lists1=[] 
count=0
for i in range(n):
    if s[i]!=s[i+1] and s[i]=="0":
        lists0.append(i-count)
        count=i
        
    elif s[i]!=s[i+1] and s[i]=="1":
        lists1.append(i-count)
        count=i

if s[0]=="1":
    lists1[0]+=1
elif s[0]=="0":
    lists0[0]+=1     
#下準備の完成
if s[0]=="1" and s[-2]=="1":
    #do nothing special
    if k>=len(lists0):
        print(n)
    elif k<len(lists0):
        big=0
        ans=sum(lists1[:k+1])+sum(lists0[:k])
        for i in range(len(lists0)-k):
            ans1=ans+lists1[k+1+i]+lists0[k+i]-lists1[i]-lists0[i]
            big=max(big,max(ans,ans1))
            ans=ans1
        print(big)
       
        
elif s[0]=="1" and s[-2]=="0":
    # 最後にlists1の方に0を挿入する
    lists1.append(0)

    if k>=len(lists0):
        print(n)
    elif k<len(lists0):
        big=0
        ans=sum(lists1[:k+1])+sum(lists0[:k])
        for i in range(len(lists0)-k):
            ans1=ans+lists1[k+1+i]+lists0[k+i]-lists1[i]-lists0[i]
            big=max(max(ans,ans1),big)
            ans=ans1
        print(big)
    
elif s[0]=="0" and s[-2]=="1":
    #さいしょのlist1の方に0を挿入する
    lists1.insert(0,0)

    if k>=len(lists0):
        print(n)
    elif k<len(lists0):
        big=0
        ans=sum(lists1[:k+1])+sum(lists0[:k])
        for i in range(len(lists0)-k):
            ans1=ans+lists1[k+1+i]+lists0[k+i]-lists1[i]-lists0[i]
            big=max(big,max(ans,ans1))
            ans=ans1
        print(big)    
elif s[0]=="0" and s[-2]=="0":
    #最初と最後にlist1の方に0を挿入する
    lists1.insert(0,0)
    lists1.append(0)

    if k>=len(lists0):
        print(n)
    elif k<len(lists0):            
        big=0
        ans=sum(lists1[:k+1])+sum(lists0[:k])
        for i in range(len(lists0)-k):
            ans1=ans+lists1[k+1+i]+lists0[k+i]-lists1[i]-lists0[i]
            big=max(big,max(ans,ans1))
            ans=ans1
        print(big)
N, A, B= map(int, input().split())
a = [1]*A + [0]*B
li = []
while len(li) < N:
  li.extend(a)
li_N = li[:N-1]
print(sum(li_N))

### FIXED CODE ###

N, A, B = map(int, input().split())

result = 0
result += N // (A + B) * A
result += min(N % (A + B), A)
print(result)