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

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


for i in range(int(M/N),0,-1):
    if M % i ==0:
        print(i)
        break

    

### FIXED CODE ###

N,M= map(int, input().split())
yakusu =[]

for i in range(int(M**(1/2)),0,-1):
    if M % i == 0:
        yakusu.append(i)
        yakusu.append(int(M/i))

yakusu.sort(reverse=True)

for i in yakusu:
    if i <= M/N:
        print(i)
        break
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
A_set = list(set(A))
result = []
for i in range(len(A_set)):
  if A.count(A_set[i])%2!=0:
    result.append(A_set[i])
print(len(set(result)))

### FIXED CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
dict = {}
for i in A:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
print(len([1 for i in dict.values() if i%2!=0]))
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7

dp = [0]*(n+1)
dp[0] = 25
dp[1] = 1

for i in range(1,n+k):
    pd = [0]*(n+1)
    for j in range(n+1):
        if j == 0:
            pd[j] = (dp[j]*25)%mod
            continue
        if j == n:
            pd[j] = (dp[j]*26+dp[j-1])%mod
            continue
        pd[j] = (dp[j]*25+dp[j-1])%mod
    dp = pd

print(dp[-1])

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6*3
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

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

N = int(input())
arr = [int(input()) for i in range(N)]
max_v= []

for v in arr:
  check = 0
  for i in range(len(max_v)):
    if max_v[i] < v:
      max_v[i] = v
      check = 1
      break
  if check == 0:
    max_v.append(v)
print(len(max_v))


### FIXED CODE ###

import bisect
N = int(input())
arr = [int(input()) for i in range(N)]
dp = [-1 for _ in range(N)]
for i in arr:
    dp[bisect.bisect_left(dp, i) - 1] = i
print(sum([i >= 0 for i in dp]))
### BUGGY CODE ###

# 23:22

S = input()
Q = int(input())

for _ in range(0, Q):
    q = input()
    if len(q.split()) == 1:
        S = S[::-1]
    else:
        _, f, c = q.split()
        if f == '1':
            S = c + S
        else:
            S = S + c
print(S)


### FIXED CODE ###

# 23:22

S = input()
Q = int(input())

# 0: 順
# 1: 逆
head = 0
pre = ''
post = ''

for _ in range(0, Q):
    q = input()
    if len(q.split()) == 1:
        head = 1 if head == 0 else 0
    else:
        _, f, c = q.split()
        if f == '1':
            # 先頭
            if head == 0:
                pre = c + pre
            else:
                post = post + c
        else:
            # 末尾
            if head == 1:
                pre = c + pre
            else:
                post = post + c

S = pre + S + post
print(S[::-1] if head == 1 else S)
### BUGGY CODE ###

s =str(input())
n = len(s)
ls = [1]*n
if n % 2 != 0:
    k = n+1
else:
    k = n
for _ in range(k):
    new = [0]*n
    for i in range(n):
        if i == 0:
            if s[1] == "L":
                new[0] = ls[1]
        elif i == n-1:
            if s[n-2] == "R":
                new[n-1] = ls[n-2]
        else:
            if s[i-1] == "R":
                new[i] += ls[i-1]
            if s[i+1] == "L":
                new[i] += ls[i+1]
    ls = new
print(*ls)

### FIXED CODE ###

s = str(input())
ls = [0]*len(s)
r = 0
l = 0
ind = 0
if s[0] == "R":
    r = 1
else:
    l = 1
for i in range(1,len(s)):
    if s[i-1] == "L" and s[i] == "R":
        ls[ind] = (l - l//2) + r//2
        if ind > 0:
            ls[ind-1] = (r - r//2) + l//2
        l = 0
        r = 1
    elif s[i-1] == "R" and s[i] == "L":
        ind = i
        l += 1
    else:
        if i == len(s)-1:
            if s[i] == "L":
                l += 1
                ls[ind] = (l - l//2) + r//2
                if ind > 0:
                    ls[ind-1] = (r - r//2) + l//2
                r = 0
                l = 0
            else:
                r += 1
                ls[-1] = r
                r = 0
        else:
            if s[i] == "R":
                r += 1
            else:
                l += 1
if r != 0 and l != 0:
    ls[ind] = (l - l//2) + r//2
    if ind > 0:
        ls[ind-1] = (r - r//2) + l//2
elif r != 0:
    ls[-1] = r
print(*ls)
### BUGGY CODE ###

#C-113
n, m = [int(i) for i in input().split()]
py = []
py_dict = {}
for mi in range(m):
  p, y = [int(i) for i in input().split()]
  py.append([p,y])
  py_dict[mi]=[p,y]
py.sort()
for mi in range(m):
  pref = py_dict[mi][0]
  x = [py[i][1] for i in range(m) if py[i][0] == pref].index(py_dict[mi][1])+1
  print("{:06}{:06}".format(pref,x))
  



### FIXED CODE ###

n, m = [int(i) for i in input().split()]
city = []
pref = [0 for i in range(n)]
for i in range(m):
    p, y = [int(_) for _ in input().split()]
    pref[p-1] += 1
    city.append([p,y,i])

city.sort(key = lambda x: (x[0], x[1]))
cnt = 1
for i in range(m):
    city[i].append(cnt)
    if cnt == pref[city[i][0]-1]:
        cnt = 1
    else:
        cnt += 1
city.sort(key = lambda x: x[2])
for i in range(m):
    print(str(city[i][0]).zfill(6)+str(city[i][3]).zfill(6))
### BUGGY CODE ###

n = int(input())
s = list(input() for _ in range(n))
ss = sorted(list(set(s)))
l = [0]*len(ss)
for i in range(len(ss)):
    l[i] =s.count(ss[i])
for i in range(len(ss)):
    if l[i] == max(l):
        print(ss[i])

### FIXED CODE ###

N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)
### BUGGY CODE ###

N = int(input())
count = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        if i*j >= N:
            break
        else:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
count = 0
flg = False
for i in range(1,N):

    count +=  int(N / i)
    if N% i == 0:
        count -=1
print(count)
### BUGGY CODE ###

import math
import re
import copy
import sys

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

### FIXED CODE ###

import math
import re
import copy
import sys

n = int(input())
a = list(map(int,input().split()))
ceil = 10 ** 18
ans = 1
if all([b > 0 for b in a]):
    for i in range(n):
        ans *= a[i]
        if ans > ceil:
            break
if any([b == 0 for b in a]):
    print(0)
elif ans > ceil:
    print("-1")
else:
    print(ans)
### BUGGY CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
j = M
for i in range(N+1):
    left = 0
    right = j
    if K - a[i] < 0:
        break
    while left < right:
        mid = (left + right)//2
        if b[mid] < K - a[i]:
            left = mid + 1
        elif b[mid] > K - a[i]:
            right = mid - 1
    if b[left] <= K - a[i]:
        j = left
    else:
        j = left - 1
    ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

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

a = int(input())
i = list(map(int, input().split()))
for num in range(a):
  sum = 0
  for num2 in range(len(i)):
    if i[num2] == num + 1:
      sum += 1
  print(sum)      

### FIXED CODE ###

a = int(input())
i = list(map(int, input().split()))
dict = {}
for num in range(a):
  dict[num] = 0

for num2 in range(len(i)):
  dict[i[num2] - 1] += 1

for num in range(a):
  print(dict[num])
### BUGGY CODE ###

#!/usr/bin/env python3

n, k = map(int, input().split())
p = list(map(int, input().split()))
exps = []

for i in range(n):
    exps.append(sum(list(range(1, p[i]+1)))/p[i])

sums = []
for i in range(n-(k-1)):
    tmp = 0 
    for j in range(k):
        tmp += exps[i+j]
    sums.append(tmp)

ans = max(sums)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

import numpy as np

n, k = map(int, input().split())
p = list(map(int, input().split()))
exps = []

for i in range(n):
    #exps.append(sum(list(range(1, p[i]+1)))/p[i])
    exps.append((1+p[i])/2)

exps = np.array(exps)
cumexps = exps.cumsum()
cumexps = np.insert(cumexps, 0, 0)

#print(exps)
#print(cumexps)

ans = -1
for i in range(n-k+1):
    tmp = -cumexps[i] + cumexps[i+k]
    if ans <= tmp:
        ans = tmp 

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

import sys

N = int(input())
H = [int (i) for i in input().split()]
flag = 1
minH = min(H)
maxH = max(H)


if N == 1:
    flag = 1
elif N == 2:
    if H[0] > H[1]+1:
        flag = 0
elif maxH-minH <= 1:
    print("Yes")
    sys.exit()
else:
    for i in range(N-1):
        if H[i] > H[i+1]+1:
            print("No")
            sys.exit()
        elif H[i] > H[i+1]:
            for j in range(i,N):
                if H[i] > H[j] + 1:
                    print("No")
                    sys.exit()

if flag == 0:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

N = int(input())
H = [int (i) for i in input().split()]
flag = 1

if N == 1:
    flag = 1
else:
    for i in range(N-2,-1,-1):
        if H[i] > H[i+1]:
            H[i] -= 1
    for i in range(N-1):
        if H[i] > H[i+1]:
            flag = 0

if flag == 0:
    print("No")
else:
    print("Yes")
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

H, W = list(map(int, input().split()))
S = []
for _ in range(H):
    S.append(input())

ans = 0


def bfs(x, y):
    global ans
    m = []
    for _ in range(H):
        m.append([-1] * W)

    q = deque()
    q.append([y, x, 0])

    while q:
        j, i, v = q.popleft()
        m[j][i] = v
        dj = j + 1
        if dj < H and m[dj][i] == -1 and S[dj][i] == ".":
            q.append([dj, i, v+1])
            if ans < v+1:
                ans = v+1
        dj = j - 1
        if 0 <= dj and m[dj][i] == -1 and S[dj][i] == ".":
            q.append([dj, i, v+1])
            if ans < v+1:
                ans = v+1
        di = i + 1
        if di < W and m[j][di] == -1 and S[j][di] == ".":
            q.append([j, di, v+1])
            if ans < v+1:
                ans = v+1
        di = i - 1
        if 0 <= di and m[j][di] == -1 and S[j][di] == ".":
            q.append([j, di, v+1])
            if ans < v+1:
                ans = v+1


for j in range(H):
    for i in range(W):
        if S[j][i] != ".":
            continue
        bfs(i, j)
print(ans)


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

H, W = list(map(int, input().split()))
S = ["#" * (W+2)] + ["#" + input().strip() +
                     "#" for _ in range(H)] + ["#" * (W+2)]

ans = 0

for j in range(1, H+1):
    for i in range(1, W+1):
        if S[j][i] != ".":
            continue
        m = [[-1] * (W+2) for _ in range(H+2)]

        q = deque()
        q.append((j, i, 0))
        m[j][i] = 0

        while q:
            y, x, v = q.popleft()
            if ans < v:
                ans = v
            for dj, di in ((y, x+1), (y, x-1), (y+1, x), (y-1, x)):
                if S[dj][di] == "#" or m[dj][di] != -1:
                    continue
                q.append((dj, di, v+1))
                m[dj][di] = v+1
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split(' '))
s = []
for i in range(m):
    l, r = map(int, input().split(' '))
    a = set(j for j in range(l, r+1))
    s.append(a)
result = s[0]
for i in range(len(s)-1):
    result = result & s[i+1]
print(len(list(result)))

### FIXED CODE ###

n, m = map(int, input().split(' '))
l_ = []
r_ = []
for i in range(m):
    l,r = map(int, input().split(' '))
    l_ += [l]
    r_ += [r]
l = max(l_)
r = min(r_)
if n < l:
    print(0)
elif n < r:
    r = n
    print(r - l + 1)
elif l > r:
    print(0)
elif l == r:
    print(1)
else:
    print(r - l + 1)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v):
	#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
	if weight[bef_v][v] % 2 :
		seen[v] = int(not seen[bef_v]);
	else :
		seen[v] = seen[bef_v];
	
	for next_v in G[v] :
		if seen[next_v]==-1 :
			dfs(G,next_v,v);


n = int(input());
weight = [[0]*n for i in range(n) ];
G = [0]*n;
for i in range(n) :
	G[i] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u].append(v);
	G[v].append(u);
	weight[u][v] = w;
	weight[v][u] = w;


seen = [-1]*n;
seen[0] = 0;
dfs(G,0,0);

for i in range(n):
	print(seen[i]);
	


### FIXED CODE ###

import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v,ind_num):
	if v == bef_v :
		seen[v] = 0;
	else :
		#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
		if G[bef_v][1][ind_num] % 2 :
			seen[v] = int(not seen[bef_v]);
		else :
			seen[v] = seen[bef_v];
	
	for i in range(len(G[v][0])) :
		next_v = G[v][0][i];
		if seen[next_v]==-1 :
			dfs(G,next_v,v,i);


n = int(input());
G = [[0]*2 for i in range(n) ];
for i in range(n) :
	G[i][0] = [];
	G[i][1] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u][0].append(v);
	G[v][0].append(u);
	G[u][1].append(w);
	G[v][1].append(w);


seen = [-1]*n;
dfs(G,0,0,0);

for i in range(n):
	print(seen[i]);
### BUGGY CODE ###

N = int(input())
S = input()
N_original = N

ans = 0
isleft = True

def f(n):
    for i in range(N_original - n+1):
        temp = S[i:i+n]
        if temp in S[0:i] + "|" + S[i+n:]:
            return True
    return False

left = 0
right = N
N = N//4
while True:
    if f(N):
        if left == N:
            ans = left
            break
        left = N
    else:
        if right == N:
            ans = right
            break
        right = N
    N = (left + right)//2
print(ans)


### FIXED CODE ###

def main():
    N = int(input())
    S = input()
    l1 = length = 0
    l2 = 1

    while (l2 + length < N):
        if S[l1:l2] in S[l2:]:
            length = l2 - l1
            l2 += 1
        else:
            l1 += 1
            l2 = l1 + length + 1
    print(length)

main()
### BUGGY CODE ###

h, w = map(int, input().split())
grid = [[0]*(w) for _ in range(h)]

black = []
for i in range(h):
    for j, k in enumerate(input()):
        if k == "#":
            black.append((i, j))
            grid[i][j] = 1

ans = 0
d = ((0, 1),
     (1, 0),
     (0, -1),
     (-1, 0),)
while True:
    paint = []
    while black:
        x, y = black.pop()
        for nx, ny in d:
            if x+nx == -1 or x+nx == h or y+ny == -1 or y+ny == w:
                continue
            if not grid[nx + x][ny + y]:
                grid[nx + x][ny + y] = 1
                paint.append((nx + x, ny + y))

    if len(paint) == 0:
        break
    black = paint[:]
    ans += 1

print(ans)

### FIXED CODE ###

h, w = map(int, input().split())
grid = [[0]*(w+2) for _ in range(h+2)]

black = []
for i in range(h):
    for j, k in enumerate(input()):
        if k == "#":
            black.append((i + 1, j + 1))
            grid[i+1][j+1] = 1

ans = 0
d = ((0, 1),
     (1, 0),
     (0, -1),
     (-1, 0),)
while True:
    paint = []
    while black:
        x, y = black.pop()
        if x == 0 or x == h + 1 or y == 0 or y == w + 1:
            continue
        else:
            for nx, ny in d:
                if not grid[nx + x][ny + y]:
                    if x+nx == 0 or x+nx == h + 1 or y+ny == 0 or y+ny == w + 1:
                        continue
                    grid[nx + x][ny + y] = 1
                    paint.append((nx + x, ny + y))

    if len(paint) == 0:
        break
    black = paint[:]
    ans += 1

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
 
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
 
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[y] = x
        else:
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
 
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
 
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def main():
  N, M = map(int, input().split())
  p = list(map(int, input().split()))
  xy = [list(map(int, input().split())) for _ in range(M)]
  U = UnionFind(N+1)
  for x, y in xy:
    U.Unite(x, y)
  root_dict = {}
  for i in range(1, N+1):
    root = U.Find_Root(i)
    if root in root_dict:
      root_dict[root] += [i]
    else:
      root_dict[root] = [i]
  ans = 0
  for idx_list in root_dict.values():
    for idx in idx_list:
      if p[idx-1] in idx_list:
        ans += 1
  print(ans)


if __name__ == "__main__":
  main()

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
 
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
 
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[y] = x
        else:
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
 
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
 
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def main():
  N, M = map(int, input().split())
  p = list(map(int, input().split()))
  xy = [list(map(int, input().split())) for _ in range(M)]
  U = UnionFind(N+1)
  for x, y in xy:
    U.Unite(x, y)
  ans = 0
  for i in range(1, N+1):
    if U.isSameGroup(i, p[i-1]):
      ans += 1
  print(ans)


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

n=int(input())
A=[]
for i in range(n):
    a=int(input())
    A.append(a)
M=max(A)
for i in range(n):
    if A[i]!=M:
        print(M)
    else:
        b=A.pop(i)
        print(max(A))
        A.insert(i,b)

### FIXED CODE ###

n = int(input())
A = [int(input()) for i in range(n)]

M = max(A)
ind = A.index(M)
A[ind] = 0
M2 = max(A)


if M in A:
    for i in range(n):
        print(M)
else:
    for i in range(n):
        if A[i] == 0:
            print(M2)
        else:
            print(M)
### BUGGY CODE ###

a, b, k = map(int, input().split())
l = [i for i in range(a, b+1)]
ans = list(set(l[:k] + l[-k:]))
for i in sorted(ans):
  print(i)

### FIXED CODE ###

a, b, k = map(int, input().split())
ans = []
for i in range(a, a+k):
  if i >= a and i <= b:
    ans.append(i)

for i in range(b-k+1, b+1):
  if not i in ans and i >= a and i <= b:
    ans.append(i)

for i in ans:
  print(i)
### BUGGY CODE ###

H, W = map(int, input().split())
dist_matrix = [[-1] * W for i in range(H)]
queue = []
for i in range(H):
  line_list = list(input())
  for j in range(W):
    if line_list[j] == "#":  
      dist_matrix[i][j] = 0
      queue.append([i,j])

#cnt = 0
#print(queue)
max_value = 0
while(True):
  #print(len(queue))
  if len(queue) == 0:
    break
  
  i,j = queue.pop(0)
  max_value = dist_matrix[i][j]
  #cnt += 1
  if i > 0 and dist_matrix[i-1][j] == -1:
    dist_matrix[i-1][j] = max_value + 1
    queue.append([i-1,j])
  if i < H-1 and dist_matrix[i+1][j] == -1:
    dist_matrix[i+1][j] = max_value + 1
    queue.append([i+1,j])
  if j > 0 and dist_matrix[i][j-1] == -1:
    dist_matrix[i][j-1] = max_value + 1
    queue.append([i,j-1])
  if j < W-1 and dist_matrix[i][j+1] == -1:
    dist_matrix[i][j+1] = max_value + 1
    queue.append([i,j+1])

#print(cnt)
#print(dist_matrix)
print(max_value)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
 
H, W = map(int, input().split())
mark_matrix = [[True]*(W+2)]
#mark_matrix.extend([[True]+[False]*(W)+[True] for _ in range(H)])
mark_matrix.extend([[True]+[x!='.' for x in input()] for _ in range(H)])
mark_matrix[H].append(True)
mark_matrix.append([True]*(W+2))
#queue = []
queue = deque()
for i in range(1,H+1):
  for j in range(1,W+1):
    if mark_matrix[i][j]:
      queue.append((i,j))
#  line = input()
#  for j,ch in enumerate(line):
#    if ch == "#":
#      mark_matrix[i+1][j+1] = True
#      queue.append((i+1,j+1))
#for i in range(1,H+1):
#  mark_matrix[i][0] = True
#  mark_matrix[i][W+1] = True
#for j in range(W+2):
#  mark_matrix[0][j] = True
#  mark_matrix[H+1][j] = True
#print(mark_matrix)
 
#cnt = 0
#print(queue)
max_value = 0
while(True):
  #print(len(queue))
  if len(queue) == 0:
    break
  
  new_queue = deque()
  for i,j in queue:
  
    if not mark_matrix[i-1][j]:
      mark_matrix[i-1][j] = True
      #queue.append((i-1,j))
      new_queue.append((i-1,j))
    if not mark_matrix[i+1][j]:
      mark_matrix[i+1][j] = True
      #queue.append((i+1,j))
      new_queue.append((i+1,j))
    if not mark_matrix[i][j-1]:
      mark_matrix[i][j-1] = True
      #queue.append((i,j-1))
      new_queue.append((i,j-1))
    if not mark_matrix[i][j+1]:
      mark_matrix[i][j+1] = True
      #queue.append((i,j+1))
      new_queue.append((i,j+1))
 
  if len(new_queue) == 0:
    break
  else:
    queue = new_queue
    max_value += 1
  
#print(cnt)
#print(dist_matrix)
print(max_value)
### BUGGY CODE ###

cnt=0
k,s=map(int,input().split())
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i+j+k==s:
                cnt+=1
print(cnt)


### FIXED CODE ###

cnt=0
k,s=map(int,input().split())
for i in range(k+1):
    for j in range(k+1):
        if (0<=s-i-j<=k):
                cnt+=1
print(cnt)
### BUGGY CODE ###

from itertools import accumulate
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
f = [1]*(N+1)


def fact():
    for i in range(1, N):
        f[i+1] = f[i]*(i+1)


def comb(n, r):
    return f[n]//(f[r]*f[n-r])


a = accumulate(A)
C = Counter(a)
fact()

ans = 0
for i, v in C.items():
    if i == 0:
        ans += v
    if v > 1:
        ans += comb(v, 2)
print(ans)


### FIXED CODE ###

from itertools import accumulate
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


a = accumulate(A)
C = Counter(a)


def comb(v):
    return (v)*(v-1)//2


ans = 0
for i, v in C.items():
    if i == 0:
        ans += v
    if v > 1:
        ans += comb(v)
print(ans)
### BUGGY CODE ###

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

ans = 1
for x in a:
    ans *= x
    
if ans > 1e18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

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

printed = False
if 0 in a:
    print(0)
    printed = True

ans = 1

for x in a:
    ans *= x
    if ans > 1e18:
        if not printed:
            print(-1)
            printed = True
        break    
    
if not printed:
    print(ans)