Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, X, M = map(int, input().split())

def mod(x):
    return x % M

a = X

i = 0

ans = 0
last = -1

dic = []

while a != 0 and i < N:
    ans += a
    a = mod(a * a)
    i += 1    

    if a in dic:
        last = dic.index(a)
        break

    dic.append(a)


if i != N and dic[last] != 0:
    tdic = dic[last:]
    if N - i >= len(tdic):
        sdic = sum(tdic)
        ans += sdic * ((N - i) // len(tdic))

    for j in range((N - i) % len(tdic)):
        ans += tdic[j]

print(ans)

### FIXED CODE ###

#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, X, M = map(int, input().split())

def mod(x):
    return x % M

a = X

i = 0

ans = 0
last = -1

dic = []

while a != 0 and i < N:
    ans += a
    a = mod(a * a)
    i += 1

    if a in dic:
        last = dic.index(a)
        break

    dic.append(a)


if i != N and a != 0:
    tdic = dic[last:]
    if N - i >= len(tdic):
        sdic = sum(tdic)
        ans += sdic * ((N - i) // len(tdic))

    for j in range((N - i) % len(tdic)):
        ans += tdic[j]

print(ans)
S = input()
K = int(input())

if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1   
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        a = 0
        b = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2)*(K-1))

### FIXED CODE ###

S = input()
K = int(input())

if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    cnt = 0
    lst = []
    tmp = S[0]
    for i in range(len(S)):
        if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
    if(cnt > 1):
        lst.append(cnt)
        
    ans = 0
    for i in lst:
        ans += K*(i//2)
    if(S[0] != S[-1]):
        print(ans)
    else:
        a = 0
        b = 0
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2))*(K-1))
n=int(input())
S=input()

if n % 2 == 1:
    print('No')
else:
    flg=True
    for i in range(int(n/2)):
        if S[i]!=S[int(n/2)+i]:
            flg=False
    if flg==True:
        print('Yes')
    else:
        print('No'):
  

### FIXED CODE ###

N=int(input())
S=str(input())
if N%2==1:
  print('No')
else:
  f=True
  h=int(N/2)
  for i in range(0,h):
    if S[i]!=S[h+i]:
      f=False
  if f==True:
    print('Yes')
  else:
    print('No')
N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)
        else:
            print(M-i)
            print(now-(M-i))
            break

### FIXED CODE ###

N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

elif N == 2:
    print(2)
    
elif N == 3:
    print(2)
    print(1)

elif N == 4:
    print(3)
    print(1)
    
else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M-1):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)

        else:
            print(M-i)
            if now-(M-i) != 0: 
                print(now-(M-i))
            break
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = 100
for i in range(ite):
  if i == ite-1:
    nums = list(range(start *i, finish ))
    else:
      nums = list(range(start *i, start*(i+1) ))
  tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
  count += len(tmp)
print(count)


### FIXED CODE ###

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
A,B,C,D = input().split()
A = int(A)-1
s = lcm(int(C),int(D))
#s = int(C)*int(D)
#numac = int(A)//int(C)#10//6 = 1
#numad = int(A)//int(D)#10//8 = 1
#numacd = int(A)//s#10//24 = 0
numa = int(A)//int(C) + int(A)//int(D) - int(A)//s
#numa = 1
#numbc = int(B)//int(C)#40//6 = 6
#numbd = int(B)//int(D)#40//8 = 5
#numbcd = int(B)//s#40//24= 1
numb = int(B)//int(C) + int(B)//int(D) - int(B)//s
#numb = 1
print(int(B)-int(A)-(numb - numa))
n = int(input())
list = list(map(int, input().split()))
sum = sum(list)
num = int(input())
for x in range(num):
    a = list(map(int, input().split()))
    ans = sum + a[1] - list[a[0]-1]
    print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split(" ")))
s = sum(l)
num = int(input())
for x in range(num):
    a = list(map(int, input().split()))
    ans = s + a[1] - l[a[0]-1]
    print(ans)
s=int(input())

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

### FIXED CODE ###

s=input()

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print('Bad')
else:
  print('Good')
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

def solve(i, m):
    if m == 0:
        return True
    if n <= i or sum(A) < m:
        return False
    res = (solve(i+1, m) or solve(i+1, m-A[i]))
    return res 
 
for m inrange M:
    if solve(0, m):
        print "yes"
    else:
        print "no"

### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

def solve(i, m):
    if m == 0:
        return True
    if n <= i or sum(A) < m:
        return False
    x = (solve(i+1, m) or solve(i+1, m-A[i]))
    return  x
 
for m in M:
    if solve(0, m):
        print "yes"
    else:
        print "no"
import math
import sys
sys.setrecursionlimit(200000)
A, B = map(int, input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(A, B))

### FIXED CODE ###

import fractions

A, B = map(int, input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(A, B))
N = int(input())
S = input()
K = int(input())

target = S[K - 1]
for i in range(N):
  if S[i] != target:
    S[i] = '*'
print(S)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())

target = S[K - 1]
ans = ''
for i in range(N):
  if S[i] != target:
    ans += '*'
  else:
    ans += S[i]
print(ans)
word = input()
b = word
d = word
f = word
h = word
def gyaku(x):
  x = list(x)
  x.reverse()
  return ''.join(x)
if gyaku('eraser') in gyaku(word):
  a = gyaku(word).split(gyaku('eraser'))
  b = ''.join(a)
  h = gyaku(b)
if gyaku('dreamer') in gyaku(h):
  g = gyaku(h).split(gyaku('dreamer')
  h = gyaku(''.join(g))
if gyaku('erase') in gyaku(h):
  c = gyaku(h).split(gyaku('erase'))
  d = ''.join(c)
  h = gyaku(d)
if gyaku('dream') in gyaku(h):
  e = gyaku(h).split(gyaku('dream'))
  f = ''.join(e)
  h = gyaku(f)
 
if h == (''):
  print('YES')
else:
  print('NO')

### FIXED CODE ###

word = input()
x = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if x == '':
  print('YES')
else:
  print('NO')
n,m=map(int,input().split())
a=list(map(int,input().split()))
import fractions
lmc=a[0]
for i in range(1,n):
    lmc=lmc*a[i]//fractions.gcd(lmc,a[i])
    if lmc>m:
        print("0")
        exit()
if i in range(n):
   if (lmc//a[i])%2==0:
   print("0")
   exit()
if (m%lmc)<lmc//2:
    print((m//lmc))
else:
    print((m//lmc)+1)

### FIXED CODE ###

n,m=map(int,input().split())
a = [int(x)//2 for x in input().split()]
import fractions
lmc=a[0]
for i in range(1,n):
    lmc=lmc*a[i]//fractions.gcd(lmc,a[i])
    if lmc>m:
        print("0")
        exit()
for i in range(n):
   if (lmc//a[i])%2==0:
      print("0")
      exit()
if (m//lmc)%2==0:
    print((m//lmc)//2)
else:
    print(((m//lmc)+1)//2)
r=int(input())
a=3(r*r)


### FIXED CODE ###

r=int(input())
a=3*(r*r)
print(a)
a,b = map(int,input())

if a >= 2b:
    print(a-2*b)
else:
    print("0")

### FIXED CODE ###

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

if a >= 2*b:
    print(a-2*b)
else:
    print("0")
N=int(input())
lst=[int(i) for i in input().split()]
for i in range(n):
  lst[i]=lst[i]//2
print(min(ans))
  

### FIXED CODE ###

n=int(input())
lst=[int(i) for i in input().split()]
ans=[0]*n
for i in range(n):
  while lst[i]%2==0:
    lst[i]=lst[i]//2
    ans[i]+=1
print(min(ans))
n = int(input())
p = list(map(int,input().split()))

dic = {}
for i in range(n-1):
    a = p[i+1]-p[i]
    if a in dic and a != 1:
        dic[a] += 1
    elif a not in dic and a != 1:
        dic[a] = 1

flag = False
for k,v in dic.values():
    if i == 2 :
        flag = True
        break
    else:
        continue

if flag:
    print("YES")
else:
    if len(dic) == 0:
        print("YES")
    else:
        print("NO")


### FIXED CODE ###

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

count = 0
for i in range(n):
    if i+1 != p[i]:
        p[i] == i+1
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")
l = list(int, input())

for i in range(5):
  if l[i] == 0:
    print(i+1)
    exit()

### FIXED CODE ###

l = list(map(int,input().split()))

for i in range(5):
  if l[i] == 0:
    print(i+1)
    exit()
n=int(input())
x=input()
s=list(x)
list=[]
 
for i in range(n):
    a=0
    moji=[]
    for j in range(i):
        for k in range(n-i):
            if s[j]==s[k+i-1]:
                if s[j] not in moji:
                    a+=1
                    moji.append(s[j])
    list.append(a)
 
f=max(list)
print(f)

### FIXED CODE ###

a, b= map(int, input().split())
 
c=a+b
d=a-b
e=a*b
 
f=max([c, d, e])
 
print(f)
import sys
input = sys.stdin.readline
import bisect
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
both = []
for i in range(n):
  both.extend(ab[i])
both.sort()
ans = 10**18
sm = sum(both[:n])
for i in range(n):
  ai = bisect.bisect_left(both,ab[i][0])
  bi = bisect.bisect_left(both,ab[i][1])
  if ai < n and bi < n:
    ans = min(ans,sm)
  elif ai < n:
    ans = min(ans,sm-both[n-1]+ab[i][1])
  elif bi < n:
    ans = min(ans,sm-both[n-1]+ab[i][0])
  else:
    ans = min(ans,sm-both[n-1]-both[n-2]+sum(ab[i]))
a,b = list(zip(*ab))
ans = min(ans,sum(a),sum(b))
if ans != sm:
  print(2/0)
else:
  print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
both = []
for i in range(n):
  both.extend(ab[i])
both.sort()
ans = 10**18
sm = sum(both[:n])
for i in range(n):
  ai = bisect.bisect_left(both,ab[i][0])
  bi = bisect.bisect_left(both,ab[i][1])
  if ai < n and bi < n:
    ans = min(ans,sm)
  elif ai < n-1:
    ans = min(ans,sm-both[n-1]+ab[i][1])
  elif ai == n-1:
    ans = min(ans,sm-both[n-2]+ab[i][1])
  elif bi < n-1:
    ans = min(ans,sm-both[n-1]+ab[i][0])
  elif bi == n-1:
    ans = min(ans,sm-both[n-2]+ab[i][0])
  else:
    ans = min(ans,sm-both[n-1]-both[n-2]+sum(ab[i]))
a,b = list(zip(*ab))
ans = min(ans,sum(a),sum(b))
print(ans)
(a, b) = [int(i) for i in input()]
  2 d = a // b
  3 r = a % b
  4 f = a / b
  5 print('%s %s %.5f' % (d, r, f)

### FIXED CODE ###

(a, b) = [int(i) for i in input().split()]
  
while True:
    d = a // b
    r = a % b
    f = a / b
    print( '{0:d} {1:d} {2:.5f}'.format( d, r, f))
    break
a,b,n=map(int,input().split())
maxs=0
if a>=b:
    if n>=b:
        maxs=a/b*(b-1)-(a%b*(b-1))%b/b
    else:
        maxs=a/b*n-(a%b*n)%b/b
else:
    if n>=b:
        maxs=(a*(b-1))//b
    else:
        maxs=(a*n)//b
print(int(maxs))

### FIXED CODE ###

k=int(input())
a,b=map(int,input().split())
if a%k==0:
    print('OK')
else:
    
    if a//k*k+k<=b:
        print('OK')
    else:
        print('NG')
N, X, M = map(int, input().split())
a = [0 for i in range(M+1)]
b = [X]
a[X-1] = 1

for i in range(min(N, M)):
  X = X**2%M
  a[X-1] += 1
  b.append(X)
  if a[X-1] > 1:
    break

if len(b) == N:
  print(sum(b))

else:
  ls = b.index(b[-1])
  bloop = b[ls:-1]
  ans = 0
  if ls > 0:
    for i in range(ls):
      ans += b[i]
  loop = (N-ls)//len(bloop)
  ans += sum(bloop) * loop
  if (N-ls)%len(bloop) != 0:
    for i in range((N-ls)%len(bloop)):
      ans += bloop[i]
  print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())
a = [0 for i in range(M+1)]
b = [X]
a[X-1] = 1

for i in range(min(N-1, M)):
  X = X**2%M
  a[X-1] += 1
  b.append(X)
  if a[X-1] > 1:
    break

if len(b) == N:
  print(sum(b))

else:
  ls = b.index(b[-1])
  bloop = b[ls:-1]
  ans = 0
  if ls > 0:
    for i in range(ls):
      ans += b[i]
  loop = (N-ls)//len(bloop)
  ans += sum(bloop) * loop
  if (N-ls)%len(bloop) != 0:
    for i in range((N-ls)%len(bloop)):
      ans += bloop[i]
  print(ans)
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

### FIXED CODE ###

X=int(input())
if X>=30:
  print("Yes")
else:
  print("No")
n=input('input: ')

a=pow(n,3)
print(a)



### FIXED CODE ###

x=input('')

print(int(x)**3)
N,M=int(input().split())

print(N*(N-1)/2+M*(M-1)/2)

### FIXED CODE ###

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

print((N*(N-1)//2)+(M*(M-1)//2))
from fractions import gcd
def lcm(a, b):
    return abs(a*b) // math.gcd(a, b)
a,b = list(map(int,input().split()))
print(lcm(a,b))

### FIXED CODE ###

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

def lcm(a,b): 
    return (a*b) / gcd(a,b) 
a,b = list(map(int,input().split()))
print(int(lcm(a,b)))
N = str(input())
if '7' in N:
  print('Yes'):
else:
  print('No')

### FIXED CODE ###

N = input()
if '7' in N:
  print('Yes')
else:
  print('No')
N = int(input())
S = input()
x = 0
length = len(S)
List = [0]
for i in range(length):
  if(S[i] == I):
    x += 1
    List.append(x)
  else:
    x -= 1
    List.append(x)
print(max(List))

### FIXED CODE ###

N = int(input())
S = input()
x = 0
length = len(S)
List = [0]
for i in range(length):
  if(S[i] == "I"):
    x += 1
    List.append(x)
  else:
    x -= 1
    List.append(x)
print(str(max(List)))
# 入力
N=int(input())
l=list(map(int,input().split()))

ln=len(set(l))

if ln==3:
  print('Three')
else:
  print('Four')

### FIXED CODE ###

n=int(input())
*s,=map(str,input().split())
if len(set(s))==3:
	print('Three')
else:
	print('Four')
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if x % y==0:
    return x
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*int(m/d)
if d==1:
  print(n*m)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)

### FIXED CODE ###

n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if max(x,y) % min(x,y)==0:
    return min(x,y)
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*int(m/d)
if d==1:
  if s[0]==t[0]:
    print(n*m)
  else:
    print(-1)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)
N, a = map(int, input().split())
*x, = (map(int, input().split()))
dp = [[[0]*(50*N+1) for _ in range(N+1)] for i in range(N+1)]
for i in range(N+1):
    for j in range(N+1):
        for k in range(50*N+1):
            if i == j == k == 0:
                dp[i][j][k] = 1
            elif i and k < x[i-1]:
                dp[i][j][k] = dp[i-1][j][k]
            elif i and j and k >= x[i-1]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]]
ans = 0
for j in range(1, N+1):
    ans += dp[N][j][a*j]
print(ans)



### FIXED CODE ###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N <= K:
    print(N * X)
else:
    print(K * X + (N - K) * Y)
N = int(raw_input())
A = map(int, raw_input().split())

def hmtd(n):
  ans = 0
  while n % 2 == 0:
    n /= 2
    ans += 1
    return ans

ans = min(map(hmtd, A))
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(l) for l in input().split()]


count1 = 0
k = 0
while True:
  count2 = 0
  for i in range(N):
      if A[i]/2** k % 2 !=0:
        break
      else:
        count2 += 1
  if count2 == N:
    count1 += 1
  else:
    break
  k += 1

print(count1)
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
for i in range(0,M):
  s[i],c[i]=map(int,input().split())

flag=0
data=[-1 for i in range(0,N)]
for i in range(0,M):
  if data[s[i]-1]==-1:
    data[s[i]-1]=c[i]
  else:
    if data[s[i]-1]!=c[i]:
      flag=1
if data[0]==0:
  flag=1
if flag==1:
  print(-1)
else:
  for i in range(0,N):
    if data[i]==-1:
      if i==0:
        data[i]=1
      else:
        data[i]=0
  ans=''
  for i in range(0,M):
    ans+=str(data[i])
  print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
s=[0]*M
c=[0]*M
for i in range(0,M):
  s[i],c[i]=map(int,input().split())

flag=0
data=[-1 for i in range(0,N)]
for i in range(0,M):
  if data[s[i]-1]==-1:
    data[s[i]-1]=c[i]
  else:
    if data[s[i]-1]!=c[i]:
      flag=1
if data[0]==0 and N!=1:
  flag=1
if flag==1:
  print(-1)
else:
  for i in range(0,N):
    if data[i]==-1:
      if i==0 and N>1:
        data[i]=1
      else:
        data[i]=0
  ans=''
  for i in range(0,N):
    ans+=str(data[i])
  print(ans)
s=input()
t=input()
n=len(s)
A='abcdefghijklmnopqrstuvwxyz'
i=0
while A and i<n+1:
	if s==t:
		print('Yes')
		exit()
	if s[i]!=t[i]:
		if s[i] in A and t[i] in A:
			s=s.replace(s[i],'X').replace(t[i],s[i]).replace('X',t[i])
			A=A.replace(s[i],'').replace(t[i],'')
	i+=1
print('No')

### FIXED CODE ###

s=input()
t=input()
n=len(s)
A='abcdefghijklmnopqrstuvwxyz'
i=0
while A:
	if s==t:
		print('Yes')
		exit()
	if i==n:
		print('No')
		exit()
	if s[i]!=t[i]:
		if s[i] in A and t[i] in A:
			s=s.replace(s[i],'X').replace(t[i],s[i]).replace('X',t[i])
			A=A.replace(s[i],'').replace(t[i],'')
	i+=1
print('No')
import sys

n=int(input())
l=[int(x) for x in input().rstrip().split()]
l.sort()
num=[0]*max(l)
for i in l:
  num[i-1]+=1

ans=0
for i in range(n):
  for j in range(i+1,n):
    for s in range(j+1,n):
      if l[i]!=l[j] and l[j]!=l[s] and l[i]!=l[s]:
        if l[i]<l[j]+l[s] and l[j]<l[i]+l[s] and l[s]<l[i]+l[j]:
          ans+=1
print(ans)




### FIXED CODE ###

import sys

n=int(input())
l=[int(x) for x in input().rstrip().split()]
l.sort()


ans=0
for i in range(n):
  for j in range(i+1,n):
    for s in range(j+1,n):
      if l[i]!=l[j] and l[j]!=l[s] and l[i]!=l[s]:
        if l[i]<l[j]+l[s] and l[j]<l[i]+l[s] and l[s]<l[i]+l[j]:
          ans+=1
print(ans)
N = int(input())

nums = []
sum = 0
for i in range(0,N):
    num = input()
    if num in nums:
        nums.remove(num)
    else:
        nums.append(num)
        sum = sum + 1
print(sum)

### FIXED CODE ###

N = int(input())

if N >= 90:
    print("Yes")
elif (N+1)%10 is 0:
    print("Yes")
else:
     print("No")
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(input())
import queue
todo = queue.Queue()
for y in range(H):
    for x in range(W):
        if A[y][x] == '#':
            exist = True
            todo.put((x, y))

seen = [[False] * W for _ in range(H)]
route= [[0] * W for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def bfs(el):
    x, y = el
    #print(x, y)
    seen[y][x] = True
    for i in range(4):
        if 0 <= x + dx[i] < W and 0 <= y + dy[i] < H:
            if seen[y + dy[i]][x + dx[i]] == False and A[y + dy[i]][x + dx[i]] == '.':
                route[y + dy[i]][x + dx[i]] = route[y][x] + 1
                seen[y + dy[i]][x + dx[i]] = True
                todo.put((x + dx[i], y + dy[i]))
    if not todo.empty():
        bfs(todo.get())
    else:
        return None
bfs(todo.get())
#print(seen)
#print(route)

M = 0
for y in range(W):
    for x in range(H):
        M = max(M, route[y][x])
print(M)

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
matrix = [["a" for _ in range(w+2)]] + [list("a" + input() + "a") for _ in range(h)] + [["a" for _ in range(w+2)]]

matrix_list1 = deque()
cnt = 0

#黒いタイルの位置情報を確認
for i in range(1,h+1):
    for j in range(1,w+1):
        if matrix[i][j] == "#":
            matrix_list1.append([i,j])

#白いタイルが無くなるまで、黒いタイルを増やす
while len(matrix_list1) != 0:     
    for _ in range(len(matrix_list1)):
        x,y = matrix_list1.popleft()
        if matrix[x+1][y] == ".":
            matrix[x+1][y] = "#"
            matrix_list1.append([x+1,y])
        if matrix[x-1][y] == ".":
            matrix[x-1][y] = "#"
            matrix_list1.append([x-1,y])
        if matrix[x][y+1] == ".":
            matrix[x][y+1] = "#"
            matrix_list1.append([x,y+1])
        if matrix[x][y-1] == ".":
            matrix[x][y-1] = "#"
            matrix_list1.append([x,y-1])
    else:
        if len(matrix_list1) > 0:
            cnt += 1
    
print(cnt)
x, a, b = map(int, input().split())
if abs(z-a) <  abs(z-b):
  print('A')
else:
  print('B')

### FIXED CODE ###

x, a, b = map(int, input().split())
if abs(x-a) <  abs(x-b):
  print('A')
else:
  print('B')
r,d,x = map(int, input().split())
result=[]
result.append(x)
for i in range(10):
	x=r*x-d
	result.append(x)
for i in result[1:11]:
	print(str(i))

### FIXED CODE ###

a, b = map(int, input().split())
if a>=13:
  print(int(b))
elif 6<=a<=12:
  print(int(b/2))
else:
  print(int(0))
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
if len(set(A)) == N:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

if __name__ == "__main__":
    S, T = input().split()
    A, B = map(int, input().split())
    U = input()

if U == S:
    A -= 1
else:
    B -= 1
print(A, B)
N, M = map(int, input().split())
a = set([int(input()) for i in range(M)])
n = [0] * N
n[0] = 1
n[1] = 2

#listの中をinで探すのはくっそ遅い
if N == 1:
    print(1)
    exit()
if 1 in a and 2 in a:
    print(0)
    exit()
if 1 in a:
    n[0] = 0
    n[1] = 1
if 2 in a:
    n[1] = 0

for i in range(2, N):
    if i + 1 in a:
        continue
    else:
        n[i] = (n[i - 1] + n[i - 2]) % 1000000007

print(n[N - 1])

### FIXED CODE ###

N, M = map(int, input().split())
a = set([int(input()) for i in range(M)])
n = [0] * (N + 1)
n[0] = 1
n[1] = 1

#listの中をinで探すのはくっそ遅い
if 1 in a:
    n[1] = 0

for i in range(2, N + 1):
    if i in a:
        continue
    else:
        n[i] = (n[i - 1] + n[i - 2]) % 1000000007

print(n[N])
a,b,c=sorted(input().split())
print(eval(f"{c}{b}+{a}"))

### FIXED CODE ###

a,b,c=sorted(input().split())
print(eval("{}{}+{}".format(c,b,a)))
W=input()
T=''
while 1:
 a=input()
 if'END_OF_TEXT'!=a:T+=a'
 else:break
 T+=' '
print(T.count(W))

### FIXED CODE ###

import sys
W=input()
print(sys.stdin.read().lower().split().count(W))