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

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

count = 0
flg = True

for i in range(len(H)-1):
  if H[i] > min(H[i:]):
    H[i] -= 1
  if i!=0 and H[i-1] > H[i]:
    flg = False
    break

if flg==True:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
 
hmax = H[-1]
 
for h in reversed(H):
  if h <= hmax:
    hmax = h
    continue
  if h-1 <= hmax:
    hmax = h-1
    continue
  print('No')
  quit()

print('Yes')
### BUGGY CODE ###

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

for i in range(len(a)):
    for j in range(len(a)):
        if i<j:
            sum += (a[i]%(10**9+7)) * (a[j]%(10**9+7))
    
print(sum % 1000000007)

### FIXED CODE ###

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

for i in range(len(a)):
    b -= a[i]
    sum += a[i]*b   

print(sum%(10**9+7))
### BUGGY CODE ###

from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)
### BUGGY CODE ###

firstvar = input()
l = int(firstvar.split(" ")[0])
r = int(firstvar.split(" ")[1])
i = l
min = 2019
while i <= r:
    j = i + 1
    while j <= r:
        mod = (i*j)%2019
        if mod < min:
            min = mod
            if mod == 0:
                break;
        j = j + 1
    i = i + 1
print(min)

### FIXED CODE ###

firstvar = input()
l = int(firstvar.split(" ")[0])
r = int(firstvar.split(" ")[1])
i = l
min = 2019
if (r/2019 - l/2019) >= 1:
    print(0)
else:
    for i in range(l,r + 1):
        for j in range(i + 1, r + 1):
            mod = (i*j)%2019
            if mod < min:
                min = mod
                if mod == 0:
                    break;
    print(min)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import deque


class LinkedList:
    def __init__(self, n):
        self.n = n
        self.ll = [[] for _ in range(self.n)]

    def link(self, u, v, direction=False):
        self.ll[u].append(v)
        if not direction:
            self.ll[v].append(u)

    def check(self, start, goal):
        states = [0] * self.n
        queue = deque([start])

        while queue:
            u = queue.popleft()
            if states[u]:
                continue
            else:
                states[u] = 1

            for v in self.ll[u]:
                if v == goal:
                    print('yes')
                    return
                queue.append(v)

        else:
            print('no')
            return


if __name__ == '__main__':
    n, m = map(int, input().split())
    ll = LinkedList(n)

    for _ in range(m):
        u, v = map(int, input().split())
        ll.link(u, v)

    q = int(input())
    for _ in range(q):
        u, v = map(int, input().split())
        ll.check(u, v)



### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)


class LinkedList:
    def __init__(self, n):
        self.n = n
        self.ll = [[] for _ in range(self.n)]

    def link(self, u, v, direction=False):
        self.ll[u].append(v)
        if not direction:
            self.ll[v].append(u)

    def dfs(self):
        self.cc = [None] * self.n

        color = 1
        for u in range(self.n):
            if not self.cc[u]:
                self.dfs_visit(u, color)
                color += 1

    def dfs_visit(self, u, color):
        self.cc[u] = color
        for v in self.ll[u]:
            if not self.cc[v]:
                self.dfs_visit(v, color)

    def check(self, u, v):
        if self.cc[u] == self.cc[v]:
            print('yes')
        else:
            print('no')


if __name__ == '__main__':
    n, m = map(int, input().split())
    ll = LinkedList(n)

    for _ in range(m):
        u, v = map(int, input().split())
        ll.link(u, v)
    ll.dfs()

    q = int(input())
    for _ in range(q):
        u, v = map(int, input().split())
        ll.check(u, v)
### BUGGY CODE ###

INF = float("inf")

H, N, *AB = map(int, open(0).read().split())

dp = [0] * (H + 10 ** 4 + 10)

for i in range(1, len(dp)):
    dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(AB)] * 2))

print(min(dp[H:]))

### FIXED CODE ###

INF = float("inf")

H, N, *AB = map(int, open(0).read().split())

dp = [INF] * (H + 10 ** 4 + 10)
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, len(dp)):
        if dp[i - a] != INF:
            dp[i] = min(dp[i], dp[i - a] + b)

print(min(dp[H:]))
### BUGGY CODE ###


import numpy as np
import sys

input = sys.stdin.readline

s = int(input())

ans = 1

while s != 4:
    if s%2 :
        s = s/2
    else:
        s = 3*s + 1
    
    ans+=1


print(ans+3)


### FIXED CODE ###


import numpy as np
import sys

input = sys.stdin.readline

s = int(input())

if s == 1 :
    n = 2
elif s == 2:
    n = 1
else:
    n = 3

ans = 1

while s != 4:
    if s%2 == 0 :
        s = s/2
    else:
        s = 3*s + 1
    
    
    ans+=1


print(ans+n)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
counter = 0
for i in range(0, n, 2):
    if a.index(b[i])%2 == 1:
        counter += 1
print(counter)

### FIXED CODE ###

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = sorted(a)
    c = b[::2]
    d = a[::2]
    set_c = set(c)
    set_d = set(d)
    print(len(set_c - set_d))
main()
### BUGGY CODE ###

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

while len(a)>1:
  a.sort()
  a=[i%a[0] for i in a if a.index(i) != 0] + [a[0]]
  a=[i for i in a if i > 0]

print(a[0])

### FIXED CODE ###

from fractions import gcd
def list_gcd(list):
    c=list[0]
    for i in list:
        c=gcd(c,i)
    return c
n=int(input())
print(list_gcd(list(map(int,input().split()))))
### BUGGY CODE ###

N,S = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
MOD = 998244353

from collections import defaultdict
dp = defaultdict(lambda: 0)
dp[0] = 1
B = 10000
for a in A:
    for k,v in list(dp.items()):
        if k%B + a > S: continue
        dp[k+a+B] += v

ans = 0
for k,v in dp.items():
    if k%B!=S: continue
    i = k//B
    ans += pow(2,N-i,MOD) * v
print(ans%MOD)

### FIXED CODE ###

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

dp = [[0]*(S+1) for i in range(N+1)]
dp[0][0] = 1

for i,a in enumerate(A):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= MOD
        if j+a <= S:
            dp[i+1][j+a] += dp[i][j]
            dp[i+1][j+a] %= MOD
print(dp[-1][-1])
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import collections

def main():
    N = int(input())
    Q = [collections.deque(map(int, input().split())) for _ in range(N)]
    games = N*(N-1)//2

    days = 0
    while True:
        gamed = [0 for _ in range(N)]
        for i in range(N-1):
            if gamed[i] > 0 or len(Q[i]) == 0:
                continue
            j = Q[i][0] - 1
            if gamed[j] > 0 or len(Q[j]) == 0:
                continue
            if Q[j][0] == i+1:
#                print("game:", j+1, i+1, days)
                Q[i].popleft()
                Q[j].popleft()
                gamed[i] = 1
                gamed[j] = 1
                games -= 1
                continue
        days += 1
        if not 1 in gamed:
            print(-1)
            return
        if games == 0:
            break

    print(days)
if __name__ == '__main__':
    main()


### FIXED CODE ###

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

def main():
    N = int(input())
    Q = [deque(map(int, input().split())) for _ in range(N)]
    games = N*(N-1)//2

    days = 0
    nxt = [i for i in range(N)] # 翌日に対戦相手を更新する選手のリスト
    opp = [0]*N # 選手毎の、次の対戦相手のリスト
    while 1:
        days += 1
        for i in nxt:
            opp[i] = Q[i].popleft() - 1 if Q[i] else -1

        tmp = set() # 次の日の更新のため、試合をした選手をメモ
        for i in nxt:
            if i not in tmp and i == opp[opp[i]]:
#                print("game:", i+1, opp[i]+1, days)
                tmp.add(i)
                tmp.add(opp[i])
                games -= 1
        if games == 0:
            break
        elif not tmp:
            print(-1)
            return
        nxt = tmp
    print(days)

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

N=int(input())
L=input().split()
L=list(map(int,L))
# print(N)
# print(L)
# print("")
count=0
i=0
while i+1 in L:
        K=L.index(i+1)
        # print(i+1)
        # print("は")
        # print(K+1)
        # print("番目")
        # print(L)
        # print("↓")
        L=L[K+1:]
        # print(L)
        count+=1
        # print("count")
        # print(count)
        # print("")
        i+=1
if count==0:
    print(-1)
else:
    print(N-count)

### FIXED CODE ###

N=int(input())
L=input().split()
L=list(map(int,L))
count=0
i=1

for j in range(N):
    if i==L[j]:
        i+=1

if i==1:
    print(-1)
else:
    print(N-i+1)
### BUGGY CODE ###

n = int(input())
s = input()
ans = 10**9

for i in range(n):
  west = s[:i].count("W")
  east = s[i+1:].count("E")
  ans = min(ans,west+east)

print(ans)

### FIXED CODE ###

N = input()
s = input()

#累積和 前処理 Eの数を集計
count = s.count('E')

ans = count
#左端1番目からリーダーをずらしながらチェック。
for ch in s:
    if ch == 'E':
        count -= 1
        ans = min(count,ans)
    else:
        count += 1
    
print(ans)
### BUGGY CODE ###

N=int(input())
P=list(map(int, input().split()))
count=1
for i in range(1,N):
  if min(P[:i+1])>=P[i]:
    count+=1
print(count)

### FIXED CODE ###

n=int(input())
p=list(map(int, input().split()))
ans=1
l=[p[0]]
buf=p[0]
for i in range(1,n):
    l.append(p[i])
    if p[i]<=buf:
        ans+=1
        buf=p[i]
print(ans)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

maxmax=max(a)

for i in range(n):
    if a[i]!=maxmax:
        print(maxmax)
    elif a[i]==maxmax:
        temp=a[i]
        a[i]=0
        print(max(a))
        a[i]=temp

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

maxmax=max(a)
maxmax_ind=a.index(maxmax)
a[maxmax_ind]=0
maxmax2=max(a)
a[maxmax_ind]=maxmax

if maxmax==maxmax2:
    for i in range(n):
        print(maxmax)

else:
    for i in range(n):
        if i==maxmax_ind:
            print(maxmax2)
        else:
            print(maxmax)
### BUGGY CODE ###

import numpy as np
N, M, Q = list(map(int, input().split()))
p_q = np.zeros([Q, 2], dtype = int)
MAP = np.zeros([500, 500], dtype = int)

for _ in range(M):
    L, R = list(map(int, input().split()))
    MAP[L - 1][R - 1] += 1
for i in range(Q):
    p, q = list(map(int, input().split()))
    p_q[i][0] = p
    p_q[i][1] = q

for i in p_q:
    print(np.sum(MAP[i[0] - 1:i[1], i[0] - 1:i[1]]))


### FIXED CODE ###

import numpy as np
N, M, Q = map(int, input().split())
X = np.zeros((N, N), dtype=int)
ends = np.zeros((M, 2), dtype=int)
queries = np.zeros((Q, 2), dtype=int)
for i in range(M):
    ends[i] = [int(item) for item in input().split()]
for i in range(Q):
    queries[i] = [int(item) for item in input().split()]
np.add.at(X, [ends[:,0] - 1, ends[:, 1] - 1], 1)
B = np.cumsum(X[::-1,:], axis = 0)[::-1,:]
C = np.cumsum(B, axis = 1)
for item in queries:
    print(C[item[0] - 1, item[1] - 1])
### BUGGY CODE ###

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

cnt = 0
chk = [0]*1000
for j in range(1000):
    j = str(j).zfill(3)
    for i, s in enumerate(S):
        if s == j[0]:
            for ii, ss in enumerate(S[i+1:]):
                if ss == j[1]:
                    for iii, sss in enumerate(S[i+ii+2:]):
                        if sss == j[2]:
                            if chk[int(j)] == 1:
                                continue
                            chk[int(j)] = 1
                            cnt += 1
print(cnt)


### FIXED CODE ###

# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

cnt = 0
for num in range(1000):
    snum = str(num).zfill(3)
    # print("snum", snum)
    ind = 0
    chkind = 0
    # while ind < len(S):
    for s in S:
        if chkind >= 3:
            break
        if s == snum[chkind]:
            chkind += 1
    if chkind == 3:
        cnt += 1
print(cnt)
### BUGGY CODE ###

def my_pow(x,n):
    if n == 0:
        return 1
    if n % 4 == 0:
        return my_pow(x**4,int(n/4))
    elif n%4 == 1:
        return my_pow(x,int(n-1))*x
    elif n%4 == 2:
        return my_pow(x,int(n-2))*x*x
    elif n%4 == 3:
        return my_pow(x,int(n-3))*x*x*x
n,m = map(int,input().split())
x = 1000000007
print(my_pow(n,m)%x)

### FIXED CODE ###

def mpow(x,n,mod):
    if n == 0:
        return 1
    if n % 4 == 0:
        return mpow((x**4)%mod,int(n/4),mod)
    elif n%4 == 1:
        return (mpow(x,int(n-1),mod)*x)%mod
    elif n%4 == 2:
        return (mpow(x,int(n-2),mod)*(x**2))%mod
    elif n%4 == 3:
        return (mpow(x,int(n-3),mod)*(x**3))%mod
n,m = map(int,input().split())
mod = 1000000007
print(mpow(n,m,mod))
### BUGGY CODE ###

import heapq

n, m = map(int, input().split())
ba=[]
for i in range(n):
    a, b = map(int, input().split())
    ba.append([-b, a])
heapq.heapify(ba)

ans=0

for i in range(m - 1, -1, -1):
    not_use = []
    while ba:
        l = heapq.heappop(ba)
        if l[1] + i <= m:
            ans += l[0] * -1
            break
        else:
            not_use.append(l)
    for j in not_use:
        heapq.heappush(ba, j)
print(ans)    

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
l = [[] for _ in range(m)]
 
for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        l[a-1].append(b)

a = []
ans = 0

for i in range(m):
    for j in l[i]:
        heapq.heappush(a, (-1) * j)
    if a:
        ans += heapq.heappop(a) * (-1)
        
print(ans)
### BUGGY CODE ###

class BIT:
    def __init__(self,n):
        self.tree = [0] * (n+1)
        self.size = n
    
    def add(self,i,x):
        while i <= self.size:
            self.tree[i] += x
            i += i&-i
    
    def get(self,i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i&-i
        return s


N,Q = map(int,input().split())
C = list(map(int,input().split()))
LR = [list(map(int,input().split()))+[i] for i in range(Q)]
LR.sort(key=lambda x: x[1])
bit = BIT(N)
stone = [0]*(N+1)
cur = 1
ans = []
for l,r,i in LR:
    while cur <= r:
        c = C[cur-1]
        if stone[c]:
            bit.add(stone[c],-1)
        stone[c] = cur
        bit.add(stone[c],1)
        cur += 1
    ans.append([bit.get(r)-bit.get(l-1),i])
ans.sort(key=lambda x: x[1])
for a,i in ans:
    print(a)

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0]*(n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def sum(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s

    N,Q = map(int,input().split())
    bit = BIT(N)
    C = list(map(int,input().split()))
    query = []
    for i in range(Q):
        l,r = map(int,input().split())
        query.append([l,r,i])
    query.sort(key=lambda x: x[1])
    ans = [0]*Q
    #良い玉のindexを1-indexで管理する
    colorMemo = [0]*(N+1)
    cur = 1
    for q in query:
        l,r,j = q
        #良い玉の情報を更新する
        for i in range(cur,r+1):
            c = C[i-1]
            if colorMemo[c]:
                bit.add(colorMemo[c],-1)
            bit.add(i,1)
            colorMemo[c] = i
        cur = r + 1
        ans[j]=bit.sum(r)-bit.sum(l-1)

    print(*ans, sep="\n")
main()
### BUGGY CODE ###

n,*A=map(int,open(0).read().split())
f=[1]*(n+2);r=f[:]
MOD=10**9+7
for i in range(n+1):f[i+1]=e=f[i]*-~i%MOD;r[i+1]=pow(e,MOD-2,MOD)
for i in range(1,n+1):
    try:
        L=A.index(i);R=A.index(i,L+1)
        for k in range(1,n+2):
            print((f[n+1]*r[k]*r[n+1-k]-(k<=L+n+1-R and f[L-1+n+1-R]*r[k-1]*r[L+n+1-k-R]))%MOD)
    except:...


### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
fact = [0]*(n+1)
frev = [0]*(n+1)
MOD = 10**9 + 7
frev[0] = fact[0] = 1

for i in xrange(1, n+1):
    fact[i] = (fact[i-1] * i) % MOD
    frev[i] = pow(fact[i], MOD-2, MOD)

def comb(n, k):
    return (((fact[n] * frev[k]) % MOD) * frev[n-k]) % MOD

left = 0; right = 0
B = [0]*(n+1)
for a in A:
    B[a] += 1
p = B.index(2)
while A[left] != p:
    left += 1
while A[-1-right] != p:
    right += 1
mid = n+1 - left - right
ans = []
for k in xrange(1, n+2):
    res = 0
    if 0 <= k <= n-1:
        res += comb(n-1, k)
    if 0 <= k-1 <= n-1:
        if k-1 <= left+right:
            res += comb(left+right, k-1) + 2*(comb(n-1, k-1) - comb(left+right, k-1))
        else:
            res += 2*comb(n-1, k-1)
    if 0 <= k-2 <= n-1:
        res += comb(n-1, k-2)
    res %= MOD
    ans.append(res)
print "\n".join(map(str, ans))
### BUGGY CODE ###

N=int(input())
ls=[]
n=0
for i in range(N):
    str1=''.join(sorted(input()))
    if str1 in ls:
        n+=ls.count(str1)
        ls.append(str1)
    else:
        ls.append(str1)
print(n)        

### FIXED CODE ###

N=int(input())
dic={}
ans=0
for i in range(N):
    str1=''.join(sorted(input()))
    n=len(str1)
    if n in dic:
        if str1 in dic[n]:
            ans+=dic[n][str1]
            dic[n][str1]+=1
        else:
            dic[n][str1]=1
    else:
        dic[n]={str1:1}
    
print(ans)
### BUGGY CODE ###

import math

def comb(n,r):
    return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))
    
n = int(input())
x = list(map(int, input().split(" ")))

a = max(x)
temp = comb(a, x[0])
result = x[0]
for i in range(1, n):
    if x[i] == a:
        continue
    if temp <= comb(a, x[i]):
        temp = comb(a, x[i])
        result = x[i]

print(a , result)

### FIXED CODE ###

import math
 
def comb(n,r):
    return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

def deff_half(l, h):
    d = abs(h/2 - l[0])
    r = 0
    for i in range(1, len(l)):
        if l[i] == h:
            continue
        if d >= abs(h/2 - l[i]):
            d = abs(h/2 - l[i])
            r = i
    return l[r]
    
n = int(input())
x = list(map(int, input().split(" ")))
 
a = max(x)
result = deff_half(x, a)

print(a , result)
### BUGGY CODE ###

from collections import deque
n,m = map(int,input().split())
to = [[] for _ in range(n)]
v = []
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    v.append((a,b))
ans = m

for i in range(m):
    a,b = v[i]
    q = deque()
    q.append((a,-1))
    seen = [False]*n
    seen[a] = True
    flag = True
    while q and flag:
        cur,prev = q.popleft()
        for nxt in to[cur]:
            if nxt == b:
                if cur == a: continue
                ans -= 1
                flag = False
                break
            if nxt == prev: continue
            if seen[nxt]: continue
            q.append((nxt,cur))

print(ans)

### FIXED CODE ###

from collections import deque
n,m = map(int,input().split())
to = [[] for _ in range(n)]
v = []
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    v.append((a,b))
ans = m
seen = [False]*n
stk = deque()
for i in range(m):
    a,b = v[i]
    stk.clear()
    stk.append((a,-1))
    for j in range(n): seen[j] = False
    seen[a] = True
    flag = True
    while stk and flag:
        cur,prev = stk.pop()
        seen[cur] = True
        for nxt in to[cur]:
            if nxt == b:
                if cur == a: continue
                ans -= 1
                flag = False
                break
            if nxt == prev: continue
            if seen[nxt]: continue
            stk.append((nxt,cur))

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

d=[]
for _ in[0]*int(input()):
 e=input().split()
 if'i'==e[0][0]:d+=[e[1]]
 else:print(['no','yes'][e[1]in d])


### FIXED CODE ###

import sys
def m():
 d={};input()
 for e in sys.stdin:
  if'f'==e[0]:print(['no','yes'][e[5:]in d])
  else:d[e[7:]]=0
if'__main__'==__name__:m()
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
q = deque()
A = []
for h in range(H):
    r = input()
    for w in range(W):
        if r[w] == "#":
            q.append([h, w])
    A.append([0 if s=="#" else -1 for s in r])

d = [[-1, 0], [0, -1], [0, 1], [1, 0]]
p = 0

while q:
    h, w = q.popleft()
    p = A[h][w]+1
    for dh, dw in d:
        nh = h+dh
        nw = w+dw
        if not (0 <= nh < H):
            continue
        if not (0 <= nw < W):
            continue
        if A[nh][nw] == -1:
            A[nh][nw] = p
            q.append([nh, nw])

print(p-1)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
q = deque()
A = []
for h in range(H):
    r = input()
    for w in range(W):
        if r[w] == "#":
            q.append([h, w])
    A.append([0 if s=="#" else -1 for s in r])

d = [[-1, 0], [0, -1], [0, 1], [1, 0]]
p = 0

while q:
    h, w = q.popleft()
    p = A[h][w]+1
    for dh, dw in d:
        nh = h+dh
        nw = w+dw
        if not (0 <= nh < H):
            continue
        if not (0 <= nw < W):
            continue
        if A[nh][nw] == -1:
            A[nh][nw] = p
            q.append([nh, nw])

print(p-1)
### BUGGY CODE ###

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

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]
t = [0] * (n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
    print(t[lr[i][1]-1] - t[lr[i][0]-1])
### BUGGY CODE ###

def main():
    S = input()
    T = input()

    for i in range(len(S)):
        tmp = S[i]
        S = S.replace(T[i],'_')
        S = S.replace(S[i],T[i])
        S = S.replace('_',tmp)
    if S == T:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    S = input()
    T = input()

    start = [-1]*26
    goal = [-1]*26
    for i in range(len(S)):
        a = ord(S[i])-ord('a')
        b = ord(T[i])-ord('a')
        if start[a]!=-1 or goal[b]!=-1:
            if start[a]!=b or goal[b]!=a:
                print('No')
                return
        else:
            start[a] = b
            goal[b] = a
    print('Yes')


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

N = int(input())
P = list(map(int, input().split()))
A = [1 for i in range(1, N) if P[i] <= min(P[:i])]
print(sum(A) + 1)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
A = 1
M = P[0]
for i in range(1, N):
  M = min(M, P[i])
  if P[i] <= M:
    A += 1
print(A)