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

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

import bisect

def main():
	N,W=map(int,input().split())
	
	li=[list(map(int,input().split())) for _ in range(N)]
	V=sum(v for w,v in li)
	
	dp=[[10**15]*(V+2) for _ in [0]*(N+1)]
	
	for i in range(N):
		w = li[i][0]
		v = li[i][1]
		dp[i + 1][v] = min(dp[i + 1][v], w)
		for j in range(V+1)[::-1]:
			if j-v>=0:
				dp[i+1][j]=min(dp[i+1][j],dp[i+1][j+1],dp[i][j],dp[i][j-v]+w)
			else:
				dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j + 1], dp[i][j])
#	for i in range(N+1):
#		print(dp[i])
	
	print(bisect.bisect_right(dp[-1],W)-1)
	
	
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

import bisect

def main():
	N,W=map(int,input().split())
	
	li=[list(map(int,input().split())) for _ in range(N)]
	V=sum(v for w,v in li)
	
	dp=[[10**15]*(V+2) for _ in [0]*(N+1)]
	
	for i in range(N):
		w = li[i][0]
		v = li[i][1]
		dp[i + 1][v] = min(dp[i + 1][v], w)
		for j in range(V+1)[::-1]:
			if j-v>=0:
				dp[i+1][j]=min(dp[i+1][j],dp[i+1][j+1],dp[i][j],dp[i][j-v]+w)
			else:
				dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j + 1], dp[i][j])
#	for i in range(N+1):
#		print(dp[i])
	
	print(bisect.bisect_right(dp[-1],W)-1)
	
	
	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

def lcm(n,m):
  ma=max(n,m)
  while True:
    if (ma%n==0 and ma%m==0):
      return ma
    ma=ma+1
n,m=map(int,input().split())
print(lcm(n,m))

### FIXED CODE ###

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

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


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

print(lcm(a,b))
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    pre = min(k,i)
    costs_pre = [0] * pre
    for j in range(1,pre+1):
        costs_pre[j-1] = dp[i-j] + abs(h[i-j]-h[i])
    dp[i] = min(costs_pre)
print(dp[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    mincost = 10 ** 9
    for j in range(1, min(i+1, k+1)):
        mincost = min(mincost, dp[i-j] + abs(h[i]-h[i-j]))
    dp[i] = mincost
print(dp[n-1])
### BUGGY CODE ###

N = int(raw_input())
A = map(int, raw_input().split())

for i in range(N):
    print A.index(i+1)+1

### FIXED CODE ###

N = int(raw_input())
A = map(int, raw_input().split())

new_list = []

for i in range(N):
    new_list.append((A[i],i+1))

new_list = sorted(new_list)

for i in range(N):
    print new_list[i][1]
### BUGGY CODE ###

N=int(input())


X=[1]+[6**i for i in range(1,7)]+[9**i for i in range(1,6)]
X.sort()
X.reverse()

ANS=1000000



i=6



for i_0 in range(max(N//X[0]-i,0),N//X[0]+1):
    N_0=N-X[0]*i_0
    for i_1 in range(max(N_0//X[1]-i,0),N_0//X[1]+1):
        N_1=N_0-X[1]*i_1
        for i_2 in range(max(N_1//X[2]-i,0),N_1//X[2]+1):
            N_2=N_1-X[2]*i_2
            for i_3 in range(max(N_2//X[3]-i,0),N_2//X[3]+1):
                N_3=N_2-X[3]*i_3
                for i_4 in range(max(N_3//X[4]-i,0),N_3//X[4]+1):
                    N_4=N_3-X[4]*i_4
                    for i_5 in range(max(N_4//X[5]-i,0),N_4//X[5]+1):
                        N_5=N_4-X[5]*i_5
                        for i_6 in range(max(N_5//X[6]-i,0),N_5//X[6]+1):
                            N_6=N_5-X[6]*i_6
                            for i_7 in range(max(N_6//X[7]-i,0),N_6//X[7]+1):
                                N_7=N_6-X[7]*i_7
                                for i_8 in range(max(N_7//X[8]-i,0),N_7//X[8]+1):
                                    N_8=N_7-X[8]*i_8
                                    for i_9 in range(max(N_8//X[9]-i,0),N_8//X[9]+1):
                                        N_9=N_8-X[9]*i_9
                                        i_10=N_9//6
                                        N_10=N_9-X[10]*i_10
                                        if ANS>i_0+i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9+i_10+N_10:
                                            ANS=i_0+i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9+i_10+N_10


                                            




print(ANS)
        
    


### FIXED CODE ###

N=int(input())


X=[1]+[6**i for i in range(1,7)]+[9**i for i in range(1,6)]
X.sort()
X.reverse()

ANS=1000000







for i_0 in range(max(N//X[0]-3,0),N//X[0]+1):
    N_0=N-X[0]*i_0
    for i_1 in range(max(N_0//X[1]-3,0),N_0//X[1]+1):
        N_1=N_0-X[1]*i_1
        for i_2 in range(max(N_1//X[2]-3,0),N_1//X[2]+1):
            N_2=N_1-X[2]*i_2
            for i_3 in range(max(N_2//X[3]-3,0),N_2//X[3]+1):
                N_3=N_2-X[3]*i_3
                for i_4 in range(max(N_3//X[4]-3,0),N_3//X[4]+1):
                    N_4=N_3-X[4]*i_4
                    for i_5 in range(max(N_4//X[5]-3,0),N_4//X[5]+1):
                        N_5=N_4-X[5]*i_5
                        for i_6 in range(max(N_5//X[6]-3,0),N_5//X[6]+1):
                            N_6=N_5-X[6]*i_6
                            for i_7 in range(max(N_6//X[7]-3,0),N_6//X[7]+1):
                                N_7=N_6-X[7]*i_7
                                for i_8 in range(max(N_7//X[8]-3,0),N_7//X[8]+1):
                                    N_8=N_7-X[8]*i_8
                                    for i_9 in range(max(N_8//X[9]-3,0),N_8//X[9]+1):
                                        N_9=N_8-X[9]*i_9
                                        i_10=N_9//6
                                        N_10=N_9-X[10]*i_10
                                        if ANS>i_0+i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9+i_10+N_10:
                                            ANS=i_0+i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9+i_10+N_10


                                            




print(ANS)
### BUGGY CODE ###

N,K = map(int, input().split())
A = [int(a) for a in input().split()]

dp = [[False]*(K+1) for _ in range(N)]
memo = [False]*(K+1)

for j in range(K+1):
    q = j // A[0]
    if q%2 == 1:
        dp[0][j] = True
        memo[j] = True
        
for _ in range(2):
    for i in range(1, N):
        for j in range(K+1):
            if j < A[i]:
                dp[i][j] = False
            else:
                if memo[j-A[i]]:
                    dp[i][j] = False
                else:
                    dp[i][j] = True
                    memo[j] = True
                
ans = "Second"
for i in range(N):
    if dp[i][K]:
        ans = "First"
        break
        
print(ans)

### FIXED CODE ###

N,K = map(int, input().split())
A = [int(a) for a in input().split()]

dp = [False]*(K+1)

for i in range(K+1):
    f = False
    for j in range(N):
        if A[j] > i:
            break
        if dp[i-A[j]]:
            continue
        f = True
    dp[i] = f
    
if dp[K]:
    ans = "First"
else:
    ans = "Second"
        
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

mod = 10**9 + 7
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dp = [0] * (C + 1)
dp[0] = 1
for i in range(N):
    X = [0] * (C + 1)
    for j in range(C+1):
        for k in range(A[i], B[i] + 1):
            X[j] = (X[j] + pow(k, j, mod)) % mod
    ndp = [0] * (C + 1)
    for j in range(C+1):
        for k in range(C+1-j):
            ndp[j + k] = (ndp[j + k] + dp[j] * X[k]) % mod
    dp = ndp
print(dp[C])

### FIXED CODE ###

import sys
input = sys.stdin.readline

mod = 10**9 + 7
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dp = [0] * (C + 1)
dp[0] = 1
for i in range(N):
    X = [0] * (C + 1)
    for j in range(A[i], B[i] + 1):
        x = 1
        for k in range(C+1):
            X[k] = (X[k] + x) % mod
            x = x * j % mod
    ndp = [0] * (C + 1)
    for j in range(C+1):
        for k in range(C+1-j):
            ndp[j + k] = (ndp[j + k] + dp[j] * X[k]) % mod
    dp = ndp
print(dp[C])
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline

n, q = map(int, input().split())
cons = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

cons.sort(key=lambda x: x[2])
for i in range(n):
    cons[i][0] -= cons[i][2]
    cons[i][1] -= cons[i][2]

ans = [-1] * q
for i in range(n):
    s = bisect.bisect_left(d, cons[i][0])
    t = bisect.bisect_left(d, cons[i][1])
    while s < t:
        if ans[s] != -1:
            s += 1
        else:
            ans[s] = cons[i][2]
            s += 1
print(*ans, sep="\n")

### FIXED CODE ###

import sys
import bisect
input = sys.stdin.readline

n, q = map(int, input().split())
cons = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

cons.sort(key=lambda x: x[2])
for i in range(n):
    cons[i][0] -= cons[i][2]
    cons[i][1] -= cons[i][2]

ans = [-1] * q
l = [-1] * q
for i in range(n):
    s = bisect.bisect_left(d, cons[i][0])
    t = bisect.bisect_left(d, cons[i][1])
    while s < t:
        if l[s] != -1:
            s = l[s]
        else:
            ans[s] = cons[i][2]
            l[s] = t
            s += 1
print(*ans, sep="\n")
### BUGGY CODE ###

def myinput(rownum):
    res = []
    for i in range(rownum):
        temp = input().split(" ")
        res += temp
    return res

def main():
    r = myinput(2)
    n = r[0]
    a = list(map(lambda x:int(x),r[1:]))
    res = ""
    res = [str(a.index(i+1) + 1) for i in range(len(a))]
    print(" ".join(res))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
#input = sys.stdin.readline

def main():
    n = input()
    a = input().split(" ")
    # r = ""
    # for i in range(int(n)):
    #     r += str(a.index(str(i+1)) + 1) + " "
    # print(r[:-1])
    a = [(a[i],str(i+1)) for i in range(len(a))]
    a = list(map(lambda x:x[1],sorted(a,key=lambda x:int(x[0]))))
    print(" ".join(a))

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

mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10 % mod

ans=0
for i in t:
  ans += (i-1)*i//2

print(ans)

### FIXED CODE ###

mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

ans=0
for i in t:
  ans += (i-1)*i//2

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

from collections import Counter
n, m = map(int, input().split())
A = list(map(int, input().split()))
cA = Counter(A)
mA = min(cA)
B = [[] for _ in range(m)]
for i in range(m):
    B[i] = list(map(int, input().split()))
B.sort(reverse=True, key=lambda x: x[1])

for (b,c) in B:
    if c < mA: break
    while b>0 and mA<c:
        if b>cA[mA]:
            cA[c] += cA[mA]; b -= cA[mA]
            del cA[mA]
            mA = min(cA)
        else:
            cA[mA] -= b
            cA[c] += b
            b = 0

ans = 0
for key, val in cA.items():
    ans += key*val
print(ans)

### FIXED CODE ###

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

B = [[] for _ in range(m)]
for i in range(m):
    B[i] = list(map(int, input().split()))
B.sort(key=lambda x: -x[1])

_A = []
cnt = 0
for i in range(m):
    _A.extend([B[i][1]]*B[i][0])
    cnt += B[i][0]
    if cnt > n:
        break
A += _A
A.sort(reverse=True)
print(sum(A[:n]))
### BUGGY CODE ###

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

count = 0

for i in range(a, b+1):
    if i % x == 0:
        count += 1

print(count)

### FIXED CODE ###

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

print(b // x - (a - 1) // x)
### BUGGY CODE ###

N = int(input())


def make_prime(n):
    array = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                array.append(i)
                temp = temp // i

    if temp != 1:
        array.append(temp)

    if array == []:
        array.append(n)

    return array


def devide(array, result):
    if array == []:
        return result

    # xに値を掛けた場合
    x_target = devide(array[1:], (result[0] * array[0], result[1]))

    y_target = devide(array[1:], (result[0], result[1] * array[0]))

    if sum(x_target) <= sum(y_target):
        return x_target
    else:
        return y_target


result = devide(make_prime(N), (1, 1))

print(sum(result) - 2)


### FIXED CODE ###

from math import sqrt

N = int(input())

search_max = int(sqrt(N))

min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
            min_number = x + y

print(min_number-2)
### BUGGY CODE ###

import heapq
import copy


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    prev = [0] * len(adj)
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to in v_tos:
            if min_dist + v_to[1] < dist[v_to[0]]:
                dist[v_to[0]] = min_dist + v_to[1]
                prev[v_to[0]] = v_from
                heapq.heappush(q, [dist[v_to[0]], v_to[0]])
    return dist, prev


N, M = map(int, input().split())
adj = [[] for _ in range(N + 1)]
for _ in range(M):
    A, B = map(int, input().split())
    adj[A].append([B, 1])

ans_best = []
len_ans = N+1
for start in range(1, N+1):
    ans = []
    adj_new = copy.deepcopy(adj)
    adj_new.append(adj[start])
    dist, prev = dijkstra(adj_new, N + 1)
    if dist[start] < 10 ** 10:
        k = start
        while k != N + 1:
            ans.append(k)
            k = prev[k]
        if len(ans) < len_ans:
            ans_best = ans
            len_ans = len(ans)

if len_ans == N+1:
    print(-1)
else:
    print(len_ans)
    for a in ans_best:
        print(a)


### FIXED CODE ###

import heapq


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    prev = [0] * len(adj)
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to in v_tos:
            if min_dist + v_to[1] < dist[v_to[0]]:
                dist[v_to[0]] = min_dist + v_to[1]
                prev[v_to[0]] = v_from
                heapq.heappush(q, [dist[v_to[0]], v_to[0]])
    return dist, prev


N, M = map(int, input().split())
adj = [[] for _ in range(2 * N + 1)]
flg = 1
see = [0] * (N + 1)
for _ in range(M):
    A, B = map(int, input().split())
    adj[A].append([B, 1])
    adj[A].append([B + N, 1])

ans_best = []
len_ans = N+1
for start in range(1, N+1):
    if flg == 0:
        if see[start] == 0:
            continue
    ans = []
    dist, prev = dijkstra(adj, start)
    if dist[start + N] < 10 ** 10:
        k = start + N
        while k != start:
            k = prev[k]
            ans.append(k)
        if len(ans) < len_ans:
            ans_best = ans
            len_ans = len(ans)
            if flg:
                for a in ans:
                    see[a] = 1
                flg = 0

if len_ans == N+1:
    print(-1)
else:
    print(len_ans)
    for a in ans_best:
        print(a)
### BUGGY CODE ###

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

#n 買う商品数
#m 割引券の数
#a 値段

a.sort()
for i in range(m):
    tmp = a.pop(-1) //2
    a.append(tmp)
    a.sort()
print(sum(a))

    

### FIXED CODE ###

n,m = map(int,input().split())
#a = list(map(int,(input().split())))
a = list(map(lambda x: int(x)*(-1), input().split()))

import heapq
#n 買う商品数
#m 割引券の数
#a 値段
heapq.heapify(a)
while True:
   # print(a)
    tmp = (-1) * heapq.heappop(a) //2
    heapq.heappush(a,-1 * tmp)
    m -= 1
    if m == 0:
        break
print(-1*sum(a))
### BUGGY CODE ###

S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]

ans = S
mode = True  # True: Normal False: Reverse
for query in Query:
    T = query[0]
    if T == '1':
        # モードを反転
        mode = not mode
    else:
        F = query[1]
        if (mode and (F == '1')) or (not mode and (F == '2')):
            ans = query[2] + ans
        else:
            ans = ans + query[2]
    
if not mode:
    ans = ans[::-1]

print(ans)

### FIXED CODE ###

S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]

mode = True  # True: Normal False: Reverse
pre = []
aft = []
for query in Query:
    if query[0] == '1':
        # モードを反転
        mode = not mode
    else:
        if (mode and (query[1] == '1')) or (not mode and (query[1] == '2')):
            pre.append(query[2])
        else:
            aft.append(query[2])
    
ans = ''.join(pre[::-1]) +  S + ''.join(aft)
    
if not mode:
    ans = ans[::-1]
 
print(ans)
### BUGGY CODE ###

from collections import Counter
import itertools

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

div_l = []
for i in range(n):
    div_l.append(make_divisors(a[i]))

div = list(itertools.chain.from_iterable(div_l))
dict = Counter(div)
ans = [k for k, v in dict.items() if v >= n - 1]
print(max(ans))


### FIXED CODE ###

from fractions import gcd

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

left = [0 for _ in range(n + 1)]
right = [0 for _ in range(n + 1)]
for i in range(n):
    left[i + 1] = gcd(left[i], a[i])

for i in reversed(range(n)):
    right[i] = gcd(right[i + 1], a[i])

ans = 0
for i in range(n):
    l = left[i]
    r = right[i+1]
    ans = max(ans, gcd(l, r))

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

import sys

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

water_pattern = []
for i in range(f+1):
    for j in range(f+1):
        x = a*i*100 + b*j*100
        if x <= f:
            water_pattern.append(x)

sugar_pattern = []
for i in range(f+1):
    for j in range(f+1):
        y = c*i + d*j
        if y <= f:
            sugar_pattern.append(y)

sugarwater_max = -1
sugar_max = -1
concentration = 0
for i in range(len(water_pattern)):
    for j in range(len(sugar_pattern)):
        if i == 0 and j == 0:
            continue
        else:
            sugarwater = water_pattern[i] + sugar_pattern[j]
            if (water_pattern[i]/100) * e >= sugar_pattern[j] and sugarwater <= f:
                if sugarwater_max == -1 and sugar_max == -1:
                    sugarwater_max = sugarwater
                    sugar_max = sugar_pattern[j]
                    concentration = 100 * sugar_pattern[j] / sugarwater
                else:
                    if concentration < 100 * sugar_pattern[j] / sugarwater:
                        sugarwater_max = sugarwater
                        sugar_max = sugar_pattern[j]
                        concentration = 100 * sugar_pattern[j] / sugarwater

print("{} {}".format(sugarwater_max, sugar_max))

### FIXED CODE ###

# ABC074C - Sugar Water
# input
a, b, c, d, e, f = list(map(int, input().rstrip().split()))
A = a * 100
B = b * 100

# default values
x, y = min(a, b) * 100, 0  # density could be 0%
dens = y / x


# exhaustive search
for i in range(f // A + 1):
    for j in range(((f - A * i) // B) + 1):
        if i == 0 and j == 0:
            continue
        water = i * A + j * B
        rest = f - water
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                total = water + sugar

                if sugar / total > e / (e + 100):  # compare to e (the max density)
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x, y = total, sugar
print(x, y)
### BUGGY CODE ###

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

# TLE
# Amod = [A for A in map(lambda x: int(x) % M , input().split())]
# ans = 0
# for l in range(len(Amod)):
#     acm = 0
#     for r in range(l, len(Amod)):
#         acm = (acm + Amod[r]) % M
#         if acm == 0: ans += 1

for i, A in enumerate(map(int, input().split())):
    if i == 0: Asym = [A % M]
    else: Asym.append((Asym[-1] + A) % M)
# print(Asym)
    
ans = Asym.count(0)
for sym in set(filter(lambda x: Asym.count(x) > 0, Asym)):
    # print(sym, Asym.count(sym), ans)
    cnt = Asym.count(sym)
    ans +=  int(cnt * (cnt -  1) / 2)

print(ans)


### FIXED CODE ###

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

d_sym = {}
sym = 0

# refresh

ans = 0
for A in map(int, input().split()):
    sym = (sym + A) % M
    #
    if sym == 0: ans += 1
    # 
    if str(sym) in d_sym.keys(): d_sym[str(sym)] += 1
    else: d_sym[str(sym)] = 1

print(int(ans + sum([val * (val - 1) / 2 for val in d_sym.values()])))
### BUGGY CODE ###

N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        tmp = 4*n*h - N*n - N*h
        if tmp <= 0:
            continue
        w = N * h * n / tmp
        if w % 1 == 0:
            print(h, n, int(w))
            exit()

### FIXED CODE ###

N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*n*h - N*n - N*h > 0:
            if N * h * n % (4*n*h - N*n - N*h) == 0:
                print(h, n, N * h * n // (4*n*h - N*n - N*h))
                exit()
### BUGGY CODE ###

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

m = []
l = []
end = 0
for y in range(H):
    h = list(input())
    m.append(h)
    for x, w in enumerate(h):
        if w == '#':
            l.append([y, x])
            end += 1
HW = H * W
ans = 0
# print(m[2][0]) m[y][x]
while (end < HW):
    nl = []
    for ll in l:
        if (0 < ll[1]):
            if (m[ll[0]][ll[1] - 1] == '.'):
                m[ll[0]][ll[1] - 1] = '#'
                end += 1
                nl.append([ll[0], ll[1] - 1])

        if (ll[1] < W - 1):
            if (m[ll[0]][ll[1] + 1] == '.'):
                m[ll[0]][ll[1] + 1] = '#'
                end += 1
                nl.append([ll[0], ll[1] + 1])

        if (0 < ll[0]):
            if (m[ll[0] - 1][ll[1]] == '.'):
                m[ll[0] - 1][ll[1]] = '#'
                end += 1
                nl.append([ll[0] - 1, ll[1]])

        if (ll[0] < H - 1):
            if (m[ll[0] + 1][ll[1]] == '.'):
                m[ll[0] + 1][ll[1]] = '#'
                end += 1
                nl.append([ll[0] + 1, ll[1]])

    l = nl
    ans += 1

print(ans)



### FIXED CODE ###



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

m = []
l = []
end = 0
for y in range(H):
    h = list(input())
    m.append(h)
    for x, w in enumerate(h):
        if w == '#':
            l.append([y, x])
            end += 1
HW = H * W
ans = 0
# print(m[2][0]) m[y][x]
while (end < HW):
    nl = []
    for ll in l:
        if (0 < ll[1]):
            if (m[ll[0]][ll[1] - 1] == '.'):
                m[ll[0]][ll[1] - 1] = '#'
                end += 1
                nl.append([ll[0], ll[1] - 1])

        if (ll[1] < W - 1):
            if (m[ll[0]][ll[1] + 1] == '.'):
                m[ll[0]][ll[1] + 1] = '#'
                end += 1
                nl.append([ll[0], ll[1] + 1])

        if (0 < ll[0]):
            if (m[ll[0] - 1][ll[1]] == '.'):
                m[ll[0] - 1][ll[1]] = '#'
                end += 1
                nl.append([ll[0] - 1, ll[1]])

        if (ll[0] < H - 1):
            if (m[ll[0] + 1][ll[1]] == '.'):
                m[ll[0] + 1][ll[1]] = '#'
                end += 1
                nl.append([ll[0] + 1, ll[1]])

    l = nl
    ans += 1

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

#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))
c = 0
for j in range(n):
  if p[j] == min(p[:j+1]):
    c += 1
print(c)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
c = 0
m = n + 1
for i in p:
  if i < m:
    c += 1
    m = i
print(c)