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

from heapq import heappop, heappush

N, M = map(int, input().split())
INF = 10**10

edges = [[] for _ in range(N * 3)]

for _ in range(M):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append(to + N)
    edges[fr + N].append(to + 2 * N)
    edges[fr + 2 * N].append(to)

S, T = map(int, input().split())
S -= 1
T -= 1

minDist = [INF] * (3 * N)
que = [(S, 0)]

while que:
    now, dist = heappop(que)

    if minDist[now] <= dist:
        continue
    minDist[now] = dist

    dist += 1

    for to in edges[now]:
        if minDist[to] > dist:
            heappush(que, (to, dist))

ans = minDist[T]

if ans == INF:
    print(-1)
else:
    print(ans // 3)

### FIXED CODE ###

def dijkstra(edge,start,end) :
    import heapq

    minCosts = [float('inf') for _ in range(len(edge))]

    nodeHeap = []
    heapq.heappush(nodeHeap, (0, start))  # (cost, node)

    while nodeHeap :
        cost, node = heapq.heappop(nodeHeap)

        if minCosts[node] <= cost :
            continue

        minCosts[node] = cost

        for nextNode , weight in edge[node] :
            newCost = cost + weight
            heapq.heappush(nodeHeap, (newCost, nextNode))
    dist = minCosts[endNode]
    if dist == float('inf') :
        return -1
    return dist

N , M = map(int,input().split())

# edges , costs
nodes = [[] for _ in range(3 * N)]

# 辺の入力
for _ in range(M) :
    fromNode , toNode = map(int,input().split())
    fromNode -= 1
    toNode -= 1
    fromNode *= 3
    toNode *= 3

    nodes[fromNode].append((toNode + 1,1))
    nodes[fromNode + 1].append((toNode + 2,1))
    nodes[fromNode + 2].append((toNode,1))

# スタート ゴール
startNode , endNode = map(int,input().split())
startNode -= 1
endNode -= 1
startNode *= 3
endNode *= 3

ans = dijkstra(nodes,startNode,endNode)

if ans == -1 :
    print(ans)
else :
    print(ans // 3)
### BUGGY CODE ###

n,m = map(int,input().split())
l = list(input())
l = l[::-1]
count = [-1]*(n+1)
count[0] = 0
check = 1
i = 0

while i < n+1:
    if count[i] != -1:
        a = -1
        for j in range(1,m+1):
            if i+j < n+1 and l[i+j] != "1":
                count[i+j] = check
                a = i+j
        
        check += 1
        if a == -1:
            print(-1)
            exit()
        else:
            i = a
        
        if count[-1] != -1:
            break
count = count[::-1]

ans = []
a = 0
for i in range(check-2,-1,-1):
    b = count.index(i)
    ans.append(b-a)
    a = b
print(*ans)




### FIXED CODE ###

def main():
    
    n,m = map(int,input().split())
    l = list(input())[::-1]
    ans = []
    i = 0
    l[0] = 0

    while i < n+1:
        if l[i] == 0:
            a = -1
            for j in range(m,0,-1):
                if i+j < n+1 and l[i+j] != "1":
                    a = i+j
                    ans.append(j)
                    l[a] = 0
                    break
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if l[-1] == 0:
                break
    
    print(*ans[::-1])

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

from collections import deque


N, Q = map(int, input().split())

link = [None] * N 
for _ in range(N-1):
    a, b = map(int, input().split())
    if link[a-1] is None:
        link[a-1] = [b]
    else:
        link[a-1].append(b)

states = [0] * N
stack = deque()


def dfs(x):
    p = stack.popleft()

    # Add score
    states[p-1] += x
    # Search nexts
    nexts = link[p-1]
    if nexts is None:
        return
    for next_node in nexts:
        stack.append(next_node)


def update(p, x):
    stack.append(p)
    while stack:
        dfs(x)


for _ in range(Q):
    p, x = map(int, input().split())
    update(p, x)

# Output
print(' '.join(map(str, states)))


### FIXED CODE ###

import sys
from collections import deque

stack = deque()
input = sys.stdin.readline

N, Q = map(int, input().split())

link = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    link[a - 1].append(b)
    link[b - 1].append(a)
    
states = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    states[p - 1] += x

check = [0] * N
stack.append(1)
check[0] = 1
while stack:
    node = stack.pop()
    for next_node in link[node - 1]:
        if check[next_node - 1]:
            continue
        states[next_node - 1] += states[node - 1]
        check[next_node - 1] = 1
        stack.append(next_node)

# Output
print(*states)
### BUGGY CODE ###

A, B, C, D, E, F = map(int, input().split())
ans1 = 100 * A
ans2 = 0
n = 0
for x in range(100, F+1, 100):
    for y in range(F+1):
        if x + y == 0:
            continue        
        if x + y > F:
            continue
        if (x / 100) * E < y:
            continue

        s = []
        for i in range((y//C)+1):
            for j in range((y//D)+1):
                if y == i * C + j * D:
                    s.append((i, j))
                    break
            if len(s):
                break
        if len(s) == 0:
            continue

        w = []
        for i in range((x//(100*A))+1):
            for j in range((x//(100*B))+1):
                if x == 100 * A * i + 100 * B * j:
                    w.append((i, j))
                    break
            if len(w):
                break

        if len(w) == 0:
            continue

        if n < (y/(x+y)):
            n = y/(x+y)
            ans1 = x + y
            ans2 = y

print(ans1, ans2)


### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())
ans1 = 100 * A
ans2 = 0
n = 0
for x in range(100, F+1, 100):
    for y in range(F+1):
        if x + y == 0:
            continue        
        if x + y > F:
            continue
        if (x / 100) * E < y:
            continue

        s = []
        for i in range((y//C)+1):
            for j in range((y//D)+1):
                if y == i * C + j * D:
                    s.append((i, j))
                    break
            if len(s):
                break
        if len(s) == 0:
            continue

        w = []
        for i in range((x//(100*A))+1):
            for j in range((x//(100*B))+1):
                if x == 100 * A * i + 100 * B * j:
                    w.append((i, j))
                    break
            if len(w):
                break

        if len(w) == 0:
            continue

        if n < (y/(x+y)):
            n = y/(x+y)
            ans1 = x + y
            ans2 = y

print(ans1, ans2)
### BUGGY CODE ###

import copy
def main():
    _ = input()
    s = list(input())
    sset = set(s)
    l = []
    for i in sset:
        for j in sset:
            for k in sset:
                l.append(str(i)+str(j)+str(k))
    ans = 0
    for i in s:
        l_ = []
        while l:
            x = l.pop(-1)
            if x[0] == i:
                if len(x) == 1:
                    ans += 1
                else:
                    l_.append(x[1:])
            else:
                l_.append(x)
        l = copy.deepcopy(l_)
    print(ans)
        
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    s = list(input())
    sset = set(s)
    d = {}
    for i in sset:
        d[i] = []
    for i in range(n):
        d[s[i]].append(i)
    dk = d.keys()
    ans = 0
    for i in dk:
        for j in dk:
            for k in dk:
                a = d[i][0]
                f = False
                b = ""
                if d[j][-1] > a:
                    for x in d[j]:
                        if x > a:
                            f = True
                            b = x
                            break
                if f:
                    if d[k][-1] > b:
                        ans += 1
    print(ans)

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

def resolve():
    def Dijkstra(s, g):
        from collections import deque
        d = {s}
        queue = deque()
        for q in edge[s]:
            queue.append(q)
        while queue:
            dist, point = queue.popleft()
            if point in d:
                continue
            d.add(point)
            if point == g:
                return dist
            for nextdist, nextp in edge[point]:
                if not nextp in d:
                    if nextdist:
                        queue.append((dist + 1, nextp))
                    else:
                        queue.appendleft((dist, nextp))
        return -1
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    n, m = map(int, input().split())
    edge = defaultdict(set)
    for _ in range(m):
        p, q, c = map(int, input().split())
        p, q = p - 1, q - 1
        edge[(p, c)].add((0, (q, c)))
        edge[(q, c)].add((0, (p, c)))
        edge[(p, c)].add((0, (p, -1)))
        edge[(q, c)].add((0, (q, -1)))
        edge[(p, -1)].add((1, (p, c)))
        edge[(q, -1)].add((1, (q, c)))
    print(Dijkstra((0, -1), (n - 1, -1)))


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

def resolve():
    def Dijkstra(s, g):
        from collections import deque
        d = {s}
        queue = deque()
        for q in edge[s]:
            queue.append((1, q))
        while queue:
            dist, point = queue.popleft()
            if point in d:
                continue
            d.add(point)
            if point == g:
                return dist
            for nextp in edge[point]:
                if not nextp in d:
                    if not -1 in point or -1 in nextp:
                        queue.appendleft((dist, nextp))
                    else:
                        queue.append((dist + 1, nextp))
        return -1
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    n, m = map(int, input().split())
    edge = defaultdict(set)
    for _ in range(m):
        p, q, c = map(int, input().split())
        p, q = p - 1, q - 1
        edge[(p, c)].add((q, c))
        edge[(q, c)].add((p, c))
        edge[(p, c)].add((p, -1))
        edge[(q, c)].add((q, -1))
        edge[(p, -1)].add((p, c))
        edge[(q, -1)].add((q, c))
    print(Dijkstra((0, -1), (n - 1, -1)))


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

import bisect
import numpy as np
N,M=map(int, input().split())
A=list(map(int, input().split()))
A=np.array(sorted(A))
for i in range(M):
    b,c=map(int, input().split())
    x=bisect.bisect_left(A,c)
    x=min(x,b)
    A[:x]=c
    A=np.sort(A)
print(sum(A))


### FIXED CODE ###

N, M=map(int, input().split())
A=list(map(int, input().split()))
bc=[]
for i in range(M):
  b, c=map(int, input().split())
  bc.append((c,b))
for i in range(N):
  bc.append((A[i], 1))
  
bc=sorted(bc, key=lambda x : x[0], reverse=True)

ans=0
res=N
for x in bc:
  c=x[0]
  b=min(x[1], res)
  ans+=c*b
  res-=b
  if res==0:
    break
    
print(ans)
### BUGGY CODE ###

from copy import copy
n=int(input())
a=[0]+list(map(int,input().split()))
ans=[0]*(n+1) 
for i in range(n//2+1,n+1):
    ans[i]=a[i]
for j in reversed(range(1,n//2+1)):
    k=2
    count=0
    j_copy=copy(j)
    a_j=a[j]
    while True:
        count+=ans[k*j_copy]
        k+=1
        if k*j_copy>n:
            break
    if count%2==a_j:
        ans[j]+=0
    else:
        ans[j]+=1
temp=[]
for i in range(1,n+1):
  if ans[i]==1:
    temp.append(str(i))
print(ans.count(1))
print(" ".join(temp))

### FIXED CODE ###

from copy import copy
n=int(input())
a=[0]+list(map(int,input().split()))
ans=[0]*(n+1) 
for i in range(n//2+1,n+1):
    ans[i]=a[i]
for j in reversed(range(1,n//2+1)):
    k=2
    count=0
    j_copy=copy(j)
    a_j=a[j]
    while True:
        count+=ans[k*j_copy]
        k+=1
        if k*j_copy>n:
            break
    if count%2==a_j:
        ans[j]+=0
    else:
        ans[j]+=1
temp=[]
for i in range(1,n+1):
  if ans[i]==1:
    temp.append(str(i))
print(ans.count(1))
print(" ".join(temp))
### BUGGY CODE ###

def main():
    def pre(n,mod):
        an=[1]*(n+1)
        a=1
        for i in range(1,n+1):
            a=(a*i)%mod
            an[i]=a
        b=pow(a,mod-2,mod)
        bs=[1]*(n+1)
        bs[n]=b
        for i in range(n,1,-1):
            b=b*i%mod
            bs[i-1]=b
        return an,bs

    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    mod=10**9+7
    an,bs=pre(n,mod)
    ans=0
    for i in range(k,n+1):
        for j in range(0,n-i+1):
            s=a[i+j-1]-a[j]
            s=(s*an[i-2]*bs[k-2]*bs[i-k])%mod
            ans=(ans+s)%mod
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    mod=10**9+7
    ans=0
    for i in range(k-1,n):
        if i==k-1:
            c=1
        else:
            c=(c*i*pow(i-k+1,mod-2,mod))%mod
        ans+=(a[i]-a[n-i-1])*c
        ans%=mod
    print(ans)

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

def main():
    n = int(input())
    cnt = 0
    for c in range(1, n):
        for i in range(1, c+1):
            if c % i == 0:
                cnt += 1
    print(cnt)
    
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

from math import floor, ceil

def main():
    n = int(input())
    cnt = 0
    for a in range(1, n):
        cnt += floor((n-1)/a) - ceil(1/a) +1
    print(cnt)
    
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

# coding: utf-8
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
ans = 0
mem = uf.all_group_members()
for k in mem.keys():
    ans = max(ans, len(mem[k]))
print(ans)

### FIXED CODE ###

# coding: utf-8
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        # xの根を探索
        if self.parents[x] < 0:
            return x
        else:
            # 再帰的に根を探索
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        # 2つの木をマージする。
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def are_same(self, x, y):
        # 2つの要素の根が同じかどうかを調べる
        return self.find(x) == self.find(y)

    def members(self, x):
        # xと同じ根の要素をリストで出力
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == self.n]

    def roots(self):
        # 根である要素をリストで出力
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{} {}".format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
ans = 0
for v in uf.parents:
    if v < 0:
        ans = max(ans, abs(v))
print(ans)
### BUGGY CODE ###

import sys

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")
# sys.stdin = open(path)

input = sys.stdin.readline
N,K = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*(K+1)
for i in range(N-1):
    dp_ = dp.pop(0)
    if i >= N-K-1:
        dp = [min(dp_+abs(H[i+j+1]-H[i]),dp[j]) if dp[j] != 0 
                    else dp_+abs(H[i+j+1]-H[i]) for j in range(N-i-1)]
        continue
    dp = [min(dp_+abs(H[i+j+1]-H[i]),dp[j]) if dp[j] != 0 
                    else dp_+abs(H[i+j+1]-H[i]) for j in range(K)]
    dp.append(0)

print(dp[0])
        

### FIXED CODE ###

import sys

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")
# sys.stdin = open(path)

input = sys.stdin.readline
N,K = map(int,input().split())
H = list(map(int,input().split()))
dp = [float('inf')]*(K)
dp.append(0)
dp = dp[::-1]
for i in range(N-1):
    dp_ = dp.pop(0)
    if i >= N-K-1:
        dp = [min(dp_+abs(H[i+j+1]-H[i]),dp[j]) for j in range(N-i-1)]
        continue
    dp = [min(dp_+abs(H[i+j+1]-H[i]),dp[j])  for j in range(K)]
    dp.append(float("inf"))

print(dp[0])
### BUGGY CODE ###

a,b = map(int,input().split())
import math 
import fractions
def is_prime(n):
	if n == 1: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

#ユークリッドの互除法
gc = fractions.gcd(a,b)
if gc == 1:
	print(1)
	exit()

list1 = [1]
cout = 0 #1がfalse判定される
for i in range(2,gc+1):
	if is_prime(i):
		list1.append(i)
for i in range(len(list1)):
	if a % list1[i] == 0 and b % list1[i] == 0:
		cout += 1

"""
for i in range(1,gc+1):
	if a % i == 0 and b % i == 0:
		if is_prime(i):
			cout+= 1
"""
print(cout)

### FIXED CODE ###

import fractions
a,b = map(int,input().split())
"""素因数分解"""
def factrize(n):
	b = 2
	fct = []
	while b*b <= n:
		while n % b == 0:
			n //= b
			#もし素因数を重複させたくないならここを加えてfct.append(b)を消す
			
			if not b in fct:
				fct.append(b)
			
			
		b = b+1
	if n > 1:
		fct.append(n)
	return fct #リストが帰る

gc = fractions.gcd(a,b)

ans = factrize(gc)
print(len(ans)+1)
### BUGGY CODE ###

import sys
X = int(input())

for x in range(100000):
    for y in range(100000):
        A = x ** 5 - y ** 5
        if A == X:
            print(x, y)
            sys.exit()
        A = - x ** 5 - y ** 5
        if A == X:
            print(-x, y)
            sys.exit()
        A = x ** 5 + y ** 5
        if A == X:
            print(x, -y)
            sys.exit()
        A = -x ** 5 + y ** 5
        if A == X:
            print(-x, -y)
            sys.exit()


### FIXED CODE ###

import sys
X = int(input())

for x in range(100000):
    if 2 * x ** 5 == X:
        print(x, -x)
        sys.exit()
    for y in range(x):
        if (x ** 5 - y ** 5) == X:
            print(x, y)
            sys.exit()
        if (-x ** 5 + y ** 5) == X:
            print(-y, -x)
            sys.exit()
    tmp = 0
    y = 0
    while tmp < X:
        tmp = x ** 5 + y ** 5
        if tmp == X:
            print(x, -y)
            sys.exit()
        y += 1
### BUGGY CODE ###

import collections
N,K = map(int, input().split())
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1
#c = collections.Counter(List)
#print(min((v, k) for k, v in List.items()))
List_sorted = sorted(List.items(), key=lambda x:x[1])
tmp=0
while(True):
    if(len(List_sorted)<=K):break
    tmp+=list(List_sorted[0])[1]
    del List_sorted[0]

print(tmp)


### FIXED CODE ###

import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)
### BUGGY CODE ###

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

n = inp[0]
k = inp[1]

for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            if (a+b) % k == 0 and (b+c) % k == 0 and (c+a) % k == 0:
                ans.append([a, b, c])

print(len(ans))

### FIXED CODE ###

inp = [int(x) for x in input().split()]
n = inp[0]
k = inp[1]

num = [x for x in range(0, n+1, k)]
ans = (len(num)-1) ** 3

if k % 2 == 0:
    c = 0
    for i in range(1, n+1):
        if i % k == k / 2:
             c += 1
    ans += c ** 3
    

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

import itertools
n = int(input())
s = input()
seq = list(set(list(s)))
avcodelist = list(itertools.product(seq, repeat=3))
ans = []
for a in range(len(avcodelist)):
    for i in range(len(s)):
        if s[i] == avcodelist[a][0]:
            for j in range(i + 1, len(s)):
                if s[j] == avcodelist[a][1]:
                    for k in range(j + 1, len(s)):
                        if s[k] == avcodelist[a][2]:
                            ans.append((avcodelist[a][0], avcodelist[a][1], avcodelist[a][2]))
print(len(set(ans)))

### FIXED CODE ###

n = int(input())
s = list(input())
genkai_list = []
for i in range(0,1000):
    if 0 <= i <= 9:
        ap = "00" + str(i)
        genkai_list.append(ap)
    elif 10 <= i <= 99:
        ap = "0" + str(i)
        genkai_list.append(ap)
    else:
        genkai_list.append(str(i))
count = 0
for a in genkai_list:
    try:
        s_ = s[s.index(a[0])+1:]
        s__ = s_[s_.index(a[1])+1:]
        if a[2] in s__:
            count += 1
    except:
        continue
print(count)
### BUGGY CODE ###

#writer:yutaka1999さんの見ながらPythonで写経 通るかな？一応O(HW)=O(10**6)らしいけど...？
from collections import deque

def main():
  h,w=map(int,input().split())
  #global mp
  mp=[list(input()) for _ in range(h)]
  #global dist
  dist=[[-1]*w for i in range(h)]
  q=deque([])
  
  for i in range(h):
    for j in range(w):
      if mp[i][j]=="#":
        dist[i][j]=0
        q.append([i,j])
      else:
        dist[i][j]=-1
  
  while q:
    x,y=q.popleft()
    for i,j in ((1,0),(0,1),(-1,0),(0,-1)):
      xx,yy=x+i,y+j
      if (0<=xx<h and 0<=yy<w and dist[xx][yy]==-1):
        dist[xx][yy]=dist[x][y]+1
        q.append([xx,yy])
  
  ret=0
  for i in range(h):
    for j in range(w):
      ret=max(ret,dist[i][j])
      
  print(ret)
  return

main()

### FIXED CODE ###

#copipe
#1次元で格納

def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()