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

#!/usr/bin/env python3
import numpy as np
import itertools

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    H, W, K = list(map(int, input().split()))
    S = np.ndarray([H, W])
    answer = np.inf

    for h in range(H):
        row = list(map(int, list(input())))
        S[h, :] = row

    for n in range(H):
        for comb in itertools.combinations([h for h in range(1, H)], n):
            num_horizontal_cut = len(comb)
            if num_horizontal_cut == 0:
                sub_S = S.sum(axis=0)
            else:
                sub_S = np.zeros([num_horizontal_cut+1, W])
                head = 0

                c_prev = 0
                for i, c in enumerate(comb):
                    sub_S[i] = S[c_prev: c].sum(axis=0)
                    c_prev = c
                sub_S[num_horizontal_cut] = S[c_prev:].sum(axis=0)

            current_sum = np.zeros(num_horizontal_cut+1)
            num_cut = 0
            if np.any(sub_S > K):
                num_cut = np.inf
                continue
            for line in sub_S.T:
                if np.any(current_sum + line > K):
                    current_sum[:] = 0#np.zeros(num_horizontal_cut+1)
                    num_cut += 1
                current_sum += line

            if num_cut + num_horizontal_cut < answer:
                answer = num_cut + num_horizontal_cut
    print(answer)
    pass

if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np
from itertools import product
H, W, K = map(int, input().split())
G = np.array([list(map(int, list(input()))) for _ in range(H)])
 
ans = float('inf')
for pattern in product([0, 1], repeat=H - 1):
    # スライスで横方向への割り方を表現する
    div = [0] + [i for i, p in enumerate(pattern, start=1) if p == 1] + [10]
 
    # 横方向へ割った後、各ブロックについて縦方向にホワイトチョコの数を修正
    rows = []
    for i in range(len(div) - 1):
        rows.append(np.sum(G[div[i]: div[i + 1]], axis=0))
 
    # 縦方向にすでにK個より多いホワイトチョコが含まれている場合はどうにもならない
    if [r for r in rows if np.any(r > K)]:
        continue
 
    # 縦方向に貪欲に割っていく
    rows = [r.tolist() for r in rows]
    tmp_ans = 0
    counts = [0] * len(rows)
    w = 0
    while w < W:
        for r in range(len(rows)):
            counts[r] += rows[r][w]
        if any([c > K for c in counts]):
            counts = [0] * len(rows)
            w -= 1
            tmp_ans += 1
        w += 1
 
    # 横に割った分を加算
    tmp_ans += len(div) - 2
    ans = min(ans, tmp_ans)
 
print(ans)
### BUGGY CODE ###

#import math
#from functools import reduce
from fractions import gcd

#def lcm_base(x, y):
#    return (x * y) // gcd(x, y)

#def lcm(numbers):
#    return reduce(lcm_base, numbers, 1)

def lcm(a):
    #from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


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

t_lcm = lcm(A)
count = 0
for i in A:
    count += t_lcm//i
    
print(count%(10**9+7))


### FIXED CODE ###

#import math
#from functools import reduce
from fractions import gcd
#from functools import lru_cache


#def lcm_base(x, y):
#    return (x * y) // gcd(x, y)

#def lcm(numbers):
#    return reduce(lcm_base, numbers, 1)


def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


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

t_lcm = lcm(A)
count = 0
for i in A:
    count += t_lcm//i
    
print(count%(10**9+7))
### BUGGY CODE ###

H, N = map(int, input().split())
magic = [list(map(int, input().split())) for i in range(N)]

# dp[damage] := モンスターに damage を与えるために必要な最小コスト

# damage = 0,1,2,...,H
dp = [10**9] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)

# print(dp)
print(dp[-1])


### FIXED CODE ###

H, N = map(int, input().split())
magic = [list(map(int, input().split())) for i in range(N)]

# dp[damage] := モンスターに damage を与えるために必要な最小コスト

# damage = 0,1,2,...,H
dp = [10**9] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)

# print(dp)
print(dp[-1])
### BUGGY CODE ###

def solve():
    s = input()

    ans = 0
    for i in range(len(s)):
        for j in range(i+3,len(s)):
            #print(s)
            #print(i, j)
            #print(s[i:j])
            if int(s[i:j+1]) % 2019 == 0:
                ans += 1
                #print(i, j)

    print(ans)

solve()

### FIXED CODE ###

S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)
### BUGGY CODE ###

import numpy as np
n,k=list(map(int,input().split()))
a=(np.array(list(map(int,input().split())))+1)/2
  
ans=0
for i in range(n-k+1):
  tmp=np.sum(a[i:i+k])
  if ans<tmp:
    ans=tmp
    
print(ans)

### FIXED CODE ###

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
  
ans=0
for i in range(k):
  ans += (a[i]+1)/2
past=ans
for i in range(1,n-k+1):
  tmp = past - (a[i-1]+1)/2 +  (a[i+k-1]+1)/2
  if ans<tmp:
    ans=tmp
  past = tmp
    
print(ans)
### BUGGY CODE ###

# 初期入力
N = int(input())
import numpy as np
koufuku = np.array( [list(map(int, input().split())) for i in range(N)] ,dtype=int)
dp_ko = [0]*(N+1) 

dp_ko[0] = max( koufuku[0,:] ) , np.argmax(koufuku[0,:]) 

#
for i in range(N-1):
    
    tomorr_i = np.argmax(koufuku[i+1,:]) # 翌日の最大値のindex
    tomorr_ko = np.max(koufuku[i+1,:] ) # 翌日の最大値
    if tomorr_i != dp_ko[i][1]: # 翌日最大値のindex not 当日の保存していたindex(当日の最大値とは限らない)
        dp_ko[i+1] = dp_ko[i][0] + tomorr_ko , tomorr_i # 累積＋翌日の最大値 , 翌日のindex
    else:
        tomorr_no2 = np.sort( koufuku[i+1,:] )[-2] # 翌日2番目に大きい値
        tomorr_no2_i = koufuku[i+1,:].argsort()[-2] # 翌日2番目に大きい値のindex
        dp_ko[i+1] = dp_ko[i][0] + tomorr_no2 , tomorr_no2_i 

print(dp_ko[N-1][0])

### FIXED CODE ###

"""
参考 Xenous
if sortを少なくし、maxで処理
""" 
# 初期入力
N = int(input())
a=[]
b=[]
c=[]
for i in range(N):
    a1,b1,c1 = (int(x) for x in input().split())
    
    a.append(a1)
    b.append(b1)
    c.append(c1)

dp_A = [0]*(N) ;dp_A[0] =a[0] 
dp_B = [0]*(N) ;dp_B[0] =b[0] 
dp_C = [0]*(N) ;dp_C[0] =c[0] 


#
for i in range(0,N-1):
    dp_A[i+1] = max(dp_B[i] + a[i+1] , dp_C[i] + a[i+1])
    dp_B[i+1] = max(dp_A[i] + b[i+1] , dp_C[i] + b[i+1])
    dp_C[i+1] = max(dp_A[i] + c[i+1] , dp_B[i] + c[i+1])
print(max (dp_A[N-1],dp_B[N-1],dp_C[N-1]) )
### BUGGY CODE ###

import re
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for i in range(1000):
        a,b,c = str(i).zfill(3)
        pattern = r'.*?{}.*?{}.*?{}.*?'.format(a, b, c)
        match = re.search(pattern, S)

        if match:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for p in range(1000):
        pattern = str(p).zfill(3)
        key = 0
        cnt = 0
        for n in pattern:
            for i in range(key,N):
                if S[i] == n:
                    key = i+1
                    cnt += 1
                    break
        if cnt == 3:
            ans += 1
    
    print(ans)


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

n = int(input())
a = list(map(int, input().split()))
b = 1
for i in range(n):
  b *= a[i]
  if b > 10**18 and 0 not in a:
    b = -1
    break
print(b)

### FIXED CODE ###

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

import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
S = input().strip()
Q = int(input())
K = list(map(int,input().split()))

m = [0] * 3
for k in K:
    ans = 0
    m = defaultdict(int)
    for i,s in enumerate(S):
        if i >= k:
            pre = S[i-k]
            if pre == 'D':
                m[0] -= 1 # m['D'] -= 1
                m[2] -= m[1] # m['DM'] -= m['M']
            elif pre == 'M':
                m[1] -= 1 # m['M'] -= 1
        if s == 'D':
            m[0] += 1 # m['D'] += 1
        if s == 'M': 
            m[2] += m[0] # m['DM'] += m['D']
            m[1] += 1# m['M'] += 1
        if s == 'C':
            ans += m[2] # ans += m['DM']
        #print(s,m)
    print(ans)



### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
S = input().strip()
Q = int(input())
K = list(map(int,input().split()))

'''
import random
import string
S = "".join(random.choices(string.ascii_uppercase, k=10**6))
Q =75 
K = [random.randint(1,10**6) for i in range(Q)]
'''

for k in K:
    ans = 0
    m = [0] * 3
    for i,s in enumerate(S):
        if i >= k:
            pre = S[i-k]
            if pre == 'D':
                m[0] -= 1 # m['D'] -= 1
                m[2] -= m[1] # m['DM'] -= m['M']
            elif pre == 'M':
                m[1] -= 1 # m['M'] -= 1
        if s == 'D':
            m[0] += 1 # m['D'] += 1
        if s == 'M': 
            m[2] += m[0] # m['DM'] += m['D']
            m[1] += 1# m['M'] += 1
        if s == 'C':
            ans += m[2] # ans += m['DM']
        #print(s,m)
    print(ans)
### BUGGY CODE ###

from itertools import permutations

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conf = [[int(x) for x in input().split()] for _ in range(n)]
# conf = sorted([[int(x) for x in input().split()] for _ in range(n)], reverse=True)

maxres = 0
for cc in permutations(conf, min(m, len(conf))):
  res = 0
  for i, c in enumerate(cc):
    if i + c[0] <= m:
      res = res + c[1]
  if res > maxres:
    maxres = res
print(maxres)


### FIXED CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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

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

cnt = 0
while True:
    for i in range(N):
        if a[i] % 2 == 1:
            break
        else:
            a[i] = a[i]/2
    cnt += 1

print(cnt)

### FIXED CODE ###

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

cnt = 0
t_f = True

while t_f == True:
    for i in range(N):
        if a[i] % 2 == 1:
            t_f = False
            break
        else:
            a[i] = a[i]//2
    cnt += 1
    
print(cnt - 1)
### BUGGY CODE ###

N, K = [int(v) for v in input().split()]

link = []
for k in range(K):
    L, R = [int(v) for v in input().split()]

    for i in range(L, R+1):
        link.append(i)

link.sort()
count = [1]

for i in range(1, N):
    v = 0
    for l in link:
        if i < l:
            break
        v = (v + count[i - l]) % 998244353
    count.append(v)

print(count[-1])


### FIXED CODE ###

N, K = [int(v) for v in input().split()]

links = []
for k in range(K):
    L, R = [int(v) for v in input().split()]
    links.append((L, R))

links = sorted(links, key=lambda x: x[1])

count = [1]
sub = [0, 1]
subtotal = 1

for i in range(1, N):
    v = 0
    for l, r in links:
        r2 = i - l + 1
        l2 = i - r
        if l2 < 0:
            l2 = 0
        if r2 >= 0:
            v += sub[r2] - sub[l2]

    count.append(v % 998244353)
    subtotal = (subtotal + v) % 998244353
    sub.append(subtotal )

print(count[-1])
### BUGGY CODE ###

nn = int(input())
ss = input()

ans = 0

for i in range(nn-1):
  n = nn-i
  s = ss[i:]
  a = [0]*n
  a[0] = n
  i, j = 1, 0
  while i < n:
    while i+j < n and s[j] == s[i+j]:
      j += 1
    a[i] = j
    if j == 0:
      i += 1
      continue
    k = 1
    while i+k < n and k+a[k] < j:
      a[i+k] = a[k]
      k += 1
    i += k
    j -= k
  for p in range(1, n-1):
    a[p] = min([p, a[p]])
  sub = max(a[1:])
  if ans < sub:
    ans = sub
print(ans)

### FIXED CODE ###

nn = int(input())
ss = input()

ans = 0

for i in range(nn-1):
  n = nn-i
  s = ss[i:]
  a = [0]*n
  a[0] = n
  i, j = 1, 0
  while i < n:
    while i+j < n and s[j] == s[i+j]:
      j += 1
    a[i] = j
    if j == 0:
      i += 1
      continue
    k = 1
    while i+k < n and k+a[k] < j:
      a[i+k] = a[k]
      k += 1
    i += k
    j -= k
  for p in range(1, n-1):
    a[p] = min([p, a[p]])
  sub = max(a[1:])
  if ans < sub:
    ans = sub
print(ans)
### BUGGY CODE ###

n = int(input())

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

i = 0
sum = 1

while i < n:
    sum *= n1[i]
    i += 1

if sum > 10 ** 18:
    print('-1')
else:
    print(sum)

### FIXED CODE ###

def main():
    n = int(input())

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

    if 0 in n1:
        print(0)
        return

    sum = 1
    for i in n1:
        sum *= i
        if sum > 1000000000000000000:
            print(-1) 
            return 
    print(sum)

main()
### BUGGY CODE ###

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

for i in range(N):
    print(A.count(i+1))


### FIXED CODE ###

n = int(input())

l = [0] * n
nums = input().split()
for i in range(n - 1):
    l[int(nums[i]) - 1] += 1
    
for i in range(n):
    print(l[i])
### BUGGY CODE ###

from fractions import gcd
import itertools

def answer():
    def make_divisors(n):
        divisors = set()
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.add(i)
                if i != n // i:
                    divisors.add(n // i)

        # divisors.sort()
        return divisors

    a, b = map(int, input().split())
    g = gcd(a, b)
    set_divisors = make_divisors(g)
    set_divisors.remove(1)
    removed = set()

    for div1, div2 in itertools.combinations(set_divisors, 2):
        if div1 in removed or div2 in removed:
            continue
        item = div1 * div2 / gcd(div1, div2)
        if item in set_divisors:
            removed.add(item)
            set_divisors.remove(item)

    print(len(set_divisors)+1)


if __name__ == '__main__':
    answer()


### FIXED CODE ###

from fractions import gcd

def answer():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        divisors.sort()
        return divisors

    a, b = map(int, input().split())
    g = gcd(a, b)
    divisors = make_divisors(g)

    length = len(divisors)
    removed = 1

    for i in range(1, length):
        d1 = divisors[i]
        for d2 in divisors[i:-1]:
            if d1 * d2 in divisors:
                divisors.remove(d1*d2)
                removed += 1
        if i + removed >= length:
            break

    print(length - removed + 1)


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

N = int(input())
print(0, flush=True)
t = input()
if t == 'Vacant':
    exit()
print(N - 1, flush=True)
l = input()
if l == 'Vacant':
    exit()

top = N - 1
lo = 0
while top - lo > 1:
    mid = (top + lo) // 2
    print(mid, flush=True)
    tmp = input()
    if tmp == 'Vacant':
        exit()
    elif (mid % 2 == 0 and l == tmp) or (mid % 2 != 0 and l != tmp):
        top = mid
        t = tmp
    else:
        lo = mid
        l = tmp


### FIXED CODE ###

N = int(input())
print(0, flush=True)
l = input()
if l == 'Vacant':
    exit()
print(N - 1, flush=True)
t = input()
if t == 'Vacant':
    exit()

top = N - 1
lo = 0
while True:
    mid = (top + lo) // 2
    print(mid, flush=True)
    tmp = input()
    if tmp == 'Vacant':
        exit()
    elif ((mid - lo) % 2 != 0 and l == tmp) or ((mid - lo) % 2 == 0 and l != tmp):
        top = mid
    else:
        lo = mid
        l = tmp
### BUGGY CODE ###

import math


def pattern(x, y, z):
    if x == y == z:
        return 1
    elif x != y and y != z and x != z:
        return 6
    else:
        return 3


def check(ans):
    cnt = 0
    upper = int(math.sqrt(ans))
    for x in range(1, upper):
        if pow(x, 2) > ans:
            break
        for y in range(x, upper):
            if pow(x+y, 2) > ans:
                break
            for z in range(y, upper):
                tmp = x*(x+y+z) + y*(y+z) + z*z
                #tmp = pow(x+y+z, 2) - x*(y+z) - y*z
                if tmp == ans:
                    cnt += pattern(x, y, z)
                elif tmp > ans:
                    break
    print(cnt)


N = int(input())
# x^2 + y^2 + z^2 + x*y + y*z + z*x = n

for i in range(1, N+1):
    #upper_value = int(math.sqrt(i))
    check(i)


### FIXED CODE ###

import math


def pattern(x, y, z):
    if x == y == z:
        return 1
    elif x != y and y != z and x != z:
        return 6
    else:
        return 3


def check(ans):
    cnt = 0
    upper = int(math.sqrt(ans))
    for x in range(1, upper):
        if pow(x, 2) > ans:
            break
        for y in range(x, upper):
            if pow(x+y, 2) > ans:
                break
            for z in range(y, upper):
                tmp = x*(x+y+z) + y*(y+z) + z*z
                # tmp = pow(x+y+z, 2) - x*(y+z) - y*z
                if tmp == ans:
                    cnt += pattern(x, y, z)
                    if x == y and y == z and z == x:
                        print(cnt)
                        return
                elif tmp > ans:
                    break
    print(cnt)


N = int(input())
# x^2 + y^2 + z^2 + x*y + y*z + z*x = n

for i in range(1, N+1):
    # upper_value = int(math.sqrt(i))
    check(i)
### BUGGY CODE ###

N = int(input())
lst = []
for i in range(1,N//2+1,1):
    if N % i == 0:
        ok_lst = [i,int(N/i)]
        lst.append(ok_lst)

min = 10 **12
for j in lst:
    if min >= (j[0] + j[1] - 2):
        min = j[0] + j[1] - 2
print(min)

### FIXED CODE ###

N = int(input())
lst = []

for i in range(1,int(N**0.5)+1,1):
  if N % i == 0:
    lst.append(int(i + N/i - 2))
print(min(lst))
### BUGGY CODE ###

n=int(input())
s=input()
sum=0
for k in range(n):
    for j in range(k):
        for i in range(j):
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i] and j-i!=k-j:
                sum=sum+1
print(sum)

### FIXED CODE ###

n=int(input())
s=input()
sum=0
r=int(s.count('R'))
g=int(s.count('G'))
b=int(s.count('B'))
for k in range(n):
    for j in range(k):
        i=2*j-k
        if i+1>0:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                sum=sum+1
print(r*g*b-sum)
### BUGGY CODE ###

#ABC179-d
import sys,math,collections,itertools
input = sys.stdin.readline
m=998244353

N,K=list(map(int,input().split()))
DP = [0]*(2*10**5+1)
move = []
for _ in range(K):
    l,r=list(map(int,input().split()))
    move += list(range(l,r+1))
move.sort()
ans = 0
for i in range(2,N+1):
    for mo in move:
        if i-mo<=0:
            break
        elif i-mo==1:
            DP[i]+=1
        else:
            DP[i]=(DP[i]+ DP[i-mo])%m
print(DP[N]%m)
        


### FIXED CODE ###

N,K = map(int,input().split())
DP = [0]*(N+1)
DPsum=[0]*(N+1)
DP[1]=1
DPsum[1]=1
lr = []
m=998244353
for _ in range(K):
    l,r = map(int,input().split())
    lr.append([l,r])

for i in range(2,N+1):
    for l,r in lr:
        lx = i - r - 1
        rx = i - l
        lx = max(0,lx)
        rx = max(0,rx)
        DP[i]+= DPsum[rx]-DPsum[lx]
    DPsum[i]=(DPsum[i-1]+DP[i])%m
print(DP[N]%m)
### BUGGY CODE ###

from collections import deque

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

dist_to_black = [[0]*w for _ in range(h)]

# # debug
# for a in A:
#     print(a)
# for a in dist_to_black:
#     print(a)

def bfs(sy,sx):
    dq = deque([(sy,sx,0)])
    while dq:
        y,x,n = dq.popleft()
        if A[y][x]=='#':
            return n
        elif A[y][x]=='.':
            dq.append([y+1,x,n+1])
            dq.append([y-1,x,n+1])
            dq.append([y,x+1,n+1])
            dq.append([y,x-1,n+1])

ans = -1
for i in range(h):
    for j in range(w):
        # dist_to_black[i][j] = bfs(i+1,j+1)
        ans = max(ans, bfs(i+1, j+1))

print(ans)

### FIXED CODE ###

from collections import deque

h,w = map(int, input().split())
A = [[s for s in input()] for _ in range(h)]

visited = [[-1]*(w) for _ in range(h)]
dq = deque()
directions = [[0,1],[1,0],[0,-1],[-1,0]]

# 初期配置の黒をキューに追加
for hi in range(h):
    for wi in range(w):
        if A[hi][wi] == '#':
            dq.append([hi,wi])
            visited[hi][wi] = 0

# キューが空になるまで
while dq:
    hi,wi = dq.popleft()
    for d in directions:
        nhi, nwi = hi+d[0],wi + d[1]
        # 場外ならスキップ
        if nhi<0 or nhi>=h or nwi<0 or nwi>=w: continue 
        # 「黒くしてない白マス」をキューに追加
        if visited[nhi][nwi] == -1 and A[nhi][nwi] == '.':
            dq.append([nhi,nwi])
            visited[nhi][nwi] = visited[hi][wi] + 1

ans = -1
for x in visited:
    ans = max(ans,max(x))
print(ans)
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    list2=[]
    count = 0
    now =1
    for i in range(n):
        if now in list2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = dict[now-1]

### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]
### BUGGY CODE ###

S = input()
ans = 0

while 'BW' in S:
    ans += S.count('BW')
    S = S.replace('BW','WB')

print(ans)

### FIXED CODE ###

S = list(input())
B = 0
ans = 0

for i in range(len(S)):
    if S[i] == 'B':
        B += 1
    else:
        ans += B

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

n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    i = 1
    a_l = a_l[a_l.index(i)+1:]
    i += 1
    while True:
        if a_l.count(i) > 0:
            a_l = a_l[a_l.index(i)+1:]
            i += 1
        else:
            break
    print(n - (i-1))

### FIXED CODE ###

n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
    exit()
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)