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

from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)  

### FIXED CODE ###

from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)
### BUGGY CODE ###

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

a = list(set((A)))
check = len(a)
dff = check - K
if dff <= 0:
  print(0)
  exit(0)
ans_list = []

for i in range(check):
  ans = 0
  checker = a[i]
  for j in range(len(A)):
    if checker == A[j]:
      ans += 1
  ans_list.append(ans) 

ans_list.sort()

result = sum(ans_list[:dff])
print(result)

### FIXED CODE ###

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

a = list(set((A)))
check = len(a)
dff = check - K
if dff <= 0:
  print(0)
  exit(0)
ans_list = [0]*check
A.sort()
index = 0
for i in range(len(A)):
  
  if i >= 1 and A[i] != A[i-1]:
    index += 1
  ans_list[index] += 1
ans_list.sort()
result = sum(ans_list[:dff])
print(result)
### BUGGY CODE ###


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

RD = []
end = [False] * N

for i in range(N):

    RD.append([])

for i in range(M):

    L,R,D = map(int,input().split())
    RD[L-1].append([R-1,D])
    RD[R-1].append([L-1,-1 * D])
    end[L-1] = True
    end[R-1] = True
    
"""
    lp = wantp(L-1)
    rp = wantp(R-1)

    if lp != rp:

        if rank[lp] 
"""
    


endnum = 0
Q = []

cor = ["x"] * N
ans = "Yes"


for endp in range(N):

    if end[endp]:
        Q.append(endp)
    else:
        continue

    while len(Q) > 0:

        q = Q.pop(0)
        end[q] = False

        if cor[q] == "x":
            cor[q] = 0

        for r,d in RD[q]:

            if cor[r] == "x":
                cor[r] = cor[q] + d
                Q.append(r)

            elif cor[r] != cor[q] + d:
                ans = "No"
                break

        if ans == "No":
            break

    if ans == "No":
        break

print (ans)


### FIXED CODE ###

from collections import deque

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

RD = [deque() for i in range(N)]
end = [False] * N

for i in range(M):

    L,R,D = map(int,input().split())
    RD[L-1].append([R-1,D])
    RD[R-1].append([L-1,-1 * D])
    end[L-1] = True
    end[R-1] = True
    
"""
    lp = wantp(L-1)
    rp = wantp(R-1)

    if lp != rp:

        if rank[lp] 
"""
    


endnum = 0
Q = deque()

cor = ["x"] * N
ans = "Yes"


for endp in range(N):

    if end[endp]:
        Q.append(endp)


        while len(Q) > 0:

            q = Q.pop()
            end[q] = False

            if cor[q] == "x":
                cor[q] = 0

            for r,d in RD[q]:

                if cor[r] == "x":
                    cor[r] = cor[q] + d
                    Q.append(r)

                elif cor[r] != cor[q] + d:
                    print ("No")
                    exit()


print ("Yes")
### BUGGY CODE ###

n = int(input())
s = input()
ans = 0
for i in range(len(s)):
    one = s[i]
    for j in range(i + 1, len(s)):
        if s[j] == one:
            continue
        dis1 = j - i
        two = s[j]
        for k in range(j + 1, len(s)):
            if s[k] == one or s[k] == two:
                continue
            else:
                dis2 = k - j
                if dis1 != dis2:
                    ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
s = input()

ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        # 三個目が範囲内 かつ 三文字違う かつ 距離が同じはダメ
        if k < n and (s[i] != s[j] and s[j] != s[k]
                      and s[i] != s[k]) and j - i == k - j:
            ans -= 1

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

R, G, B, N = map(int, input().split())
 
cnt = 0
for r in range(N + 1):
    for g in range(N + 1):
        b = N - (r * R + g * G)
        if b >= 0 and b % B == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

R, G, B, N = map(int, input().split())

cnt = 0
for r in range(N + 1):
    for g in range(N + 1):
        b = N - (r * R + g * G)
        if b >= 0 and b % B == 0:
            cnt += 1
print(cnt)
### BUGGY CODE ###

import copy

H, W = map(int, input().split())
A = []
count = 0
for i in range(H):
  x = input()
  A.append(x)
  count += x.count('.')

ans = 0
allblack = False
while not allblack:
  B = copy.deepcopy(A)
  if count > 0:
    ans += 1
  else:
    allblack = True
  for i in range(H):
    for j in range(W):
      if A[i][j] == '#':
        if i - 1 >= 0 and B[i - 1][j] == '.':
          str_list = list(B[i - 1])
          str_list[j] = '#'
          B[i - 1] = ''.join(str_list)
          count -= 1
        if j - 1 >= 0 and B[i][j - 1] == '.':
          str_list = list(B[i])
          str_list[j - 1] = '#'
          B[i] = ''.join(str_list)
          count -= 1
        if i + 1 < H and B[i + 1][j] == '.':
          str_list = list(B[i + 1])
          str_list[j] = '#'
          B[i + 1] = ''.join(str_list)
          count -= 1
        if j + 1 < W and B[i][j + 1] == '.':
          str_list = list(B[i])
          str_list[j + 1] = '#'
          B[i] = ''.join(str_list)
          count -= 1
        str_list = list(B[i])
        str_list[j] = '%'
        B[i] = ''.join(str_list)
  A = copy.deepcopy(B)
print(ans)


### FIXED CODE ###

H,W = map(int,input().split())
A = []
for i in range(H):
  A.append(input())
#print(A)

INF = 10000
S = [[INF for _ in range(W)] for _ in range(H)]
for i in range(H):
  flag = False
  for j in range(W):
    if A[i][j] == '#':
      flag  = True
      d = 0
      S[i][j] = 0
    if flag and A[i][j] == '.':
      d += 1
      S[i][j] = min(d,S[i][j])
  flag = False
  for j in range(W-1,-1,-1):
    if A[i][j] == '#':
      flag  = True
      d = 0
      S[i][j] = 0
    if flag and A[i][j] == '.':
      d += 1
      S[i][j] = min(d,S[i][j])
for j in range(W):
  flag = False
  for i in range(H):
    if S[i][j] < INF:
      flag = True
    if flag and i > 0 and A[i][j] == '.':
      S[i][j] = min(S[i][j],S[i-1][j]+1)
  flag = False
  for i in range(H-1,-1,-1):
    if S[i][j] < INF:
      flag = True
    if flag and i < H-1 and A[i][j] == '.':
      S[i][j] = min(S[i][j],S[i+1][j]+1)
#print(S)

ans = 0
for s in S:
  ans = max(ans,max(s))
print(ans)
### BUGGY CODE ###

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

inputs = []
sorted_inputs = {}

for _ in range(M):
    P, Y = map(int, input().split())
    inputs.append((P, Y))
    if sorted_inputs.get(P) is None:
        sorted_inputs[P] = [Y]
    else:
        sorted_inputs[P].append(Y)

for input in sorted_inputs:
    sorted_inputs[input].sort()

for input in inputs:
    first = str(input[0]).rjust(6, '0')
    latter = str(sorted_inputs[input[0]].index(input[1])+1).rjust(6, '0')
    print(first + latter)


### FIXED CODE ###

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

sorted_inputs = {}
ans = [None]*M

for i in range(M):
    P, Y = map(int, input().split())
    if sorted_inputs.get(P) is None:
        sorted_inputs[P] = [(Y, i)]
    else:
        sorted_inputs[P].append((Y, i))

for pref, l in sorted_inputs.items():
    l.sort() # Yでソートされる
    for j, (Y, i) in enumerate(l):
        first = str(pref).rjust(6, '0')
        latter = str(j+1).rjust(6, '0')
        ans[i] = first + latter

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

import sys

sys.setrecursionlimit(10 ** 5)

n, m, p = map(int, input().split())
abc = []
for _ in range(m):
    a, b, c = map(int, input().split())
    abc.append([a-1, b-1, p-c])

d = [[float('inf') for _ in range(n)] for _ in range(n*2 + 1)]

d[0][0] = 0

for i in range(1, n):
    for a, b, c in abc:
        #print(a,b,c, d[i-1], min(d[i-1][b], d[i-1][a] + c))
        d[i][b] = min(d[i][b], d[i-1][b], d[i-1][a] + c)
    #print(d[i])

for a, b, c in abc:
    if d[n-1][b] > d[n-1][a] + c:
        d[n-1][b] = - float('inf')

for i in range(n, 2*n+1):
    for a, b, c in abc:
        d[i][b] = min(d[i][b], d[i-1][b], d[i-1][a] + c)

if d[n*2][n-1] == - float('inf'):
    print(-1)
else:
    print(max(- d[n*2][n-1], 0))



### FIXED CODE ###

n, m, p = map(int, input().split())
abc = []
for _ in range(m):
    a, b, c = map(int, input().split())
    abc.append([a-1, b-1, p-c])

d = [float('inf')] * n
d[0] = 0

for i in range(n):
    for a, b, c in abc:
        d[b] = min(d[b], d[a] + c)

for a, b, c in abc:
    if d[b] > d[a] + c:
        d[b] = - float('inf')

for i in range(n):
    for a, b, c in abc:
        d[b] = min(d[b], d[a] + c)

if d[n-1] == - float('inf'):
    print(-1)
else:
    print(max(0, - d[n-1]))
### BUGGY CODE ###

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


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


ans = -1
for i in range(N):
    flg = 0
    tmp = A[:i] + A[i+1:]
    Gcd = tmp[0]
    for j in range(N-2):
        g = gcd(tmp[j], tmp[j+1])
        Gcd = gcd(Gcd, g)
        if Gcd < ans:
            flg = 1
            break
    if flg:
        continue
    ans = max(ans, Gcd)

print(ans)


### FIXED CODE ###

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


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


L = [0] * N
R = [0] * N
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i-1])
    R[N-i-1] = gcd(R[N-i], A[N-i])

for i in range(N):
    if i == 0:
        ans = R[i]
    elif i == N-1:
        ans = max(ans, L[i])
    else:
        ans = max(ans, gcd(L[i], R[i]))

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

n = int(input())
A = [int(i) for i in input().split(' ')] 

ls = [x for x in set(A) if A.count(x) > 1]

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

### FIXED CODE ###

n = int(input())
A = input().split(' ')

if len(A) == len(set(A)):
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

input()
list = map(int, input().split())
count = 0
while all(a % 2 == 0 for a in list):
  list = [a/2 for a in list]
  count += 1
print(count)

### FIXED CODE ###

input()
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)
### BUGGY CODE ###

l, r = map(int, input().split())
"""
もしl~rの範囲に2019の倍数を含むならば、2019の倍数をi,jのいずれかに設定して0を得る。
それ以外の場合、l~rの範囲は高々2019程度なので、全探索で間に合う
"""
if l//2019 - r//2019 > 0:
    print(0)
else:
    ans = 2019
    for i in range(l, r):
        for j in range(l+1, r+1):
            ans = min(ans, (i*j)%2019)
            if ans == 0:
                break
    print(ans)

### FIXED CODE ###

l, r = map(int, input().split())
"""
もしl~rの範囲に2019の倍数を含むならば、2019の倍数をi,jのいずれかに設定して0を得る。
それ以外の場合、l~rの範囲は高々2019程度なので、全探索で間に合う
"""
if r//2019 - l//2019 > 0:
    print(0)
else:
    ans = 2019
    for i in range(l, r):
        for j in range(l+1, r+1):
            ans = min(ans, (i*j)%2019)
            if ans == 0:
                break
    print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

n, k = map(int, input().split())
h = list(map(int, input().split()))

# dp = [float('inf') for i in range(len(h))]
dp = [0] * n
dp[0] = 0
# dp[1] = abs(h[0] - h[1])
# print(dp)

for i in range(1, n):
    # for j in range(1, min(k + 1, n - i)):
    #     dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
    dp[i] = min([dp[j] + abs(h[j] - h[i]) for j in range(max(0, i - k), i)])
            
        # print(dp)
        
print(dp[-1])

### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
def findlet(let,ind):
    add = len([x for x in st[ind:] if x == let])
    if add > 0:
        if 2*ind < len(st):
            if st[2*ind] == let:
                add -= 1
        global count
        count += add
for i in range(N-2):
    if i == 0:
        st = S
    else:
        st = st[1:]
    if st[0] == "R":
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("B",j)
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("G",j)
    elif st[0] == "G":
        for j in [x for x, y in enumerate(st) if y == 'B']:
            findlet("R",j)
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("B",j)
    else:
        for j in [x for x, y in enumerate(st) if y == 'R']:
            findlet("G",j)
        for j in [x for x, y in enumerate(st) if y == 'G']:
            findlet("R",j)
print(count)

### FIXED CODE ###

N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
count = r * g * b
for i in range(N):
    for j in range(i+1,N-1):
        if 2*j - i <= N-1:
            l = set([S[i],S[j],S[2*j-i]])
            if len(l) == 3:
                count -= 1
print(count)
### BUGGY CODE ###

#4
n,k=map(int,input().split())
s=str(input())

import numpy as np
line = np.zeros([2*n,],dtype=np.int)
counter1 = 0
counter0 = 0
ind = 0
for i in range(n):
    c = int(s[i])
    if ind%2 ==0:
        if c == 1:
            counter1 += 1
        else:
            counter0 += 1
            line[ind] = counter1
            counter1 = 0
            ind+=1
    elif ind%2 ==1:
        if c == 0:
            counter0 += 1
        else:
            counter1 += 1
            line[ind] = counter0
            counter0 = 0
            ind+=1

if ind%2 ==0:
        line[ind] = counter1
        ind+=1
elif ind%2 ==1:
        line[ind] = counter0
        ind+=1
        
if ind%2 ==0:
        line[ind] = 0
        ind+=1
line = line[:ind]    
#print(line)

if (len(line)//2)<=k:
    print(n)
else:
    maxchain = 0
    for i in range(0,ind-(2*k+1)+1,2):
        chain = sum(line[i:i+2*k+1])
        if chain>maxchain:
            maxchain=chain
    print(maxchain)

### FIXED CODE ###

#4
n,k=map(int,input().split())
s=str(input())

import numpy as np
line = np.zeros([2*n,],dtype=np.int)
counter1 = 0
counter0 = 0
ind = 0
for i in range(n):
    c = int(s[i])
    if ind%2 ==0:
        if c == 1:
            counter1 += 1
        else:
            counter0 += 1
            if ind == 0:
                line[ind] = counter1
            else:
                line[ind] = line[ind-1]+counter1
            counter1 = 0
            ind+=1
    elif ind%2 ==1:
        if c == 0:
            counter0 += 1
        else:
            counter1 += 1
            line[ind] = line[ind-1] + counter0
            counter0 = 0
            ind+=1

if ind%2 ==0:
        if ind == 0:
                line[ind] = counter1
        else:
                line[ind] = line[ind-1]+counter1
        ind+=1
elif ind%2 ==1:
        line[ind] = line[ind-1] + counter0
        ind+=1
        
if ind%2 ==0:
        line[ind] = line[ind-1]
        ind+=1
        
line[1:ind+1]  = line[:ind]   
line[0] = 0 
line = line[:ind+1]
#print(line)

if (len(line)//2)<=k:
    print(n)
else:
    maxchain = 0
    for i in range(0,len(line)-2*k,2):
        chain = line[i+2*k+1]-line[i]
        #print(chain)
        if chain>maxchain:
            maxchain=chain
    print(maxchain)
### BUGGY CODE ###

n, s = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
mod = 998244353
dp = [0] * (s + 1)
dp[0] = 1
for i in a:
    dp2 = [0] * (s + 1)
    for j in range(s + 1):
        dp2[j] = dp[j] * 2
        if j >= i:
            dp2[j] += dp[j - i]
        dp2[j] %= mod
    dp = dp2
print(dp[-1])


### FIXED CODE ###

n, s = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
mod = 998244353
dp = [0] * (s + 1)
dp[0] = 1
for i in a:
    dp2 = [0] * (s + 1)
    for j in range(s + 1):
        dp2[j] = dp[j] * 2
        if j >= i:
            dp2[j] += dp[j - i]
        dp2[j] %= mod
    dp = dp2
print(dp[-1])
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
m = ["#" * (W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W+2)]
q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

step = [[float("inf") for _ in range(W+2)] for _ in range(H+2)]

for h in range(1, H+1):
	for w in range(1, W+1):
		if m[h][w] == "#":
			q.appendleft([h, w])
			step[h][w] = 0

while q:
	label = q.pop()

	for i in range(4):
		h, w = label[0] + dx[i], label[1] + dy[i]
		if m[h][w] != "#" and step[h][w] > step[label[0]][label[1]] + 1:
			q.appendleft([h, w])
			step[h][w] = step[label[0]][label[1]] + 1

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		ans = max(ans, step[h][w])
print(ans)

### FIXED CODE ###

from collections import deque
import sys
def input():
	return sys.stdin.readline()[:-1]

H, W = map(int, input().split())
m = [["#"] * (W+2)] + [["#"] + list(input()) + ["#"] for _ in range(H)] + [["#"] * (W+2)]
q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

step = [[float("inf") for _ in range(W+2)] for _ in range(H+2)]

for h in range(1, H+1):
	for w in range(1, W+1):
		if m[h][w] == "#":
			q.appendleft([h, w])
			step[h][w] = 0

while q:
	label = q.pop()

	for i in range(4):
		h, w = label[0] + dx[i], label[1] + dy[i]
		if m[h][w] != "#" and step[h][w] > step[label[0]][label[1]] + 1:
			q.appendleft([h, w])
			step[h][w] = step[label[0]][label[1]] + 1

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		ans = max(ans, step[h][w])
print(ans)
### BUGGY CODE ###

import copy
x,y = list(map(int, input().split()))
Z = [list(map(int, input().split())) for _ in range(x)]

def gonext(a,b):
    if a < x-1:
        a += 1
    else:
        b += 1
        a = 0
    return(a,b)

a, b = 0, 0
ans = []
visited = [[-1, -1], [-1, -1]]
stac = 0

while a < x and b < y:
    now = Z[a][b]
    if now % 2 == 0:
        a,b = gonext(a,b)
    else:
        stac += 1
        if stac < 2:
            visited[0] = [a,b]
            a,b = gonext(a,b)
        else:
            visited[1] = [a,b]
            stac = 0
            a, b = gonext(a, b)
            ans.append(visited)
            visited = [[-1, -1], [-1, -1]]

count = 0
final = []
for lis in ans:
    l0, l1 = lis
    while not l0 == l1:
        for i in range(2):
            if l1[i] - l0[i] > 0:
                l0_copy = copy.deepcopy(l0)
                l0[i] += 1
                for j in range(2):
                    l0_copy.append(l0[j])
                count += 1
                final.append(l0_copy)

print(count)
for i in final:
    k = [j+1 for j in i]
    print(" ".join(list(map(str, k))))

### FIXED CODE ###


import copy
y,x = list(map(int, input().split()))
Z = [list(map(int, input().split())) for _ in range(y)]

way = 1
a, b = 0, 0
ans = []
count = 0
while a < y and b < x:
    now = Z[a][b]
    a_copy= copy.deepcopy(a)
    b_copy = copy.deepcopy(b)

    if (way == 1 and a < y-1) or (way == -1 and a > 0):
        a += way
    else:
        b += 1
        way = way*(-1)
    if not (a < y and b < x):
        break
    if now % 2 == 1:
        Z[a][b] += 1
        ans.append([a_copy, b_copy, a, b])
        count += 1

print(count)
for i in ans:
    k = [j+1 for j in i]
    print(" ".join(list(map(str, k))))
### BUGGY CODE ###


#####

import numpy as np
# from numpy import int32, int8
from collections import deque

#####

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def travel(colors, h, w, row0, col0, targetColor, flipSize, nextParams: deque):
# 	print()
# 	print("row0",row0,"col0",col0,"flipSize",flipSize)
	
	visited=np.zeros((h-row0, w-col0), np.bool)
	visited[0,0]=True
	next=set()
	for hi in range(row0, h):
		for wi in range(col0, w):
			c=colors[hi,wi]==targetColor
			if hi>0 and visited[hi-1-row0,wi-col0]:
				if c:
					visited[hi-row0,wi-col0]=True
				else:
					next.add((hi,wi))
			if wi>0 and visited[hi-row0,wi-1-col0]:
				if c:
					visited[hi-row0,wi-col0]=True
				else:
					next.add((hi,wi))
	
	if visited[h-1-row0,w-1-col0]:
# 		print("found")
# 		return flipSize
		print(flipSize)
		sys.exit(0)
					
# 	print(next)
	if len(next)==0: return None
	minFlipSize=None
	if targetColor: nextFlipSize=flipSize+1
	else: nextFlipSize=flipSize
	for nr,nc in next:
		p=(colors, h, w, nr, nc, not targetColor, nextFlipSize)
		nextParams.append(p)


def main(inputs):
	h,w=getIntList(inputs[0])
	colors=np.empty((h,w),np.bool)
	for hi in range(h):
		for wi in range(w):
			colors[hi,wi]=inputs[1+hi][0][wi]=="."
# 	print(colors)
	
	if colors[0,0]: nextFlipSize=0
	else: nextFlipSize=1
	
	nextParams=deque()
	p=(colors, h, w, 0, 0, colors[0,0], nextFlipSize)
	nextParams.append(p)
	
	while len(nextParams)>0:
		param=nextParams.popleft()
		travel(*param, nextParams=nextParams)
# 	print("flipSize",flipSize)
# 	print(flipSize)
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)


### FIXED CODE ###


#####

import numpy as np
# from numpy import int32, int8
# from collections import deque

#####

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs



def main(inputs):
	h,w=getIntList(inputs[0])
	colors=np.empty((h,w),np.bool)
	for hi in range(h):
		for wi in range(w):
			colors[hi,wi]=inputs[1+hi][0][wi]=="."

# 	h=20
# 	w=20
# 	np.random.seed(0)
# 	colors=np.random.randint(0,2,(h,w))

# 	from matplotlib import pyplot as plt
# 	for hi in range(h):
# 		for wi in range(w):
# 			plt.annotate(str((hi,wi)), (wi-0.5,hi), color="g")
# 	plt.imshow(colors)
# 	plt.show()
			
# 	print(colors.astype(np.int32))
	
	flipSize=np.empty((h,w), np.int32)
	
	if colors[0,0]: flipSize[0,0]=0
	else: flipSize[0,0]=1
	
	for hi in range(h):
		for wi in range(w):
			if hi==0 and wi==0: continue
			c=colors[hi,wi]
			fs=[]
			if hi>0:
				d=int(colors[hi-1,wi] and (not c))
				s=flipSize[hi-1, wi]+d
				fs.append(s)
				
			if wi>0:
				d=int(colors[hi,wi-1] and (not c))
				s=flipSize[hi, wi-1]+d
				fs.append(s)
			
			fs=min(fs)
			flipSize[hi,wi]=fs
	
	print(flipSize[h-1,w-1])
	

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

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

count = 0
for i in range(N):
    lists_slice = lists[:i+1]
    lists_min = min(lists_slice)
    if lists_min >= lists[i]:
        count+=1

    # cnt = 0
    # for j in lists_slice:
    #     if lists_slice[i] <= j:
    #         cnt += 1
    # if cnt == i+1:
    #     count+= 1
print(count)

### FIXED CODE ###

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

count = 0
ans = 0
for i in range(N):
    if i == 0:
        ans = lists[i]
        count += 1
    else:
        if ans >= lists[i]:
            count += 1
            ans = min(ans, lists[i])
        else:
            ans = min(ans, lists[i])


    # lists_slice = lists[:i+1]
    # lists_min = min(lists_slice)
    # if lists_min >= lists[i]:
    #     count += 1
print(count)