Harryxun/stf_run huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def com(com_n, com_r):
    return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md
def way(h, w):
    if h < 0 or w < 0:
        return 0
    else:
        return com(h + w, h)

# combinationの準備
# md>n_maxの条件
md = 10 ** 9 + 7
n_max = 100
fac = [1]
inv = [1] * (n_max + 1)
k_fac_inv = 1
for i in range(1, n_max + 1):
    k_fac_inv = k_fac_inv * i % md
    fac.append(k_fac_inv)
k_fac_inv = pow(k_fac_inv, md - 2, md)
for i in range(n_max, 1, -1):
    inv[i] = k_fac_inv
    k_fac_inv = k_fac_inv * i % md

def main():
    h, w, n = MI()
    rc = [LI1() for _ in range(n)]
    # i番目の壁まで無傷で来る方法の数
    # (全ルート)－(i-1までの壁にぶつかる分)
    rc.sort(key=lambda x: x[0] + x[1])
    dp = [0] * n
    for i, (r, c) in enumerate(rc):
        dp[i] = way(r, c) - sum(v * way(r - pr, c - pc) for v, (pr, pc) in zip(dp[:i], rc[:i]))
    h, w = h - 1, w - 1
    ans = way(h, w) - sum(v * way(h - r, w - c) for v, (r, c) in zip(dp, rc))
    print(ans)

main()


### FIXED CODE ###

def f():
    h, w, n = map(int, input().split())
    md = 10 ** 9 + 7
    k = [list(map(int, input().split())) for _ in range(n)] + [[h, w]]

    # 壁をマンハッタン距離順に
    k.sort(key=lambda x: x[0] + x[1])

    # 階乗と逆元とコンビネーションを事前準備
    fct = [1]
    re_fct = []
    fct_i = 1
    for i in range(1, h + w + 1):
        fct_i = fct_i * i % md
        fct += [fct_i]
    # fct_i**(md-2)が逆元re_i
    re_i = 1
    p = md - 2
    while p:
        if p & 1:
            re_i = re_i * fct_i % md
        p >>= 1
        fct_i = fct_i ** 2 % md
    for i in range(h + w, -1, -1):
        re_fct += [re_i]
        re_i = re_i * i % md
    re_fct = re_fct[::-1]
    cmb = lambda a, b: fct[a] * re_fct[b] * re_fct[a - b] % md

    # こっから本体
    dp = [0] * (n + 1)
    for i, [r, c] in enumerate(k):
        dpi = cmb(r + c - 2, r - 1) % md
        for j in range(i):
            dr, dc = r - k[j][0], c - k[j][1]
            if dr >= 0 and dc >= 0:
                dpi = (dpi - dp[j] * cmb(dr + dc, dr)) % md
        dp[i] = dpi
    print(dp[-1])


f()
x = int(input())
h = 0
fh = x // 500
h += fh * 1000
r = x % 500
f = r // 5
h += f * 5
print(h)

### FIXED CODE ###

s = input()
if (s[2] == s[3]) & (s[4] == s[5]):
    print('Yes')
else:
    print('No')
x=int(input())
print(x//3600 a%3600//60 x%60)


### FIXED CODE ###

x=int(input())
print(x//3600,x%3600//60,x%60,sep=':')
l = list(input())
ans = []
ans.append(0)
count = 0
for i in range(len(l)):
  if l[i] == ("A" or "G" or "T" or "C"):
    count += 1
  else:
    ans.append(count)
    count = 0
    
print(max(ans)))
  

### FIXED CODE ###

l = list(input())
ans = []
ans.append(0)
count = 0
for i in range(len(l)):
  if l[i] == "A" or  l[i] == "G" or  l[i] == "T" or  l[i] == "C":
    count += 1
  else:
    ans.append(count)
    count = 0
    
ans.append(count)
print(max(ans))
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
import functools
def gcd_list(x):
    return functools.reduce(math.gcd, x)

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

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if (j != i):
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

### FIXED CODE ###

#!/usr/bin/env python3
#C
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

N = int(input())
A = list(map(int,input().split()))
L=[0]*(N+2)
R=[0]*(N+2)
L[0] = A[0]
R[N-1] = A[N-1]
for i in range(1,N):
    L[i] = gcd(L[i-1],A[i])
for i in range(N-2,-1,-1):
    R[i] = gcd(R[i+1],A[i])

ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i-1],R[i+1]))
print(ans)
string = input()
number = int(string[0])
print(number^2*3.14159, number*2*3.14159)


### FIXED CODE ###

import math

PI = math.pi
string = input()
number = string.split(' ')
r = float(number[0])
print(r*r*PI, r*2*PI)
def main():
    import numpy as np
    n = int(input())
    graph = np.zeros((n,n))
    come = np.ones(n)*-1
    for i in range(n-1):
        u,v,w = map(int,input().split())
        graph[u-1][v-1] = graph[v-1][u-1] = w
    que = [0]
    come[0] = 0
    while len(que)>0:
        s = que.pop(0)
        for i,nv in enumerate(graph[s]):
            if nv!=0:
                if come[i]!=-1:
                    continue
                if nv%2==0:
                    come[i]=come[s]
                else:
                    come[i]=(come[s]+1)%2
                que.append(i)
    for i in range(n):
        print(int(come[i]))
            
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    ki = {}
    for i in range(1,n+1):
        ki[i] = []
    for i in range(n-1):
        u,v,w = map(int,input().split())
        ki[u] += [[v,w%2]]
        ki[v] += [[u,w%2]]
    cl = [-1 for i in range(n)]
    cl[0] = 0
    que = [0]
    while len(que)>0:
        q = que.pop(0)
        for v in ki[q+1]:
            if cl[v[0]-1] != -1:
                continue
            if v[1]==1:
                cl[v[0]-1] = (cl[q]+1)%2
                que.append(v[0]-1)
            else:
                cl[v[0]-1] = cl[q]
                que.append(v[0]-1)
    for i in range(n):
        print(cl[i])

if __name__ == "__main__":
    main()
n = int(input())
a = [int(s) for s in input().split()]
tmpa = a 
tmpa.sort()
for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

### FIXED CODE ###

n = int(input())

print(3 * (n ** 2))
import sys
sys.setrecursionlimit(10000)

def gcd(a, b):
    if b == 1:
        return 1
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

def lcm(A, n):
    if n == 2:
        return A[0]* (A[1] // gcd(A[0], A[1]))
    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
    rec = lcm(A, n-1)
    return rec * (A[n-1] // gcd(rec, A[n-1]))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
ans = lcm(a, n)
print(str(ans))

#通るコード
#n = int(input())
#T1 = int(input())
#for i in range(n-1):
#    T2 = int(input())
#    T1 = T1*T2 // gcd(T1, T2)
#print(str(T1))

### FIXED CODE ###

def gcd(a, b):
    if b == 1:
        return 1
    # a > b　を仮定
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

#def lcm(A, n):
#    if n == 2:
#        return A[0]*A[1] // gcd(A[0], A[1])
#    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
#    a = lcm(A, n-1)
#    return a* A[n-1] // gcd(a, A[n-1])

n = int(input())
#a = []
T1 = int(input())
for i in range(n-1):
    T2 = int(input())
    T1 = T1*T2 // gcd(T1, T2)
    #a.append(int(input()))
#a.sort(reverse = True)
#ans = lcm(a, n)
print(str(T1))
n = int(input())
x = 10**6
li = [True for i in range(x)]
li[0] = False
li[1] = False

for i in range(int(x**0.5)+1):
    if li[i]:
        m = 2
        while(i*m<=x):
            li[i*m] = False
            m += 1
#print(li)
for i in range(x):
    if i>=n and li[i]:
        print(i)
        break

### FIXED CODE ###

n = int(input())
x = 10**6
li = [True for i in range(x+10)]
li[0] = False
li[1] = False

for i in range(int(x**0.5)+1):
    if li[i]:
        m = 2
        while(i*m<=x):
            li[i*m] = False
            m += 1
#print(li)
for i in range(x):
    if i>=n and li[i]:
        print(i)
        break
a = list(map(float,input().split(),9))
answer = float(a[0] * a[1],9)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)

### FIXED CODE ###

a = list(map(float,input().split()))
answer = float(a[0] * a[1]/2)
print(answer)
if a[2] == a[0]/2:
  if a[3] == a[1]/2:
    print(1)
  else:
    print(0)
else:
  print(0)
k = int(input())
que = []
for i in range(10):
  que.append(i)
while(len(que) < k-1):
  x = que[0]
  que.remove(x)
  if (x%10 != 0):
    que.append((10*x) + (x%10) - 1)
    que.append((10*x) + (x%10))
  if (x%10 != 9):
    que.append((10*x) + (x%10) + 1)
print(que[k-1])

### FIXED CODE ###

k = int(input())
que = []
for i in range(1,10):
  que.append(i)
ct = 0
while(len(que) < k):
  ct += 1
  value = que[0]
  que.remove(value)
  for i in [-1,0,1]:
    if 0 <= (value%10) + i and (value%10) + i <= 9:
      tmp = 10*value + (value%10) + i
      que.append(tmp)  
print(que[k-1-ct])
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# a,b,c = map(int, input().split())
# n = int(input())
# a = list(map(int,input().split()))
s,t = input().split()
a,b = map(int, input().split())
u = int(input())
if u == s: print(a-1,b)
else: print(a,b-1)
print(ans)



### FIXED CODE ###

# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# a,b,c = map(int, input().split())
# n = int(input())
# a = list(map(int,input().split()))
s,t = input().split()
a,b = map(int, input().split())
u = input()
if u == s: print(a-1,b)
else: print(a,b-1)
import sys
from collections import deque, OrderedDict
inputs = sys.stdin.readlines()

n = int(inputs[0])
edges = [tuple(map(int, x.split())) for x in inputs[1:]]

tree, colors = [[] for _ in range(n)], OrderedDict()
for x, y in edges:
    tree[x-1].append(y-1)
    tree[y-1].append(x-1)
    colors[(x-1, y-1)] = 0
use_color = max(len(x) for x in tree)

queue, passed = deque([0]), set()
while queue:
    x = queue.popleft()
    passed.add(x)
    pallet = [i for i in range(use_color)][::-1]
    for y in tree[x]:
        if y in passed:
            if (x, y) in colors:
                pallet.remove(colors[(x, y)])
            if (y, x) in colors:
                pallet.remove(colors[(y, x)])
            continue
        colors[(x, y)] = pallet.pop()
        queue.append(y)

print(use_color)
for c in colors.values():
    print(c+1)

### FIXED CODE ###

from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[n]-=i
x=sum(a)//n
ans=0
for i in a:
  ans+=abs(i-b)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]
c=[0]
d=[0]
e=[0]
count=0
count2=0
count3=0
count4=0
for i in range(n):
  a[i]-=i
a.sort()
for i in range(n-1):
  count+=a[i+1]-a[i]
  count3+=a[n-i-1]-a[n-i-2]
  b.append(count)
  d.append(count3)
for i in range(n-1):
  count2+=b[i+1]
  count4+=d[i+1]
  c.append(count2)
  e.append(count4)
ans=10**18
for i in range(n):
  ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1)+e[-1]-e[n-i-1]-d[n-i-1]*i)
print(ans)
import sys
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=map(int,input().split())
xs,qs = [],[]
for _ in range(n):
    s,t,x=map(int,input().split())
    s,t,x=s-x,t-x,x
    xs += [(s,1,x), (t,0,x)]
for _ in range(Q):
    qs.append(int(input()))

xs.sort(key=lambda x:x[0])

### FIXED CODE ###

a, b = map(int, input().split())
print((a*3 + b)//2)
let n = read_int ()

let () = n / 2 + (n mod 2) |> print_int; print_string "\n"

### FIXED CODE ###

N = int(input())
print(int(N / 2 if not N % 2 else N // 2 + 1))
M = 1000000007
n = int(input())
a = list(map(int,input().split()))
S = [0]
for i in range(n):
 S.append(S[-1]+a[i])%M
sum = 0
for i in range(n-1):
 sum += (a[i]*(S[n]-S[i+1]))%M
print(sum%M)


### FIXED CODE ###

M = 1000000007
n = int(input())
a = list(map(int,input().split()))
S = [0]
for i in range(n):
 S.append((S[-1]+a[i])%M)
sum = 0
for i in range(n-1):
 sum += (a[i]*(S[n]-S[i+1]))%M
print(sum%M)
x = int(input())

b = 0
while True:
    if int((x + b ** 5) ** 0.2) == (x + b ** 5) ** 0.2:
        a = int((x + b ** 5) ** 0.2)
        break
    elif int((x - b ** 5) ** 0.2) == (x - b ** 5) ** 0.2:
        a = int((x - b ** 5) ** 0.2)
        b *= -1
        break
    else:
        b += 1

print(str(a) + " " + str(b))


### FIXED CODE ###

x = int(input())

flag = False
for a in range(-200, 200):
    for b in range(-200, 200):
        if a ** 5 - b ** 5 == x:
            flag = True
            print(str(a) + " " + str(b))
            break
    if flag:
        break
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

if a >= 0 and c >= 0:
    print(b * d)
    sys.exit(0)

if b <= 0 and d <= 0:
    print(a * c)
    sys.exit(0)

if a <= 0 <= b and c <= 0 <= d:
    print(max(a * c, b * d))
    sys.exit(0)

if b <= 0 and c >= 0:
    pritn(b * c)
    sys.exit(0)

if d <= 0 and a >= 0:
    print(a * d)
    sys.exit(0)

if a <= 0 <= b and d <= 0:
    print(0)
    sys.exit(0)

if c <= 0 <= d and b <= 0:
    print(0)
    sys.exit(0)


### FIXED CODE ###

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

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

ans = max(a * c, a * d, b * c, b * d)

if ans < 0 and (a <= 0 <= b or c <= 0 <= d):
    print(0)
else:
    print(ans)
N, A, B = map(int input().split())
res = 0
 
for i in range(N+1):
  if A <= sum([int(n) for n in str(i)]) <= B:
    res += 1
 
print(res)

### FIXED CODE ###

N, A, B = map(int, input().split())
res = 0
for i in range(N+1):
    if A <= sum([int(s) for s in str(i)]) <= B:
        res += i
print(res)
n = int(input())
lst = []

for item in range(n):
  goods.append(item)

goods = sorted(lst, reverse=True)
goods[0] = goods[0] // 2

print(sum(goods))

### FIXED CODE ###

n = int(input())
lst = []

for i in range(n):
  item = int(input())
  lst.append(item)

goods = sorted(lst, reverse=True)
goods[0] = goods[0] // 2

print(sum(goods))
from collections import defaultdict
import itertools
import math

def dfs(vum,s,visit,depth):
    # print('first')
    # print(s,depth,visit)
    if visit[s-1] >= 0:
        return visit
    visit[s-1] = depth
    # print(vum[s])
    for u in vum[s]:
        # print('now', str(u))
        if visit[u-1] >= 0:
            # print('skip', str(u))
            if visit[u-1] > depth:
                visit[u-1] = depth
                # print('update', str(u))
            continue
        s = u
        depth += 1
        visit = dfs(vum,s,visit,depth)
    return visit


def main():
    N,M = [int(x) for x in input().split()]
    vum = defaultdict(list)
    for i in range(M):
        a,b = [int(x) for x in input().split()]
        vum[a].append(b)
        vum[b].append(a)
        
    s = 1 # 現在地 (初期値はゴールを設定)
    visit = [-1]*len(vum) # 訪問リスト
    depth = 0 # 移動数(深さ)
    visit = dfs(vum,s,visit,depth)
    if -1 in visit:
        print('No')
        return
    else:
        print('Yes')
    for v in visit[1:]:
        print(v)

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict
import queue

def main():
    N,M = [int(x) for x in input().split()]
    vum = defaultdict(list)
    for i in range(M):
        a,b = [int(x) for x in input().split()]
        vum[a].append(b)
        vum[b].append(a)
        
    ### bfs ###
    q = queue.Queue()
    F = [-1]*N # 道標の先の部屋
    s = 1 # 始点
    step = 0
    while True:
        # print('s',str(s))
        for v in vum[s]:
            # print('v',str(v))
            if F[v-1] < 0:
                q.put(v)
                F[v-1] = s
        if q.empty():
            break
        # print(list(q.queue),V)
        s = q.get()

    if -1 in F[1:]:
        print('No')
    else:
        print('Yes')
        for d in F[1:]:
            print(d)

if __name__ == '__main__':
    main()
N, Q = map(int, input().split())

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

cnt = [0 for _ in range(N)]
for i in range(Q):
  p, x = map(int, input().split())
  cnt[p-1] += x


def dfs(now, bef):
  for i in edge[now-1]:
    if i != bef:
      cnt[i-1] += cnt[now-1]
      dfs(i, now)


dfs(1, -12345)
print(" ".join(map(str, cnt)))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)


def input(): return sys.stdin.readline()


N, Q = map(int, input().split())
ab = [[] for _ in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  ab[a-1].append(b)
  ab[b-1].append(a)

P = [0 for _ in range(N)]
for i in range(Q):
  p, x = map(int, input().split())
  P[p-1] += x


def dfs(p, par):
  for i in ab[p-1]:
    if i != par:
      P[i-1] += P[p-1]
      dfs(i, p)


dfs(1, -12345)
print(" ".join(map(str, P)))
a=[]
while True:
 n=input()
 if n=='0 ? 0':break
 a.append(n)
for s in a:
 t=s.split()
 if t[1]="/":
  print(t[0]//[1])
 else:
  b=eval(''.join(t))
  print(b)

### FIXED CODE ###

while 1:
 a=input()
 if'?'in a:break
 print(int(eval(a)))
import numpy as np
N=int(input())
S = input()

c=S.count
r,g,b=c('R'),c('G'),c('B')

ans = r*g*b

for i in range(N):
  for d in range(N):
    j = i+d
    k = j*d
    if k >= n:
      break
    if S[i] != S[j] and S[j] != S[k] and S[i] != S[i]:
      ans -= 1
    
print(ans)


### FIXED CODE ###

n = int(input())
s = input()
 
r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')
 
ans = r_cnt * g_cnt * b_cnt
 
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
print(ans)
a,t = input().split()

if a == "H":
  print(b)
else:
  if t == "D":
    print("H")
  else:
    print("D")


### FIXED CODE ###

a,t = input().split()

if a == "H":
  print(t)
else:
  if t == "D":
    print("H")
  else:
    print("D")
s = list(input())
for i in range[3]:
  if (s[i] == s[i+1] ):
  print('Bad')
  exit()
else:
  print('Good')


### FIXED CODE ###

S = list(input())
for i in range(3):
    if(S[i]==S[i+1]):
        print('Bad')
        exit()
else:
    print('Good')
def main():
    n, q = map(int, input().split())
    g = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v = map(int, input().split())
        g[u].append(v)
        g[v].append(u)

    f = [0 for _ in range(n + 1)]

    for _ in range(q):
        p, x = map(int, input().split())
        f[p] += x

    k = [0 for _ in range(n + 1)]
    vis = [False for _ in range(n + 1)]

    def c(n, p):
        if vis[n]:
            return
        vis[n] = True
        w = f[n] + p
        k[n] = w
        ch = g[n]
        for x in ch:
            c(x, w)

    c(1, 0)
    ans = ' '.join(map(str, k[1:]))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def c(i, p, f, g, k, vis):
    if vis[i]:
        return
    vis[i] = True
    w = f[i] + p
    k[i] = w
    ch = g[i]
    for x in ch:
        c(x, w, f, g, k, vis)


def main():
    import sys
    sys.setrecursionlimit(300000)
    n, q, *abpx = map(int, sys.stdin.read().split())

    g = [[] for _ in range(n + 1)]
    for u, v in zip(*[iter(abpx[:2 * (n - 1)])] * 2):
        g[u].append(v)
        g[v].append(u)

    f = [0 for _ in range(n + 1)]

    for p, x in zip(*[iter(abpx[2 * (n - 1):])] * 2):
        f[p] += x

    k = [0 for _ in range(n + 1)]
    vis = [False for _ in range(n + 1)]

    c(1, 0, f, g, k, vis)
    ans = ' '.join(map(str, k[1:]))
    print(ans)


if __name__ == '__main__':
    main()
N = str(input())
print("Yes","No")[N[0]!="7" and N[1]!="7" and N[2]!="7"]

### FIXED CODE ###

N = str(input())

if N[0]!="7" and N[1]!="7" and N[2]!="7":
    print("No")
else:
    print("Yes")
from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*H for _ in range(W)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

d = 0
while black_cells:
    # キューとして使うのでpop()ではなくpopleft()
    h, w = black_cells.popleft()  # 黒いセルの座標
    d = dist[h][w]
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        new_h = h + dy
        new_w = w + dx
        if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
            continue
        if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
            dist[new_h][new_w] = d+1
            black_cells.append((new_h, new_w))

print(d)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [list(input()) for i in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append([h, w, 0])

ans = 0
while len(black_cells) > 0:
    one_black_cell = black_cells.popleft()  # キューとして使うのでpop()ではなくpopleft()
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        nh = one_black_cell[0] + dy
        nw = one_black_cell[1] + dx
        d = one_black_cell[2]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if grid[nh][nw] == '.':
            grid[nh][nw] = '#'
            black_cells.append([nh, nw, d + 1])
        ans = d

print(ans)
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

N, K = LI()
S = str(input())
S = S + "2"
d1 = []
d0 = []
k = S[0]
if k=="0":
    d1.append(0)
cou = int(1)
for i in range(N):
    if S[i]!=S[i+1]:
        if S[i]=="0":
            d0.append(cou)
        if S[i]=="1":
            d1.append(cou)
        cou = int(1)
    else:
        cou +=1

#print(d1)
#print(d0)

ansC = []
t = 2*K+1
newN = len(d1)
if newN!=len(d0):
    d0.append(0)
sumd1 = [0]*(newN+t)
sumd0 = [0]*(newN+t)
for i in range(newN):
    sumd1[i+1] = d1[i]
    sumd0[i+1] = d0[i]
for i in range(newN+1):
    sumd1[i+1] += sumd1[i]
    sumd0[i+1] += sumd0[i]

for i in range(newN-K+1):
    ans = (sumd1[i+K+1]-sumd1[i]) + (sumd0[i+K]-sumd0[i])
    ansC.append(ans)

print(max(ansC))
#print(sumd1)
#print(sumd0)

### FIXED CODE ###

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

N, K = LI()
S = str(input())
S = S + "2"
d1 = []
d0 = []
k = S[0]
if k=="0":
    d1.append(0)
cou = int(1)
for i in range(N):
    if S[i]!=S[i+1]:
        if S[i]=="0":
            d0.append(cou)
        if S[i]=="1":
            d1.append(cou)
        cou = int(1)
    else:
        cou +=1

#print(d1)
#print(d0)

ansC = []
t = 2*K+1
newN = len(d1)
if len(d1)==1 or d0==[] or K>=N//2+1:
    ansC.append(N)

if newN!=len(d0):
    d0.append(0)
    d0.append(0)
sumd1 = [0]*(newN+t+5)
sumd0 = [0]*(newN+t+5)
for i in range(newN):
    sumd1[i+1] = d1[i]
    sumd0[i+1] = d0[i]
for i in range(newN+1):
    sumd1[i+1] += sumd1[i]
    sumd0[i+1] += sumd0[i]

#for i in range(max(newN-K+1,K)):
if ansC==[] and (newN - K + 1)>=1:
    for i in range(newN - K + 1):
        ans = (sumd1[i + K + 1] - sumd1[i]) + (sumd0[i + K] - sumd0[i])
        ansC.append(ans)
else:
    ansC.append(N)
print(max(ansC))
s = input()
pirnt(s[0:3]+'7'+s[4:])

### FIXED CODE ###

s = input()
print(s[:3]+'8'+s[4:])
num = input()
#num = str(code)

if num[0] == num[1] or num[1] == num[2] or num[2] == num[3]:
    print('Bad')
else:
    print('Good')

### FIXED CODE ###

num = input()
#num = str(code)

if num[0] == num[1] or num[1] == num[2] or num[2] == num[3]:
    print('Bad')
else:
    print('Good')
a,b,c = int(input())

print(c , end= " ")
print(a , end= " ")
print(b)

### FIXED CODE ###

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

print(c , end= " ")
print(a , end= " ")
print(b)