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

#2回目


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

dp=[-1]*n

for i in range(min(k,n)):
    dp[i]=abs(h[i]-h[0])
#print(dp)

for i in range(k,n):
    #print(i)
    mindp=10**9
    for j in range(i-k,i):
        #print(j)
        mindp=min(mindp , abs(h[i]-h[j])+dp[j])
        
    dp[i]=mindp
 #   print(dp[i])
#print(dp)
print(dp[-1])



### FIXED CODE ###

n,x=map(int,input().split())
a=list(map(int,input().split()))
dp=[-1]*n
dp[0]=0
if n<=x:
    x=n-1
for i in range(1,x+1):
    dp[i]=abs(a[i]-a[0])

for i in range(x+1,n):
    min1=10**9
    for j in range(i-(x),i):  
        if min1>dp[j]+abs(a[j]-a[i]):               
            min1=dp[j]+abs(a[j]-a[i])
    dp[i]=min1
print(dp[-1])
### BUGGY CODE ###

from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
l = a[0]
for i in range(1,n):
  l = lcm(l,a[i])
ans = 0
for i in range(n):
  ans += (l//a[i])%mod
print(ans%mod)

### FIXED CODE ###

from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
l = a[0]
for i in range(1,n):
  l = lcm(l,a[i])
ans = 0
for i in range(n):
  ans += l//a[i]
print(ans%mod)
### BUGGY CODE ###

import numpy as np


def mod_max(loop, mod):
    if mod == 0:
        return 0
    loop_len = len(loop)
    mm = min(loop)
    sheet = np.zeros(loop_len * 2, dtype=int)
    for i in range(mod):
        sheet[i:i + loop_len] += loop
        mm = max(max(sheet[:loop_len] + sheet[loop_len:]), mm)
    return mm


def main():
    n, k = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    c = [int(i) for i in input().split()]

    seen = set()
    loop_list = []
    for start in range(n):
        v = start
        loop = []
        while v not in seen:
            seen.add(v)
            loop.append(c[v])
            v = p[v]
        seen.add(v)
        if loop:
            loop_list.append(np.array(loop))

    ans = min(c)
    for loop in loop_list:
        loop_len = len(loop)
        loop_num = k // loop_len
        loop_mod = k % loop_len
        loop_sum = loop.sum()
        ans = max(mod_max(loop, min(loop_len, k)), ans)
        if loop_num > 0:
            ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
            ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def mod_max(loop, mod):
    if mod == 0:
        return 0
    loop_len = len(loop)
    mm = min(loop)
    for start in range(loop_len):
        current_sum = 0
        for i in range(mod):
            current_sum += loop[(start + i) % loop_len]
            mm = max(current_sum, mm)
    return mm


def main():
    n, k = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    c = [int(i) for i in input().split()]

    seen = set()
    loop_list = []
    for start in range(n):
        v = start
        loop = []
        while v not in seen:
            seen.add(v)
            loop.append(c[v])
            v = p[v]
        seen.add(v)
        if loop:
            loop_list.append(loop)

    ans = min(c)
    for loop in loop_list:
        loop_len = len(loop)
        loop_num = k // loop_len
        loop_mod = k % loop_len
        loop_sum = sum(loop)
        ans = max(mod_max(loop, min(loop_len, k)), ans)
        if loop_num > 0:
            ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
            ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

x = input()
while ("ST" in x):
    x = x.replace("ST", '',1 )
print(len(x))

### FIXED CODE ###

x = input()
ans = []
for i in range(len(x)):
    if (x[i] == "S"):
        ans.append("S")
    else:
        if (len(ans) != 0):
            if (ans[-1] == "S"):
                ans.pop(-1)
            else:
                ans.append("T")
        else:
            ans.append("T")
print(len(ans))
### BUGGY CODE ###

def d_no_need(N, K, A):
    from bisect import bisect_left
    # 値がK以上の要素は単体で不必要でない要素になれる
    A.sort()
    a_sorted = A[:bisect_left(A, K)]
    ans = len(a_sorted)  # a_sortedの要素は不必要となりうる

    dp = [False] * K  # dp[k]:a_sortedの一部の和を取った値をKにできるか？
    dp[0] = True
    current_max = 0
    for idx, a in reversed(list(enumerate(a_sorted))):
        if current_max + a >= K:
            ans = idx
        for j in range(min(current_max, K - a) + 1):
            if dp[j] and j + a < K:
                current_max = max(current_max, j + a)
                dp[j + a] = True
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_no_need(N, K, A))

### FIXED CODE ###

def d_NoNeed(N, K, A):
    a = sorted(A)
    s = t = 0
    # aのうち要素が大きいものから見ていったとき、
    # その要素を入れても総和がK未満のものだけ加えていく
    # 最後に連続して加えた要素の個数が解となる
    # (それら以外の要素の組み合わせでK以上にでき、かつ、
    #  それらの総和がK未満になるため)
    for i in range(N - 1, -1, -1):
        if s + a[i] < K:
            s += a[i]
            t += 1
        else:
            t = 0
    return t

N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_NoNeed(N, K, A))
### BUGGY CODE ###

import numpy as np
from scipy.sparse import csr_matrix, csgraph
N = int(input())
row, column, data = zip(*tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(N - 1)))
Q, K = map(int, input().split())
dist = csgraph.dijkstra(csr_matrix(([d + 1 for d in data], (row, column)), (N, N), dtype=np.int64), directed=False, indices=[K - 1])[0]
for _ in range(Q):
    indices = list(map(lambda n: int(n) - 1, input().split()))
    print(int(dist[indices].sum()))

### FIXED CODE ###

from collections import deque
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    graph[a - 1].append((b - 1, c))
    graph[b - 1].append((a - 1, c))
Q, K = map(int, input().split())
visited = [0] * N
visited[K - 1] = 1
q = deque([(K - 1, 0)])
while q:
    p, c = q.popleft()
    for dst, d in graph[p]:
        if not visited[dst]:
            visited[dst] = c + d
            q.append((dst, c + d))
for _ in range(Q):
    x, y = map(lambda n: int(n) - 1, input().split())
    print(visited[x] + visited[y])
### BUGGY CODE ###

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

mx = max(H)
ind = H.index(max(H))

if ind != N - 1 and mx - min(H[ind+1:]) > 1:
    print("No")
    exit()

for i in range(N-1):
    if H[i] - min(H[i+1:]) > 1:
        print("No")
        exit()

print("Yes")

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
r_H = list(reversed(H))

for i in range(N-1):
    if r_H[i+1] - r_H[i] > 1:
        print("No")
        exit()
    if r_H[i+1] - r_H[i] == 1:
        r_H[i+1] = r_H[i+1] - 1
print("Yes")
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
ans=1
for i in range (n):
  ans=ans*l[i]
  
if ans>10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
ans = 1

if 0 in l:
  print(0)
  exit()

for i in range(n):
  ans*=l[i]
  if ans > 10**18:
      print(-1)
      exit()

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

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

a = [0]
for i in range(N):
    a.append(a[i]+A[i])
b = [0]
for i in range(M):
    b.append(b[i]+B[i])

ans = 0
for i in range(N+1):
    if a[i] > K: break
    for j in range(M+1):
        if a[i] + b[j] > K: break
        ans = max(ans, i+j)

print(ans)

### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K: break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
    
print(ans)
### BUGGY CODE ###

import itertools
from heapq import heappush, heappop
from random import randint
from time import time

class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue
    #...
queue = PriorityQueue()
n = int(input())
l = tuple(map(int, input().split()))
total = 0
mod = 1000000007
L = itertools.combinations(l, 2)
for a,b in L:
    num = ((a % mod) * (b % mod)) % mod
    queue.push(num)
while len(queue) > 0:
    total += queue.pop()
print(total % mod)


### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
mod = 1000000007
q = sum(l)
ans = 0
for i in range(len(l)):
    q -= l[i]
    ans += l[i] * q % mod
print(ans % mod)
### BUGGY CODE ###

from collections import deque

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())

c = [input().rstrip() for _ in range(H)]

d = deque([(0, x1-1, y1-1)])

dp = [[False] * W for _ in range(H)]
dp[x1-1][y1-1] = True

while d:
    step, x, y = d.popleft()
    if x == x2-1 and y == y2-1:
        print(step)
        break

    for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        for i in range(1, K+1):
            nx = x + dx * i
            ny = y + dy * i
            if 0 <= nx < H and 0 <= ny < W:
                if c[nx][ny] == '@':
                    break

                if not dp[nx][ny]:
                    dp[nx][ny] = True
                    d.append((step + 1, nx, ny))
            else:
                break
else:
    print(-1)


### FIXED CODE ###

from collections import deque

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())

c = [input().rstrip() for _ in range(H)]

d = deque([(x1-1, y1-1)])

dp = [[-1] * W for _ in range(H)]
dp[x1-1][y1-1] = 0

while d:
    x, y = d.popleft()
    if x == x2-1 and y == y2-1:
        print(dp[x][y])
        break

    for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        for i in range(1, K+1):
            nx = x + dx * i
            ny = y + dy * i

            if 0 > nx or nx >= H or 0 > ny or ny >= W or c[nx][ny] == '@':
                break

            if dp[nx][ny] == -1:
                dp[nx][ny] = dp[x][y] + 1
                d.append((nx, ny))
            elif dp[nx][ny] <= dp[x][y]:
                break
else:
    print(-1)
### BUGGY CODE ###

A, B, K = list(map(int, input().split()))
if K >= (B - A + 1) / 2 :
    l = [n for n in range(A, B+1)]
else:
    l1 = {n for n in range(A, A + K)}
    l2 = {n for n in range(B - K + 1, B + 1)}
    l = sorted(list((l1 | l2) & {n for n in range(A, B+1)}))
for s in l:
    print(s)

### FIXED CODE ###

A, B, K = list(map(int, input().split()))
if K >= (B - A + 1) / 2 :
    for n in range(A, B+1):
        print(n)
else:
    for n in range(A, A + K):
        print(n)
    for n in range(B - K + 1, B + 1):
        print(n)
### BUGGY CODE ###

# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数を２つのグループに分ける

import itertools

def main():
  a, b = map(int, input().split())
  c = gojo(a,b)
  
  fac = [1]
  fac = facto(c, fac)
  # print(fac)
  print(len(fac))  
  
def facto(n, fac):
  if n == 1:
    return [1]
  if n == 2:
    return[1, 2]
  if n % 2 == 0:
    fac = [1, 2]
  else:
    fac = [1]
  
  max_n = n + 1 #int(n ** 0.5 + 2)
  
  is_prime = [True for x in range(max_n)]
  for cursor in range(3, max_n, 2):
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
        while n % cursor == 0:
          n //= cursor
        if n == 1:
          break
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
      
  return fac
  
def gojo(a,b):
  if b > a:
    a, b = b, a
  c = a % b
  if c == 0:
    return(b)
  else:
    return gojo(b, c)

if __name__ == "__main__":
  main()


### FIXED CODE ###

# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数＋１が答え

import itertools
from fractions import gcd
from math import ceil

def main():
  a, b = map(int, input().split())
  fac = facto(gcd(a,b))
  print(len(fac))  
  
def facto(n):
  fac = [1]
  if n == 1:
    return [1]
  elif n % 2 == 0:
    fac = [1, 2]
    while n % 2 == 0:
      n = n // 2
  
  max_n = ceil(n ** 0.5) + 1
  
  is_prime = [True for x in range(max_n)]
  for cursor in range(3, max_n, 2):
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
        while n % cursor == 0:
          n = n // cursor
        if n == 1:
          break
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    fac.append(n)
  return fac

if __name__ == "__main__":
  main()
### BUGGY CODE ###

x, y, z, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ab = []
for i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
c.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
k_2 = min([len(c), k])
for i in range(k_1):
    for j in range(k_2):
        abc.append(ab[i]+c[j])
abc.sort(reverse = True)
for i in range(k):
    print(abc[i])

### FIXED CODE ###

import heapq
import sys
x, y, z, k = map(int, input().split())

a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3))

abc = {(0,0,0)}

stu = [[-a[0]-b[0]-c[0], 0,0,0]]
heapq.heapify(stu)
result = []
while k > 0:
    out_p, n, m, l = heapq.heappop(stu)
    if n+1<x and not((n+1,m,l) in abc):
        abc.add((n+1,m,l))
        heapq.heappush(stu, [-a[n+1]-b[m]-c[l], n+1, m, l])
    if m+1<y and not((n,m+1,l) in abc):
        abc.add((n,m+1,l))
        heapq.heappush(stu, [-a[n]-b[m+1]-c[l], n, m+1, l])
    if l+1<z and not((n,m,l+1) in abc):
        abc.add((n,m,l+1))
        heapq.heappush(stu, [-a[n]-b[m]-c[l+1], n, m, l+1])
    result.append(-out_p)
    k -= 1
result.sort(reverse=True)
for i in result:
    print(i)
### BUGGY CODE ###

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

inf = float('inf')
memo = [inf for _ in range(h+1)]
memo[0] = 0
for i in range(h+1):
    for x,y in l:
        # これめっちゃ大事やん
        j = min(i+x, h)
        memo[j] = min(memo[j],memo[i] + y)
print(memo[-1])




### FIXED CODE ###

h,n = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(n)]
 
inf = float('inf')
memo = [inf for _ in range(h+1)]
memo[0] = 0
for i in range(h+1):
    for x,y in l:
        j = min(i+x, h)
        memo[j] = min(memo[j],memo[i] + y)
print(memo[-1])
### BUGGY CODE ###

N = int(input())

def ryuka(N):    
    if N == 0:
        return 2
    elif N == 1:
        return 1
    else:
        N = ryuka(N-1) + ryuka(N-2)
        return N

print(ryuka(N))

### FIXED CODE ###

N = int(input())
L = [2, 1]
for i in range(2, N+1):
    L.append(L[i-1] + L[i-2])
print(L[N])
### BUGGY CODE ###

s = input()
q = int(input())
num = 0
ans = "0"

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans = query[2] + ans
      else:
        ans = ans + query[2]
    else:
      if num%2 == 0:
        # 後方
        ans = ans + query[2]
      else:
        ans = query[2] + ans
        
mes = ans.replace("0", s)
if num%2 == 0:
  print(mes)
else:
  mes = ''.join(list(reversed(mes)))
  print(mes)

### FIXED CODE ###

from collections import deque
s = input()
q = int(input())
num = 0
ans = deque(s)

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:
      if num%2 == 0:
        # 後方
        ans.append(query[2])
      else:
        ans.appendleft(query[2])     

if num%2 == 0:
  print(''.join(ans))
else:
  ans.reverse()
  print(''.join(ans))
### BUGGY CODE ###

S = input()

n = len(S)

modlist = [0] * 2019
num = 0

for i in range(n):
    fig = int(S[n - i - 1])
    num = (num + fig * (10 ** i)) % 2019
    modlist[num] = modlist[num] + 1

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    m = modlist[i]
    if n != 0:
        result += m * (m - 1) / 2

print(int(result))

### FIXED CODE ###

S = input()

n = len(S)

medalist = [0] * 2019
medalist[0] = 1
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    num = (num + fig * mods) % 2019
    medalist[num] = medalist[num] + 1
    mods = (mods * 10) % 2019

result = 0

for i in range(2019):
    m = medalist[i]
    if m != 0:
        result += m * (m - 1) / 2

print(int(result))
### BUGGY CODE ###

from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

n = int(input())
a = list(map(int, input().split()))

lcm = lcmArr(a)
ret = 0
for val in a:
    ret += lcm // val
    ret %= MOD
print(ret)

### FIXED CODE ###

from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

n = int(input())
a = list(map(int, input().split()))

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)
### BUGGY CODE ###

N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)
t=0
for i in range(N):
    for j in range(i+1,N):
        if 2*L[j]<L[i]:
            break
        for k in range(j+1,N):
            if L[i]<L[j]+L[k]:
                t+=1
            else:
                break

print(t)


### FIXED CODE ###

from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
res=[0]*n

datas=[None]*m
for i in range(m):
  x,y,z=map(int,input().split())
  datas[i]=[min(x-1,y-1),max(x-1,y-1)]

maxi=0
for i in range(len(datas)):
  d=datas[i]
  if res[d[0]]==0 and res[d[1]]==0:
    maxi+=1
    res[d[0]]=maxi
    res[d[1]]=maxi
  elif res[d[0]]==0 and res[d[1]]!=0:
    res[d[0]]=res[d[1]]
  elif res[d[0]]!=0 and res[d[1]]==0:
    res[d[1]]=res[d[0]]
  elif res[d[0]]!=res[d[1]]:
    cor=min(res[d[0]],res[d[1]])
    dum=max(res[d[0]],res[d[1]])
    res[d[0]],res[d[1]]=cor,cor
    for i in range(len(res)):
      if res[i]==dum:
        res[i]=cor

count0=res.count(0)
ress=set(res)

print(count0 + len(ress) - (1 if 0 in ress else 0))


### FIXED CODE ###

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

parent=[i for i in range(n)]
rank=[0 for i in range(n)]

def find(a):
  if parent[a]==a:
    return a
  else:
    return find(parent[a])

def union(a,b):
  ar=find(a)
  br=find(b)
  if ar==br:
    return
  if rank[a]>rank[b]:
    parent[br]=ar
  else:
    parent[ar]=br
    if rank[a]==rank[b]:
      rank[a]+=1
      
def same(a,b):
  ar=find(a)
  br=find(b)
  return ar==br

q=[None]*m

for i in range(m):
  x,y,z=map(int,input().split())
  q[i]=[x-1,y-1]

for i in range(len(q)):
  union(q[i][0],q[i][1])
  
roots=[0]*len(parent)
for i in range(len(parent)):
  roots[i]=find(i)

print(len(set(roots)))
### BUGGY CODE ###

from collections import Counter
from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())

    ac = Counter(a)
    acl = defaultdict(int)
    for ae in ac:
        acl[ae] = ac[ae]

    for _ in range(q):
        b, c = map(int, input().split())
        rmed = acl[b]
        acl[c] += rmed
        acl[b] = 0
        r = 0
        for acle in acl:
            r += acle * acl[acle]
        print(r)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    asum = sum(a)
    ac = Counter(a)
    acl = defaultdict(int)
    for ae in ac:
        acl[ae] = ac[ae]

    for _ in range(q):
        b, c = map(int, input().split())
        rmed = acl[b]
        acl[c] += rmed
        acl[b] = 0
        asum -= b * rmed
        asum += c * rmed
        print(asum)

if __name__ == '__main__':
    main()
### BUGGY CODE ###


n, a, b = map(int, input().split())
l = []
while len(l) <= n:
    for _ in range(a):
    	l.append("b")
    for _ in range(b):
        l.append("r")

print(l[:n].count("b"))


### FIXED CODE ###

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

l = a + b
set_cnt = n // l
rest = n % l
if rest >= a:
    ans = set_cnt * a + a
else:
    ans = set_cnt * a + rest

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

n,k = map(int,input().split())
A = list(map(int,input().split()))
num = []
for i in range(n-k):
  An = 1
  An2 = 1
  for j in range(k):
    An = An*A[i+j]
    An2 = An2*A[i+j+1]
  if An2 > An:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

n,k = map(int,input().split())
A = list(map(int,input().split()))
for i in range(n-k):
  if A[i] < A[i+k]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

R,G,B,N = map(int,input().split())
ans = 0
for i in range(0,int(N/R)+1):
  for j in range(0,int(N/G)+1):
    if i*R+j*G<=N and (N-i*R-j*G)%B == 0:
        ans+=1
print(ans)

### FIXED CODE ###

R,G,B,N = map(int,input().split())
ans = 0
for i in range(0,N+1,R):
  for j in range(0,N+1,G):
    if i+j<=N:
      if (N-i-j)%B == 0:
        ans+=1
print(ans)
### BUGGY CODE ###

def main():

    from collections import deque

    h,w = map(int,input().split())
    A = [list(input()) for i in range(h)]

    queue = deque([])
    Distance = [[-1 for i in range(w)]for j in range(h)]

    for i in range(h):
        for j in range(w):
            if A[i][j]=='#':
                queue.append([i,j])
                Distance[i][j] = 0

    ans = 0

    while queue:
        x,y = queue.popleft()
        if x!=0:
            if A[x-1][y] == '.' and Distance[x-1][y] == -1:
                queue.append([x-1,y])
                ans = Distance[x-1][y] = Distance[x][y] + 1
        if x!=h-1:
            if A[x+1][y] == '.' and Distance[x+1][y] == -1:
                queue.append([x+1,y])
                ans = Distance[x+1][y] = Distance[x][y] + 1
        if y!=0:
            if A[x][y-1] == '.' and Distance[x][y-1] == -1:
                queue.append([x,y-1])
                ans = Distance[x][y-1] = Distance[x][y] + 1
        if y!=w-1:
            if A[x][y+1] == '.' and Distance[x][y+1] == -1:
                queue.append([x,y+1])
                ans = Distance[x][y+1] = Distance[x][y] + 1

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    from collections import deque

    h,w = map(int,input().split())
    A = []
    for i in range(h):
        A += list(input())

    queue = deque([])
    Distance = [-1]*(h*w)

    for i in range(h):
        for j in range(w):
            if A[i*w+j]=='#':
                queue.append([i,j])
                Distance[i*w+j] = 0

    ans = 0

    while queue:
        x,y = queue.popleft()
        d = Distance[x*w+y]
        if x!=0 and Distance[(x-1)*w+y] == -1:
                queue.append([x-1,y])
                ans = Distance[(x-1)*w+y] = d+1
        if x!=h-1 and Distance[(x+1)*w+y] == -1:
                queue.append([x+1,y])
                ans = Distance[(x+1)*w+y] = d+1
        if y!=0 and Distance[x*w+y-1] == -1:
                queue.append([x,y-1])
                ans = Distance[x*w+y-1] = d+1
        if y!=w-1 and Distance[x*w+y+1] == -1:
                queue.append([x,y+1])
                ans = Distance[x*w+y+1] = d+1

    print(ans)
if __name__ == '__main__':
    main()