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

"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import numpy as np

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

N, *A = map(int, read().split())
B = sorted(A)
ans=[]
for i in B:
    ans.append(A.index(i)+1)
print(*ans, sep=' ')

### FIXED CODE ###

"""
author : halo2halo
date : 18,Oct,2019
"""

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


N = int(readline())
A = [int(x) for x in readline().split()]
ans = [None]*N

for i, a in enumerate(A):
    ans[a-1] = i+1


print(*ans)
### 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()))

a.sort()
b.sort()
c.sort()

from bisect import bisect_left, bisect_right

def C(x):
    # count "abc <= x"
    ret = 0
    for aa in a:
        for bb in b:
            idx = bisect_right(c, x - aa - bb)
            ret += idx
    return ret

kk = x * y * z - k + 1
lb = 0
ub = (10 ** 10) * 4
while ub - lb > 1:
    mid = (ub + lb) // 2
    if C(mid) >= kk:
        ub = mid
    else:
        lb = mid

kth = ub


l = []
for aa in a:
    for bb in b:
        idx = bisect_left(c, kth - aa - bb)
        # print(aa, bb, idx)
        for i in range(idx, z):
            l.append(aa + bb + c[i])


l.sort(reverse=True)
for ll in l:
    print(ll)


### FIXED CODE ###



if __name__ == '__main__':
    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()))

    bc = []
    for bb in b:
        for cc in c:
            bc.append(bb + cc)
    bc.sort()

    from bisect import bisect_left

    def C(x):
        # count "abc >= x"
        ret = 0
        for aa in a:
            idx = bisect_left(bc, x - aa)
            ret += len(bc) - idx
        return ret

    lb = 0
    ub = (10 ** 10) * 3 + 1
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if C(mid) >= k:
            lb = mid
        else:
            ub = mid

    kth = lb

    l = []
    for aa in a:
        idx = bisect_left(bc, kth - aa)
        for i in range(idx, len(bc)):
            l.append(aa + bc[i])

    l.sort(reverse=True)
    l = l[:k]
    for ll in l:
        print(ll)
### BUGGY CODE ###

num = input().split(' ')
num_data = [int(num[i]) for i in range(3)]
cost = [0 for i in range(num_data[0] - 1)]
for i in range(num_data[0] - 1):
    for l in range(i + 1, num_data[0]):
        result = min(abs(i - l),abs(i - num_data[1] + 1) + 1 + abs(l - num_data[2] + 1),abs(i - num_data[2] + 1) + 1 + abs(l - num_data[1] + 1))
        cost[result - 1] += 1
for per in cost:
    print(per)


### FIXED CODE ###

def main():
    n,x,y = map(int,input().split(' '))
    cost = [0 for i in range(n - 1)]
    for i in range(n - 1):
        for l in range(i + 1, n):
            result = min(abs(i - l),abs(i - x + 1) + 1 + abs(l - y + 1),abs(i - y + 1) + 1 + abs(l - x + 1))
            cost[result - 1] += 1
    for per in cost:
        print(per)

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

import numpy as np

N = int(input())

inp = map(int,input().split(' '))

A = [int(i) for i in inp]

for i in range(N):
    B = np.hstack(([0],np.delete(A, i),[0]))
    X = [np.abs(B[j] - B[j+1]) for j in range(N)]
    print(int(np.sum(X)))

### FIXED CODE ###

import numpy as np

N = int(input())

inp = map(int,input().split(' '))

A = [0] + [int(i) for i in inp] + [0]
s = np.sum(np.abs(np.diff(A,n=1)))

for j in range(1,N+1):
    df = np.abs(A[j+1]-A[j-1]) - np.abs(A[j]-A[j-1]) - np.abs(A[j+1]-A[j])
    print(int(s+df))
### BUGGY CODE ###

power = 1
x = int(input())
for a in range(1, x + 1):
  power = power * a
  
power = power % (10**9 + 7)
print(power)

### FIXED CODE ###

power = 1
x = int(input())
for a in range(1, x + 1):
  power = (power * a) % (10**9 + 7)

print(power)
### BUGGY CODE ###

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

limit=10**9+7

ans=0
for i in range(N-1):
    ans+=(A[i]*(sum(A[i+1:])%limit))
    ans=ans%limit
print(ans)

### FIXED CODE ###

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

limit=10**9+7
S=[0]
for i in range(N):
    A[i]=A[i]%limit
for i in range(1,N):
    S.append((S[i-1]+A[-i])%limit)
ans=0
for i in range(N-1):
    ans+=A[i]*S[-1-i]
    ans=ans%limit
print(ans)
### BUGGY CODE ###

from collections import deque
def bfs(v):
    todo = deque()
    todo.append(v)
    seen[v] = 0
    while len(todo) > 0:
        v = todo.popleft()
        d = seen[v]
        for w in graph[v]:
            if seen[w] != -1:
                continue
            seen[w] = d + 1
            todo.append(w)


N, X, Y = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i].append(i+1)
    graph[i+1].append(i)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0 for _ in range(N)]
for i in range(N-1):
    seen = [-1 for _ in range(N)]
    bfs(i)
    for j in range(i+1, N):
        cnt[seen[j]] += 1

for i in range(1, N):
    print(cnt[i])

### FIXED CODE ###

from collections import deque
def bfs(v):
    todo = deque()
    todo.append(v)
    seen[v] = 0
    while len(todo) > 0:
        v = todo.popleft()
        d = seen[v]
        for w in graph[v]:
            if seen[w] != -1:
                continue
            seen[w] = d + 1
            todo.append(w)


N, X, Y = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i].append(i+1)
    graph[i+1].append(i)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0 for _ in range(N)]
for i in range(N-1):
    seen = [-1 for _ in range(N)]
    bfs(i)
    for j in range(i+1, N):
        cnt[seen[j]] += 1

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

import numpy as np

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

counter = np.bincount(A)

ans = []
for i in range(len(A)):
    counter_i = counter.copy()
    counter_i[A[i]] -=1
    sum_i = sum(counter_i * (counter_i -1) //2)
    ans.append(sum_i)
    
print(*ans, sep="\n")

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.array(read().split(), np.int64)
counter = np.bincount(A)
 
total = (counter * (counter - 1)).sum() // 2
answer = (total - (counter - 1))[A]
 
print('\n'.join(answer.astype(str)))
### BUGGY CODE ###

N = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if j - i == a[j] + a[i]:
            ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
a = [int(x) for x in input().split()]
l = [0]*N
r = [0]*N
for i in range(N):
    l[i] = a[i] + i + 1
    r[i] = i + 1 - a[i]
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    d[r[i]] += 1
ans = 0
for i in range(N):
    d[r[i]] -= 1
    ans += d[l[i]]
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

n, q = map(int,input().split())
g = [[] for _ in range(n+1)]
for  _ in range(n-1):
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)
points = [0]*(n+1)
for _ in range(q):
    p, x = map(int,input().split())
    points[p] += x
# print(g)
# print(points)
def dfs(e,preve):
    for nexte in g[e]:
        # print(nexte)
        if nexte != preve:
            points[nexte] = points[nexte] + points[e]
            dfs(nexte,e)
dfs(1,-1)
print(*points[1:])



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline()[:-1]

n, q = map(int,input().split())
g = [[] for _ in range(n+1)]
for  _ in range(n-1):
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)
points = [0]*(n+1)
for _ in range(q):
    p, x = map(int,input().split())
    points[p] += x
# print(g)
# print(points)
def dfs(e,preve = -1):
    for nexte in g[e]:
        # print(nexte)
        if nexte == preve:
            continue
        points[nexte] = points[nexte] + points[e]
        dfs(nexte,e)
dfs(1)
print(*points[1:])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
tree=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)
cnt=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    cnt[p-1]+=x

def DFS(v,p_v):
    for next_v in tree[v]:
        if next_v==p_v:
            continue
        cnt[next_v]+=cnt[v]
        DFS(next_v,v)

DFS(0,-1)
print(*cnt)

### FIXED CODE ###

#「探索候補スタック」「探索済みリスト」「現在地点」の３点セットでとらえる
n,q=map(int,input().split())
mat=[set() for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    mat[a-1].add(b-1)
    mat[b-1].add(a-1) # プラスした要素
count=[0]*n
for _ in range(q):
    p,score=map(int,input().split())
    count[p-1]+=score

stack=[[0,0,-1]]
while stack:
    # print(stack)
    num,cnt,pr=stack.pop()
    count[num]+=cnt
    for k in mat[num]:
        if k==pr:
            continue
        stack.append([k,count[num],num])
print(*count)
### BUGGY CODE ###

from collections import deque
import sys

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

an=[0]*(n-1)
tg = deque([1])
wwk =deque([])
con =0

while con<=m*2:
    while len(tg)!=0:
        itg = tg.pop()
        wk =deque(abl[itg-1])
        for j in range(len(wk)):
            iwk=wk.pop()
            con += 1
            if an[iwk-2]==0 and iwk!=1:
                an[iwk-2]=itg
                wwk.append(iwk)
            if all(an):
                print('Yes')
                for j in an:
                    print(j)
                sys.exit()
        
    tg=deque(wwk)
    wwk =deque([])

print('No')

### FIXED CODE ###

def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()
### BUGGY CODE ###

import itertools

N, C = map(int, input().split())
D = []
for _ in range(C):
    D.append(list(map(int, input().split())))
c = []
for _ in range(N):
    c.append(list(map(lambda x: int(x) - 1, input().split())))


min_diff = float("inf")
for ccs in itertools.permutations(range(C), 3):
    diff = 0
    for i in range(N):
        for j in range(N):
            diff += D[c[i][j]][ccs[(i + j) % 3]]
    min_diff = min(min_diff, diff)

print(min_diff)


### FIXED CODE ###

import itertools

N, C = map(int, input().split())
# N, C = 500, 30

D = []
for _ in range(C):
    D.append(list(map(int, input().split())))
    # D.append([100] * C)

diff_by_pos_color_pair = [[0 for _ in range(C)] for _ in range(3)]
for i in range(N):
    for j, color_from in enumerate(map(lambda x: int(x) - 1, input().split())):
        # for j, color_from in enumerate([0] * N):
        pos = (i + j) % 3
        for color_to in range(C):
            diff_by_pos_color_pair[pos][color_to] += D[color_from][color_to]


min_diff = float("inf")
for ccs in itertools.permutations(range(C), 3):
    diff = 0
    for pos, color in enumerate(ccs):
        diff += diff_by_pos_color_pair[pos][color]
    min_diff = min(min_diff, diff)

print(min_diff)
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
from decimal import Decimal

mod = 998244353
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

n = I()
A = LI()
ret = 1
flg = 0
for a in A:
    if a == 0:
        print(0)
        exit()
    ret *= a
    if ret > 10 ** 18:
        flg = 1

if flg:
    print(-1)
else:
    print(ret)

### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul

mod = 10 ** 9 + 7
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
A = LI()
ret = 1
for i in range(n):
    if A[i] == 0:
        print(0)
        exit()

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

print(ret)
### BUGGY CODE ###

N = int(input())
X = list(map(int,input().split()))
MOD = 10 ** 9 + 7
goal = X[-1]
ans = goal - X[0]
x = 1
count = 2
for i in X[1:N-1]:
    tmp = goal - i
    ans = ((ans * count % MOD) + ((x*tmp)%MOD)) % MOD
    x *= count % MOD
    count += 1
print(ans)

### FIXED CODE ###

def main():
    N = int(input())
    X = list(map(int,input().split()))
    MOD = 10 ** 9 + 7
    goal = X[-1]
    ans = goal - X[0]
    fact = [1]
    fact_inv = [1]
    for i in range(10**5+5):
        new_fact = fact[-1]*(i+1)%MOD
        fact.append(new_fact)
    count = 1
    for i in range(1,N-1):
        count += 1
        tmp = goal - X[i]
        ans = ((ans * count) + ((fact[i] * tmp))) % MOD  
    print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
for h in range(1, 3500+1):
    for n in range(h, 3500+1):
        a = (h * n * N)
        b = (4 * h * n - n * N - h * N)
        if b > 0 and a % b == 0:
            print(h, n, a // b)
            quit()


### FIXED CODE ###

N = int(input())
if N % 2 == 0:
    print(N // 2, N, N)
    quit()
for h in range(1, 3500+1):
    hN = h * N
    for n in range(h, 3500+1):
        b = (4 * h * n - n * N - hN)
        if b <= 0:
            continue
        a = (n * hN)
        if a % b == 0:
            print(h, n, a // b)
            quit()
### BUGGY CODE ###

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
a0=input()
a0=a0.split()
a=[int(s) for s in a0]
a1=[int(s) for s in a0]
for f in range(k):
    for x in range(n):
        c=0
        for i in range(n):
            if a1[i]-abs(x-i)>=0:
                c=c+1
        a[x]=c
    a1=[int(s) for s in a]
    if sum(a)==n**2:
        break
a=[str(s) for s in a]
a=" ".join(a)
print(a)

### FIXED CODE ###

from numba import njit

@njit(cache=True)
def aaa(n,k,a):
    for f in range(k):
        a1=[0]*(n+1)
        for x in range(n):
            y=max(0,x-a[x])
            a1[y]=a1[y]+1    
            z=min(n-1,x+a[x])
            a1[z+1]=a1[z+1]-1
        a[0]=a1[0]
        for x in range(1,n):    
            a[x]=a[x-1]+a1[x]
        if a==[n]*n:
            break
    return a

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
a0=input()
a0=a0.split()
a=[int(s) for s in a0]

b=aaa(n,k,a)
for i in range(n):
    print(b[i])
### BUGGY CODE ###

import bisect

n, m = map(int, input().split())
py_dict = {}
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  if p not in py_dict:py_dict[p] = [y]
  else:py_dict[p].insert(bisect.bisect_left(py_dict[p],y),y)
  cityi_by_year.append([p,y])
  
for p, y in cityi_by_year:
  idx = bisect.bisect_left(py_dict[p],y)
  print('0'*(6-len(str(p))) + str(p) + '0'*(6-len(str(idx+1))) + str(idx+1))


### FIXED CODE ###

import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))
### BUGGY CODE ###

a,b,k=map(int,input().split());print(*[i for i in range(a,b+1)if(i>=a+k)*b-k<i])

### FIXED CODE ###

a,b,k=map(int,input().split());r=range(a,b+1);print(*sorted(set(r[:k])|set(r[-k:])),sep='\n')
### BUGGY CODE ###

import numpy as np

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

ans = 0

for i, a in enumerate(A):
    ans += np.sum(A[i+a+1:] == np.arange(1, N-i-a))
    """
    for j, b in enumerate(A[i+a+1:]):
        if j + 1 == b:
            ans += 1
    """
print(ans)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
ai = defaultdict(int)
aj = defaultdict(int)

for i, a in enumerate(A):
    ai[i + 1 + a] += 1
    aj[i + 1 - a] += 1

ans = 0
for k, v in ai.items():
    ans += v * aj[k]
print(ans)
### BUGGY CODE ###

N=list(input())

count=0

for i in range(len(N)-3):
    for j in range(i+4,len(N)+1):
        B=int(''.join(N[i:j]))
        if B%2019==0:
            count+=1
        else:
            pass
print(count)   

### FIXED CODE ###

s=input()
n=len(s)
a=0
t=1
d=[1]+[0]*2018
 
for i in range(n):
    a+=int(s[n-1-i])*t
    a%=2019
    t*=10
    t%=2019
    
    d[a]+=1

ans=0
for i in d:
    ans+=i*(i-1)//2
 
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))
keep = 1

for i in range(k):
    keep *= A[i]


for j in range(n - k):
    if keep * A[k + j] > keep*A[j]:
        print("Yes")
    else:
        print("No")
    keep = keep * A[k + j] / A[j]


### FIXED CODE ###

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

for j in range(n - k):
    if A[k + j] > A[j]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###


# -*- coding: utf-8 -*-
import random
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))

def warshall_floyd(g):
    d = g
    N = len(g)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


def slv(N, M, L, ABC, Q, ST):
    g = [[sys.maxsize]*(N) for _ in range(N)]
    for i in range(N):
        g[i][i] = 0
    for a, b, c in ABC:
        if c > L:
            continue
        g[a-1][b-1] = c
        g[b-1][a-1] = c
    
    d = warshall_floyd(g)
    gg = [[sys.maxsize]*(N) for _ in range(N)]
    for u in range(N):
        for v in range(N):
            if d[u][v] <= L:
                gg[u][v] = 1
    dd = warshall_floyd(gg)

    for s, t in ST:
        d = dd[s-1][t-1]
        if d != sys.maxsize:
            print(d-1)
        else:
            print(-1)



def main():
    N, M, L = read_int_n()
    ABC = [read_int_n() for _ in range(M)]
    Q = read_int()
    ST = [read_int_n() for _ in range(Q)]
    
    (slv(N, M, L, ABC, Q, ST))

    # N = 300
    # M = (N*(N-1))//2
    # L = random.randint(1, 10**9)
    # ABC = []
    # for i in range(1, N+1):
    #     for j in range(i+1, N+1):
    #         ABC.append([i, j, random.randint(1, 10**9)])
    
    # ST = []
    # for i in range(1, N+1):
    #     for j in range(1, N+1):
    #         if i == j:
    #             continue
    #         ST.append([i, j])
    # Q = len(ST)
    # # (slv(N, M, L, ABC, Q, ST))

    # print(N, M, L)
    # for a, b, c in ABC:
    #     print(a, b, c)
    # print(Q)
    # for s, t in ST:
    #     print(s, t)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    n, m, l = list(map(int, input().rstrip('\n').split()))
    INF = 10 ** 11
    w = [[INF] * n for _ in range(n)]
    wl = [[INF] * n for _ in range(n)]

    for i in range(n):
        w[i][i] = 0

    for i in range(m):
        a, b, c = list(map(int, input().rstrip('\n').split()))
        if c <= l:
            w[a - 1][b - 1] = c
            w[b - 1][a - 1] = c

    for i in range(n):
        for j in range(n):
            for k in range(n):
                w[j][k] = min(w[j][k], w[j][i] + w[i][k])

    for i in range(n):
        for j in range(n):
            if w[i][j] <= l:
                wl[i][j] = 1
    for i in range(n):
        for j in range(n):
            for k in range(n):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        if wl[s-1][t-1] == INF:
            print(-1)
        else:
            print(wl[s-1][t-1] - 1)


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

from collections import deque 
import sys
input = sys.stdin.readline
def main():
    q = deque([])
    h,w=map(int,input().split())
    a=[list(input()) for i in range(h)]
    x=[[-1,0],[1,0],[0,-1],[0,1]]
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                for k in x:
                    if 0<=i+k[0]<h and 0<=j+k[1]<w and a[i+k[0]][j+k[1]]==".":
                        a[i+k[0]][j+k[1]]="0"
                        q.append([i+k[0],j+k[1],1])
    ans=0
    while q:
        v=q.popleft()
        for k in x:
            if 0<=v[0]+k[0]<h and 0<=v[1]+k[1]<w and a[v[0]+k[0]][v[1]+k[1]]==".":
                a[v[0]+k[0]][v[1]+k[1]]="0"
                q.append([v[0]+k[0],v[1]+k[1],v[2]+1])
                ans=v[2]+1
    print(ans)
if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque 
import sys
input = sys.stdin.readline
def main():
    q = deque([])
    h,w=map(int,input().split())
    a=[list(input()) for i in range(h)]
    x=[[-1,0],[1,0],[0,-1],[0,1]]
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                for k in x:
                    if 0<=i+k[0]<h and 0<=j+k[1]<w and a[i+k[0]][j+k[1]]==".":
                        a[i+k[0]][j+k[1]]="0"
                        q.append([i+k[0],j+k[1],1])
    ans=0
    while q:
        v=q.popleft()
        for k in x:
            if 0<=v[0]+k[0]<h and 0<=v[1]+k[1]<w and a[v[0]+k[0]][v[1]+k[1]]==".":
                a[v[0]+k[0]][v[1]+k[1]]="0"
                q.append([v[0]+k[0],v[1]+k[1],v[2]+1])
                ans=v[2]+1
    print(ans)
if __name__ == '__main__':
    main()