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

n = int(input())
s = input()
ls = len(s)

ans = 0
for i in range(1, n):
    #print(s[:i], s[i:], i, ls-i)
    a, b = s[:i], s[i:]
    la, lb = i, ls - i
    dp = [[0] * (la+1) for _ in range(lb+1)]
    for j in range(la):
        for k in range(lb):
            if a[j] == b[k]:
                dp[k+1][j+1] = dp[k][j] + 1
    #print(dp[lb][la])
    ans = max(ans, dp[lb][la])
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
"""
def lcs(s, t):
    ls, lt = len(s), len(t)
    dp = [[0] * (lt+1) for _ in range(ls+1)]
    for i in range(ls):
        for j in range(lt):
            #prev = dp[i+1][j+1]
            if s[i] == t[j]:
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
    return dp[ls][lt]
"""
def z_algorithm(s):
    ls = len(s)
    Z = [0] * ls
    Z[0] = ls
    i, j = 1, 0
    while i < ls:
        while i + j < ls and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < ls and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
for i in range(n):
    #print(s[i:])
    z = z_algorithm(s[i:])
    for j, zj in enumerate(z):
        if j+1 > zj:
            ans = max(ans, zj)
    #print(z)
print(ans)
### BUGGY CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val]

n = INT()
s = input()

di = {}
ans=0

for start in range(n):
    for end in range(start,n):
        di[(start,end)] = s[start:end+1]

for k,v in di.items():
    tmp = di[k]
    di[k]=0
    if tmp in di.values():
        keys = get_keys_from_value(di,tmp)
        for i in keys:
            if k[1]<i[0]:
                ans = max(ans,len(tmp))

print(ans)


### FIXED CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
s = input()

a=0
i=0
j=1

while j<n:
    if s[i:j] in s[j:]:
        a = max(a,len(s[i:j]))
        j+=1
    else:
        i+=1
    if i==j:
        i+=1
        j+=2

print(a)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 0

for i in range(N-1):
  for j in range(i+1,N):
    ans += A[i]^A[j]
    ans %= mod
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 0
count=[0]*60
for a in A:
  for i in range(60):
    count[i] += a & 1
    a >>= 1
    
for i in range(60):
  ans += count[i] * (N - count[i]) * (2 ** i)
  ans %= mod
print(ans)
### BUGGY CODE ###

n=int(input())
print(sum([i for i in range(1,n)]))

### FIXED CODE ###

n=int(input())
print(n*(n-1)//2)
### BUGGY CODE ###

from bisect import bisect_right
import sys
input = sys.stdin.readline
n = int(input())
s = tuple(map(lambda x: ord(x) - ord("a") + 1, input()))
base = 1007
mod = 2**61 - 1

length = n//2
b = [1] * (length + 1)
shash = [0] * (length+1)
for i in range(1, length + 1):
    b[i] = b[i-1] * base
    b[i] %= mod
    shash[i] = shash[i - 1] * base % mod + s[i - 1]
    shash[i] %= mod

for ans in reversed(range(1, length+1)):
    # calc hash
    hash_ = 0
    check = {}
    #y = set([])
    for left in range(n - ans + 1):
        if left == 0:
            hash_ = shash[ans]
            check[hash_] = left
            #y.add(hash_)
        else:
            hash_ = base * hash_ % mod - b[ans] * s[left - 1] % mod + s[left + ans - 1]
            hash_ %= mod
            if hash_ in check.keys():
                # print("tmp = ", tmp)
                if check[hash_] <= left - ans:
                    print(ans)
                    # a = check[hash_][tmp-1]
                    # at = "".join(map(lambda x: chr(x + ord("a")), s[a:a+ans]))
                    # for j in range(ans):
                        # if s[a+j] != s[left+j]:
                            # print("Fail")
                            # exit()
                    # print("Success")
                    sys.exit()
            else:
                check[hash_] = left
                #y.add(hash_)
        # print(hash_, s[left:left+ans])
print(0)



### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
s = tuple(map(lambda x: ord(x) - ord("a") + 1, input()))
base = 1007
mod = 2**61 - 1

length = n//2
b = [1] * (length + 1)
shash = [0] * (length+1)
for i in range(1, length + 1):
    b[i] = b[i-1] * base % mod
    shash[i] = (shash[i - 1] * base + s[i - 1]) % mod

for ans in reversed(range(1, length+1)):
    # calc hash
    hash_ = 0
    check = {}
    #y = set([])
    for left in range(n - ans + 1):
        if left == 0:
            hash_ = shash[ans]
            check[hash_] = left
            #y.add(hash_)
        else:
            hash_ = base * hash_ - b[ans] * s[left - 1] + s[left + ans - 1]
            hash_ %= mod
            if hash_ in check.keys():
                # print("tmp = ", tmp)
                if check[hash_] <= left - ans:
                    print(ans)
                    # a = check[hash_][tmp-1]
                    # at = "".join(map(lambda x: chr(x + ord("a")), s[a:a+ans]))
                    # for j in range(ans):
                        # if s[a+j] != s[left+j]:
                            # print("Fail")
                            # exit()
                    # print("Success")
                    sys.exit()
            else:
                check[hash_] = left
                #y.add(hash_)
        # print(hash_, s[left:left+ans])
print(0)
### BUGGY CODE ###

from collections import defaultdict

n = int(input())
aaa = list(map(int, input().split()))
rd = defaultdict(set)
ma = 0
for i, a in enumerate(aaa):
    rd[a].add(i)
    ma = max(ma, a)

ma2 = 2
while ma2 <= ma:
    ma2 <<= 1

edges = [None for _ in range(n)]
for a, i_set in rd.items():
    tmp_set = set()
    k = 2
    while k <= ma2:
        if k > a:
            b = k - a
            if b in rd:
                tmp_set.update(rd[b])
        k <<= 1
    for i in i_set:
        ts = tmp_set.copy()
        ts.discard(i)
        edges[i] = ts


def dfs(v, visited):
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited):
            matched[u] = v
            return True
    return False


matched = [-1] * n

print(sum(dfs(s, set()) for s in range(n)) // 2)


### FIXED CODE ###

from collections import defaultdict

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


def solve(count):
    ans = 0
    for a in sorted(count, reverse=True):
        cnt = count[a]
        if cnt <= 0:
            continue
        ma = 1 << (a.bit_length())
        b = ma - a
        if b in count and count[b] > 0:
            if a == b:
                pair = cnt // 2
            else:
                pair = min(cnt, count[b])
                count[b] -= pair
            ans += pair
    return ans


count_e = defaultdict(lambda: 0)
count_o = defaultdict(lambda: 0)
for a in aaa:
    if a % 2 == 0:
        count_e[a] += 1
    else:
        count_o[a] += 1

print(solve(count_e) + solve(count_o))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
# print(a)
ans = 1
for i in a:
    ans = ans* i

print(-1 if ans>(10**18) else ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
    ans = 0
else:
    a.sort(reverse=True)
    for i in a:
        if(i==0):
            ans = 0;break
        if ans>(10**18):
            ans = -1;break
        ans = ans*i
print(-1 if ans>(10**18) else ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
N,K=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))]
dic={}
MOD=10**9+7
def findout(i,j,k):
    
    if k==1:
        if A[i][j]==1:
            return 1
        else:
            return 0
    if (i,j,k) in dic:
        return dic[(i,j,k)]
    N=len(A)
    a1=k//2
    a2=k-a1
    
    ans=0
    for node in range(N):
        ans+=(findout(i,node,a1)*findout(node,j,a2))%MOD
    dic[(i,j,k)]=ans
    return ans
ans=0
for i in range(N):
    for j in range(N):
        ans+=findout(i,j,K)
        ans%=MOD
print(ans)

### FIXED CODE ###

N,K=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))]
dic={}
MOD=10**9+7
power=1
while 2**power<=K:
    power+=1

dp=[[[0 for j in range(N)] for i in range(N)] for p in range(power+1) ]
for p in range(0,power+1):
    
    if p==0:
        for i in range(N):
            for j in range(N):
                if A[i][j]==1:
                    dp[p][i][j]=1
    else:
        for i in range(N):
            for j in range(N):
                for k in range(N):
                    dp[p][i][j]+=(dp[p-1][i][k]*dp[p-1][k][j])%MOD
                    dp[p][i][j]%=MOD

    
rep=bin(K)[2:][::-1]
final_ans=[[0 for i in range(N)] for j in range(N)]
need=[]
for i in range(len(rep)):
    if rep[i]=="1":
        need+=[i]

final=[[dp[need[0]][i][j] for j in range(N)] for i in range(N)]
for i in range(1,len(need)):
    ##start*dp[need[i]]
    temp_ans=[[0 for i in range(N)] for j in range(N)]
    for x in range(N):
        for y in range(N):
            temp=0
            for z in range(N):
                temp+=final[x][z]*dp[need[i]][z][y]
                temp%=MOD
            temp_ans[x][y]=temp
    final=[[temp_ans[i][j] for j in range(N)] for i in range(N)]
            
ans=0
for i in range(N):
    for j in range(N):
        ans+=final[i][j]
        ans%=MOD
print(ans)
### BUGGY CODE ###

import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        
        if sum(ANS[a[1]:a[1]+L]) < MAX + len(ANS[a[1]:a[1]+L]) - 1 : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == MAX:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] == MAX : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == MAX : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
parameter = 0.9998
MAX = 10**9+1
ANS = [MAX]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

n=int(input())
a=[]
minv=200000
for i in range(n):
    a.append(int(input()))
for i in range(n):
    b=a.pop(i)
    print(max(a))
    a.insert(i,b)

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if a.count(maxa)>=2:
    for i in range(n):
        print(maxa)
else:
    maxi=a.index(maxa)
    a.remove(maxa)
    maxa2=max(a)
    for i in range(n):
        if i==maxi:
            print(maxa2)
        else:
            print(maxa)
### BUGGY CODE ###

a,b=map(int,input().split())
import numpy as np
l=np.array(list(map(int,input().split())))
for i in range(min(b,int(a**0.5)+4)):
  now=np.zeros(a,dtype=np.int)
  for j in range(a):
    x=l[j]
    y=np.zeros(a,dtype=np.int)
    y[max(0,j-x):min(a,j+x+1)]=1
    now+=y
  l=now
for i in range(a):
  now[i]=min(now[i],a)
print(*now)


### FIXED CODE ###

a,b=map(int,input().split())
l=list(map(int,input().split()))
import itertools
b=min(b,50)
def ku(l):
    y=[0]*a
    for j,x in enumerate(l):
      y[max(0,j-x)]+=1
      r=min(j+x,a-1)
      if r<a-1:
        y[r+1]-=1
    return itertools.accumulate(y)

  
for _ in range(b):
  l=ku(l)
print(*l)
### BUGGY CODE ###

n,q = map(int, input().split())
s = input()
a = [0 for i in range(q)]
for k in range(q):
    i,j = map(int, input().split())
    a[k] = [i,j]
for nums in a:
    print(s[nums[0]-1:nums[1]].count("AC"))

### FIXED CODE ###

def get_ac_count(S):
    buf = None
    temp = []
    count = 0
    for c in S:
        if c == "A":
            buf = "A"
        elif buf == "A" and c == "C":
            buf = None
            count += 1
        elif buf == "A":
            buf = None
        temp.append(count)
    return temp
N, Q = map(int, input().split())
S = input()
ac_count = get_ac_count(S)
for i in range(Q):
    l,r = map(int, input().split())
    print(ac_count[r-1]-ac_count[l-1])
### BUGGY CODE ###

from collections import deque
import sys
input=sys.stdin.readline
moji=deque([])
s=input().rstrip()
for i in range(len(s)):
	moji.append(ord(s[i]))
q=int(input())
rev=0
for _ in range(q):
	qw=input().split()
	if qw[0]=="1":
		rev+=1
	else:
		f=qw[1]
		c=qw[2]
		if f=="1":
			if rev%2==0:
				moji.appendleft(ord(c))
			else:
				moji.append(ord(c))
		else:
			if rev%2==0:
				moji.append(ord(c))
			else:
				moji.appendleft(ord(c))
ans=""
for i in range(len(moji)):
	ans+=chr(moji[i])
if rev%2==0:
	print(ans)
else:
	print(ans[::-1])

### FIXED CODE ###

alph="abcdefghijklmnopqrstuvwxyz"
from collections import deque
import sys
input=sys.stdin.readline
moji=deque([])
s=input().rstrip()
for i in range(len(s)):
	for j in range(26):
		if s[i]==alph[j]:
			moji.append(j)
			break
q=int(input())
rev=0
for _ in range(q):
	qw=input().split()
	if qw[0]=="1":
		rev+=1
	else:
		f=qw[1]
		c=qw[2]
		for j in range(26):
			if c==alph[j]:
				x=j
				break
		if f=="1":
			if rev%2==0:
				moji.appendleft(x)
			else:
				moji.append(x)
		else:
			if rev%2==0:
				moji.append(x)
			else:
				moji.appendleft(x)
ans=""
r=[]
for i in range(len(moji)):
	r.append(moji.popleft())
for i in range(len(r)):
	ans+=alph[r[i]]
if rev%2==0:
	print(ans)
else:
	print(ans[::-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0

    for i in range(n - k + 1):
        ref = sum(p[i: i + k])
        if ref > ans:
            ans = ref

    print(ans/2 + k*0.5)

main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ref = sum(p[:k])
    ans = ref

    for i in range(1, n - k + 1):
        ref = ref - p[i - 1] + p[i + k - 1]
        if ref > ans:
            ans = ref

    print(ans/2 + k*0.5)

main()
### BUGGY CODE ###

N=int(input())
S=input()
count=0
for i in range(N-2):
    for j in range(i,N-1):
        for k in range(j,N):
            if(S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]):
                if((j-i)!=(k-j)):
                    count=count+1

print(count)


### FIXED CODE ###

import itertools
N = int(input())
S = input()
out = S.count('R') * S.count('G') * S.count('B')

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(1, N):
  for j in range(N-i*2):
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = list(input())
m = []
n = []
for i in range(N):
    if S[i] == 'E':
        S[i] = 1
    else:
        S[i] = 0
for i in range(1, N):
    ls = sum(S[:i-1])
    rs = sum(S[i+1:])
    n.append(i-1-ls+rs)
print(min(n))


### FIXED CODE ###

import numpy as np
N = int(input())
S = np.array(list(input()))
n = []
for i in range(N):
    if S[i] == 'E':
        S[i] = 1
    else:
        S[i] = 0
S = np.array(S, dtype=int)
S = np.cumsum(S)
last = S[N-1]
n.append(last-S[0])
for i in range(1, N):
    ls = i - S[i-1]
    rs = last - S[i]
    n.append(ls+rs)
print(min(n))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import itertools 

def solve(N: int, C: int, D: "List[List[int]]", c: "List[List[int]]"):
    c_list = list(itertools.permutations(range(C),3))
    answer = 10**9
    for zero,one,two in c_list:
        a = 0
        for i in range(N):
            for j  in range(N):
                color = c[i][j]
                if (i+j) % 3 == 0:
                    a+= D[color-1][zero]
                elif (i+j) % 3 == 1:
                    a+= D[color-1][one]
                elif (i+j) % 3 == 2:
                    a+= D[color-1][two]
        answer = min(answer,a)

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = [[int(next(tokens)) for _ in range(C)] for _ in range(C)]  # type: "List[List[int]]"
    c = [[int(next(tokens)) for _ in range(N)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, C, D, c)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import itertools 

def solve(N: int, C: int, D: "List[List[int]]", c: "List[List[int]]"):
    answer = 10**9

    cost = [[0 for _ in range(C)] for _ in range(3)]


    for i in range(1,N+1):
        for j  in range(1,N+1):
            cost[(i+j)%3][c[i-1][j-1]-1] += 1

    for i in range(C):
        for j in range(C):
            for k in range(C):
                if i==j or j==k or k==i:
                    continue
                a = 0
                for index in range(C):
                    a += cost[0][index]*D[index][i]
                    a += cost[1][index]*D[index][j]
                    a += cost[2][index]*D[index][k]
                
                answer = min(a,answer)

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = [[int(next(tokens)) for _ in range(C)] for _ in range(C)]  # type: "List[List[int]]"
    c = [[int(next(tokens)) for _ in range(N)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, C, D, c)

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

n = int(input())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
taka = 0
aoki = 0
while (1):
    max_list = []
    max_list = [i for i, x in enumerate(a) if x == max(a)]
    max_val = 0
    max_index = 0
    for i in max_list:
        if(b[i] > max_val):
            max_index = i
    taka += a[max_index]
    b.pop(max_index)
    a.pop(max_index)
    if(len(a) == 0):
        print(taka - aoki)
        exit()
    max_list = []
    max_list = [i for i, x in enumerate(b) if x == max(b)]
    max_val = 0
    max_index = 0
    for i in max_list:
        if(b[i] > max_val):
            max_index = i
    aoki += b[max_index]
    a.pop(max_index)
    b.pop(max_index)
    if(len(a) == 0):
        print(taka - aoki)
        exit()

### FIXED CODE ###

n = int(input())
a_b = []
b_sum = 0
for i in range(n):
    ai, bi = map(int, input().split())
    a_b.append(ai+bi)
    b_sum += bi
a_b.sort(reverse=True)
ans = 0
for i in range(len(a_b)):
    if i%2==0:
        ans += a_b[i]
print(ans-b_sum)
### BUGGY CODE ###

N,K=map(int,input().split())
num=list(map(float,input().split()))
answer=[]
a=0
for i in range(N):
    num[i]=(num[i]+1)/2
for i in range(N-K+1):
    ans=0
    for j in range(K):
        ans+=num[i+j]
    if ans>a:
      a=ans
print(a)

### FIXED CODE ###

N,K=map(int,input().split())
num=list(map(float,input().split()))
a=0
check=0
for i in range(N):
    num[i]=(num[i]+1)/2
    if i<K:
        check+=num[i]
a=check        
for i in range(N-K):
    ans=check-num[i]+num[K+i]
    if ans>a:
        a=ans
    check=ans  
print(a)
### BUGGY CODE ###

N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))

DP = [0] * (N+1)

for i in range(2, N+1):
  k = min(i, K+1)
  DP[i] = min(DP[i-j] + abs(H[i-j] - H[i]) for j in range(1, k))
print(DP[N])


### FIXED CODE ###

N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))

DP = [0] * (N+1)

for i in range(2, N+1):
  k = max(i-K, 1)
  DP[i] = min(dp + abs(h - H[i]) for dp, h in zip(DP[k:i], H[k:i]))
print(DP[N])
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
g = [str(input()) for _ in range(H)]
ans = 0
dh = [1, 0, 0, -1]
dw = [0, -1, 1, 0]
for h in range(H):
    for w in range(W):
        if g[h][w] == '.':
            d = 0
            done = [[False] * W for _ in range(H)]
            done[h][w] = True
            q = deque([[h, w]])
            while q:
                h, w = q.popleft()
                d += 1
                for i in range(4):
                    nh = h + dh[i]
                    nw = w + dw[i]
                    if 0 <= nh < H and 0 <= nw < W and done[nh][nw] == False:
                        if g[nh][nw] == '.':
                            done[nh][nw] = True
                            q.append([nh, nw])
                        else:
                            q.clear()
                            break
            ans = max(ans, d)
print(ans)


### FIXED CODE ###

def main():
    H, W = map(int, input().split())
    g = []
    q = []
    cnt = 0
    for h in range(H):
        A = str(input())
        row = []
        for w in range(W):
            row.append(A[w])
            if A[w] == '#':
                cnt += 1
                q.append([h, w])
        g.append(row)
    ans = 0
    dh = [1, 0, 0, -1]
    dw = [0, -1, 1, 0]
    while cnt < H * W:
        ans += 1
        nextq = []
        while q:
            h, w = q.pop()
            for i in range(4):
                nh = h + dh[i]
                nw = w + dw[i]
                if 0 <= nh < H and 0 <= nw < W and g[nh][nw] == '.':
                    g[nh][nw] = '#'
                    nextq.append([nh, nw])
                    cnt += 1
        q = nextq
    print(ans)
main()
### BUGGY CODE ###

k, s = input().split(" ")
count = 0

for x in range(int(k)+1):
  for y in range(int(k)+1):
    for z in range(int(k)+1):
      a = x + y + z
      if int(s) == a:
        count += 1

print(count)

### FIXED CODE ###

k, s = map(int, input().split())
count = 0

for x in range(k+1):
  for y in range(k+1):
    z = s - x -y
    if z >= 0 and z <= k:
      count += 1

print(count)
### BUGGY CODE ###

s = list(str(input()))
t = list(str(input()))
flag = 'Yes'
for i in range(len(s)):
    for j in range(i):
        if s[i] == s[j] and t[i] != t[j]:
            flag = 'No'
            break
        elif t[i] == t[j] and s[i] != s[j]:
            flag = 'No'
            break
        if flag == 'No':
            break
    if flag == 'No':
        break

print(flag)

### FIXED CODE ###

import sys
s = str(input())
t = str(input())
l = len(s)
tmp = [[], []]
for i in range(l):
    if (not s[i] in tmp[0]) and (not t[i] in tmp[1]):
        tmp[0].append(s[i])
        tmp[1].append(t[i])
    else:
        if s[i] in tmp[0]:
            tmp2 = 0
            for j in range(len(tmp[0])):
                if s[i] == tmp[0][j]:
                    tmp2 = j
            if t[i] != tmp[1][tmp2]:
                print('No')
                sys.exit()
        else:
            print('No')
            sys.exit()
print('Yes')