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

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def sosuserch(n):
        sosu = [2]
        for i in range(3, int(n ** (1 / 2)) + 1):
            flg = True
            for s in sosu:
                if i % s == 0:
                    flg = False
                    break
            if flg:
                sosu.append(i)

        return sosu

    a, b = ns()

    sosu_set = set(sosuserch(max(a//2+1, b//2+1)))


    def make_divisors(a, b):
        divisors = []
        for i in range(1, min(a, b) + 1):
            if a % i == 0 and b % i == 0:
                if i in sosu_set:
                    divisors.append(i)

        # divisors.sort()
        return divisors

    gcd = make_divisors(a, b)

    print(len(gcd)+1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a, b = ns()

    g = fractions.gcd(a, b)

    def search(n):
        i = 2
        so = []
        while not(n == 1 or i * i > n):
            while n % i == 0:
                n //= i
                so.append(i)
            i += 1
        if n != 1:
            so.append(n)

        return so

    ans = set(search(g))
    print(len(ans) + 1)


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

n, k, q = map(int, input().split())
score = [k for i in range(n)]
for i in range(q):
  a = int(input())
  score[a - 1] += 1
  score = list(map(lambda x: x- 1, score))
for i in range(n):
  if score[i] > 0:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

n, k, q = map(int, input().split())
score = [0 for i in range(n)]
for i in range(q):
  a = int(input())
  score[a - 1] += 1
for i in range(n):
  if q - score[i] >= k:
    print('No')
  else:
    print('Yes')
### BUGGY CODE ###

import sys
import os
import math
import bisect
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, N = il()
    ret = 0
    mi = math.floor(A / N)
    for n in range(mi, N + 1):
        ret = max(ret, f(A, B, n))
    print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, N = il()
    print(f(A, B, min(B - 1, N)))


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

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

ans = 0
for i in range(1,n+1):
    list = listn[:i]
    if listn[i-1]==min(list):
        ans+=1

print(ans)
    



### FIXED CODE ###

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

a = 10**6
ans = 0
for i in range(n):
    if listn[i] <= a:
        a = listn[i]
        ans += 1

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

semester, K = map(int, input().split())

score = input().split()

result1 = 1
result2 = 1

for i in range(semester - K + 1) :
    if i == 0 :
        for j in range(K) :
            result1 = result1 * int(score[K - 1 - j])
        continue
    
    for l in range(K) :
        result2 = result2 * int(score[K - l - 1 + i])
    
    if result1 < result2 :
        print("Yes")
    else :
        print("No")
 
    result1 = result2
    result2 = 1


### FIXED CODE ###

semester, K = map(int, input().split())

score = input().split()

for i in range(semester - K + 1) :
    if i == 0 :
        continue    

    if int(score[K - K + i - 1]) < int(score[K - 1 + i]) :
        print("Yes")
    else :
        print("No")
### BUGGY CODE ###

"""
A - Limited Insertion
"""


def solve():
    N = int(input())
    b = list(map(int, input().split()))
    ans = make_list(b, 0, [])

    if ans == -1:
        print(ans)
    else:
        for a in list(reversed(ans)):
            print(a)
        # ans = list(reversed(ans))
        # ans = [str(i) for i in ans]
        # print(' '.join(ans))


def make_list(b: list, x: int, ans: list) -> list:
    re = -1
    # print('try {}'.format(x))
    # print(b)

    if len(b) == 0:
        return ans

    for i, element in enumerate(b, 1):
        if i == element:
            b_c = b.copy()
            ans_c = ans.copy()
            ans_c.append(b_c[i - 1])
            b_c.remove(element)  # 除去対象は自分より前に同じ要素が存在しない
            # print('match element {}'.format(element))
            # print(ans)
            tmp = make_list(b_c, x + 1, ans_c)
            if tmp != -1:
                re = tmp
                break
    # print('return {} is '.format(x), re)
    return re


if __name__ == '__main__':
    solve()


### FIXED CODE ###

"""
A - Limited Insertion
"""


def solve():
    N = int(input())
    b = list(map(int, input().split()))
    ans = make_list(b, 0, [])

    if ans == -1:
        print(ans)
    else:
        for a in list(reversed(ans)):
            print(a)
        # ans = list(reversed(ans))
        # ans = [str(i) for i in ans]
        # print(' '.join(ans))


def make_list(b: list, x: int, ans: list):
    re = -1
    # print('try {}'.format(x))
    # print(b)

    if len(b) == 0:
        return ans

    if check_list(b) is False:
        return re

    for i, element in enumerate(b, 1):
        if i == element:
            b_c = b.copy()
            ans_c = ans.copy()
            ans_c.append(b_c[i - 1])
            b_c.remove(element)  # 除去対象は自分より前に同じ要素が存在しない
            # print('match element {}'.format(element))
            # print(ans)
            tmp = make_list(b_c, x + 1, ans_c)
            if tmp != -1:
                re = tmp
                break
    # print('return {} is '.format(x), re)
    return re


def check_list(b):
    re = True
    for i, element in enumerate(b, 1):
        if i < element:
            re = False
            break
    return re


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

# encoding: utf-8
N, M = list(map(int, input().split()))
Amod = [A for A in map(lambda x: int(x) % M ,filter(lambda x: int(x) > 0, input().split()))]

ans = 0
for l in range(len(Amod)):
    acm = 0
    for r in range(l, len(Amod)):
        acm = (acm + Amod[r]) % M
        if acm == 0: ans += 1

print(ans)

### FIXED CODE ###

# encoding: utf-8
N, M = list(map(int, input().split()))

d_sym = {}
sym = 0

# refresh

ans = 0
for A in map(int, input().split()):
    sym = (sym + A) % M
    #
    if sym == 0: ans += 1
    # 
    if str(sym) in d_sym.keys(): d_sym[str(sym)] += 1
    else: d_sym[str(sym)] = 1

print(int(ans + sum([val * (val - 1) / 2 for val in d_sym.values()])))
### BUGGY CODE ###

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

a.append(k + a[0])
each_dist = [(a[i] - a[i - 1]) for i in range(1, n + 1)]
ans = k
for i in range(n):
    all_dist = sum(each_dist[: i] + each_dist[i + 1: ])
    if all_dist < ans:
        ans = all_dist

print(ans)

### FIXED CODE ###

k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(k + a[0])

each_dist = [(a[i] - a[i - 1]) for i in range(1, n + 1)]
print(k - max(each_dist))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

K,S = map(int, input().split())
count = 0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                count += 1
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-

K,S = map(int, input().split())
count = 0

for i in range(K+1):
    for j in range(K+1):
        if i + j <= S and S-i-j <= K:
            count += 1
print(count)
### BUGGY CODE ###

r = []
N = int(input())
for i in range(0, N):
    r.append(int(input()))

min_i = N-2
max_i = N-1

for i in range(N-1)[::-1]:
    if r[i] < r[i+1] or r[max_i] - r[min_i] < 0:
        for j in range(i+1, N):
            if r[j] - r[i] > r[max_i] - r[min_i]:
                max_i = j
                min_i = i

                
print(r[max_i] - r[min_i])

### FIXED CODE ###

N = int(input())
r = [int(input()) for i in range(N)]
 
min = r[0]
max = -9999999999999999
 
for i in range(1, N):
    if r[i] - min > max:
        max = r[i] - min
    if r[i] < min:
        min = r[i]
 
print(max)
### BUGGY CODE ###

def solve():
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [start]
    ans = [-1] * N
    ans[0] = 0
    reached = set()
    import heapq
    heapq.heapify(hq)
    while hq:
        x = heapq.heappop(hq)
        t,v = divmod(x,N*2501)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached.add(i)
            if len(reached) == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b)*N*2501 + nv)
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: continue
            times[nv] = nt
            heapq.heappush(hq, nt*N*2501 + nv)
    print(*ans[1:], sep='\n')
solve()

### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [start]
    ans = [-1] * N
    ans[0] = 0
    reached = 0
    import heapq
    heapq.heapify(hq)
    while hq:
        x = heapq.heappop(hq)
        t,v = divmod(x,N*2501)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached += 1
            if reached == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b)*N*2501 + nv)
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: break
            times[nv] = nt
            heapq.heappush(hq, nt*N*2501 + nv)
    print(*ans[1:], sep='\n')
solve()
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
mod=10**9+7

dp=[0]*(n+1)
dp[0]=1

if 1 not in a:
  dp[1]=1
else:
  dp[1]=0
  

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]=dp[i-1]+dp[i-2]
  dp[i]%=mod
  
print(dp[n])



### FIXED CODE ###

N,M = map(int,input().split())
a = set(int(input()) for x in range(M))
A = [0]*(N+1)
mod = 1000000007
A[0] = 1
if not(1 in a):
  A[1] = 1
for i in range(2,N+1):
    if i in a:
      A[i] = 0
    else:
      A[i] = (A[i-2] + A[i-1]) % mod
print(A[N])
### BUGGY CODE ###

N = int(input())
P = []
ans = 0
for i in range(N):
    s = int(input())
    P.append(s)
    ans += 1
P.sort()
for i in range(N-1):
    for j in range(i+1,N):
        if P[i] == P[j]:
            P[i] = -1 * i
            P[j] =  -1 * j
            ans -= 2
            break
        
print(ans)

### FIXED CODE ###

s = set()
N = int(input())
for _ in range(N):
    x = int(input())
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))
### BUGGY CODE ###

K,S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                count += 1
print(count)

### FIXED CODE ###

K,S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - (i+j) <= K:
            count += 1
print(count)
### BUGGY CODE ###

n,m=map(int,input().split())

#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    l[a-1].append(b)
    l[b-1].append(a)

#深さのリストを作る
l_depth=[1]
l_depth_sub=[0]*n
l_depth_sub[0]+=1
for i in range(n):
    for j in range(len(l[i])):
        if l_depth_sub[l[i][j]-1]==0:
            l_depth_sub[l[i][j]-1]+=1
            l_depth.append(l[i][j])               
    if l_depth_sub.count(0)==0:break

#解の出力
print('Yes')
for i in range(1,n):
    k=10**9
    for j in range(len(l[i])):
        if l_depth.index(l[i][j])<k:#より浅い部屋へ通じるのなら更新
            k=l_depth.index(l[i][j])
    print(l_depth[k])

### FIXED CODE ###

import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
 
g=nx.Graph() #無向グラフ
g.add_edges_from(s) #リストsを参照して頂点（部屋）の追加
di=nx.predecessor(g,source=1)#1から全点までの最短路におけるその点の前の点を表示
 
print("Yes")
for x in range(2,n+1):
      print(di[x][0])
### BUGGY CODE ###

import heapq
class HeapDict:
    def __init__(self):
        self.h = []
        self.d = {}

    def insert(self,x):
        if x not in self.d or self.d[x] == 0:
            heapq.heappush(self.h, x)
        self.d.setdefault(x,0)
        self.d[x] += 1


    def erase(self,x):
        if x not in self.d or self.d[x] == 0:
            return
        else:
            self.d[x] -= 1

        while self.h:
            if self.d[self.h[0]] == 0:
                heapq.heappop(self.h)
            else:
                break


    def get_min(self):
        if not self.h:
            return None
        else:
            return self.h[0]


    def pop(self):
        poped_val = self.h[0]
        self.erase(poped_val)
        return poped_val


    def exist(self, x):
        return (x in self.d and self.d[x] > 0)


    def show_h(self):
        elems = [v for v in self.h if self.d[v] > 0]
        print(elems)


    def show_d(self):
        print(self.d)

n,q = map(int, input().split())
eventl = []

for _ in range(n):
    s,t,x = map(int, input().split())
    eventl.append((s-x-0.5, 'stop', x)) 
    eventl.append((t-x-0.5, 'start', x))

for i in range(q):
    d = int(input())
    eventl.append((d,'go', i))

eventl.sort()

ans = [0]*q
hd = HeapDict()
for e in eventl:
    if e[1] == 'stop':
        hd.insert(e[2])
    elif e[1] == 'start':
        hd.erase(e[2])
    else:
        min_x = hd.get_min()
        if min_x is not None:
            ans[e[2]] = min_x
        else:
            ans[e[2]] = -1

for a in ans:
    print(a)

### FIXED CODE ###

import heapq
class HeapDict:
    def __init__(self):
        self.h = []
        self.d = {}

    def insert(self,x):
        if x not in self.d or self.d[x] == 0:
            heapq.heappush(self.h, x)
        self.d.setdefault(x,0)
        self.d[x] += 1


    def erase(self,x):
        if x not in self.d or self.d[x] == 0:
            return
        else:
            self.d[x] -= 1

        while self.h:
            if self.d[self.h[0]] == 0:
                heapq.heappop(self.h)
            else:
                break


    def get_min(self):
        if not self.h:
            return None
        else:
            return self.h[0]


    def pop(self):
        poped_val = self.h[0]
        self.erase(poped_val)
        return poped_val


    def exist(self, x):
        return (x in self.d and self.d[x] > 0)


    def show_h(self):
        elems = [v for v in self.h if self.d[v] > 0]
        print(elems)


    def show_d(self):
        print(self.d)



# def main():
n,q = map(int, input().split())
eventl = []

for _ in range(n):
    s,t,x = map(int, input().split())
    eventl.append((s-x, 'a-stop', x)) 
    eventl.append((t-x, 'b-start', x))

for i in range(q):
    d = int(input())
    eventl.append((d,'c-go', i))

eventl.sort()

ans = [0]*q
hd = HeapDict()
for e in eventl:
    if e[1] == 'a-stop':
        hd.insert(e[2])
    elif e[1] == 'b-start':
        hd.erase(e[2])
    else:
        min_x = hd.get_min()
        if min_x is not None:
            ans[e[2]] = min_x
        else:
            ans[e[2]] = -1

for a in ans:
    print(a)


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

S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]
s = list(S)
for j in range(Q):
    if Query[j][0] == '1':
        s.reverse()
    elif Query[j][1] == '1':
        s.insert(0,Query[j][2])
    else:
        s.append(Query[j][2])
printed = ''.join(s)
print(printed)

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]
s = list(S)
d = deque(s)
d_is_reversed = False
for j in range(Q):
    if Query[j][0] == '1':
        d_is_reversed = not d_is_reversed
    elif Query[j][1] == '1':
        if d_is_reversed == False:
            d.appendleft(Query[j][2])
        else:
            d.append(Query[j][2])
    else:
        if d_is_reversed == False:
            d.append(Query[j][2])
        else:
            d.appendleft(Query[j][2])
if d_is_reversed == True:
    d.reverse()
printed = ''.join(d)
print(printed)
### BUGGY CODE ###

from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-7

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r)) 


### FIXED CODE ###

from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r))
### BUGGY CODE ###

s = input()
q = int(input())

for i in range(q):
    t_f_c = list(input().split())
    if t_f_c[0] == "1":
        s = s[::-1]
    elif t_f_c[0] == "2":
        if t_f_c[1] == "1":
            s = t_f_c[2] + s
        elif t_f_c[1] == "2":
            s = s + t_f_c[2]
print(s)

### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())

cnt = 1
for i in range(q):
    t_f_c = list(input().split())
    if t_f_c[0] == "1":
        cnt *= -1
    elif t_f_c[0] == "2":
        if cnt == 1: #反転-
            if t_f_c[1] == "1":
                s.appendleft(t_f_c[2])
            elif t_f_c[1] == "2":
                s.append(t_f_c[2])
        elif cnt == -1:  #反転+
             if t_f_c[1] == "2":
                s.appendleft(t_f_c[2])
             elif t_f_c[1] == "1":
                s.append(t_f_c[2])
if cnt == 1:
    print("".join(s))
elif cnt == -1:
    s.reverse()
    print("".join(s))
### BUGGY CODE ###

import math
n=int(input())
for i in range(1,n+1):
    ans=0
    for x in range(1, math.floor(math.sqrt(i))+1):
        for y in range(1, math.floor(math.sqrt(i-x*x))+1):
            for z in range(1, math.floor(math.sqrt(abs(i-x*x-y*y-x*y)))+1):
                if x*x + y*y + z*z + x*y + y*z + z*x == i:
                    ans += 1
    print(ans)

### FIXED CODE ###

import math
N=int(input())
ans=[0 for _ in range(10**4+1)]
for x in range(1, math.floor(math.sqrt(10**4))+1):
    for y in range(1, math.floor(math.sqrt(10**4))+1):
        for z in range(1, math.floor(math.sqrt(10**4))+1):
            if x*x + y*y + z*z + x*y + y*z + z*x <= 10**4:
                ans[x*x + y*y + z*z + x*y + y*z + z*x]+=1
for i in range(1,N+1):
    print(ans[i])
### BUGGY CODE ###

s = str(input())
p = -1
q = -1
m = 0
n = 2
N = len(s)
while ((p+1)**2 + (q+1)**2) == 0:
    t = s[m:n]
    r = 0
    for i in range(len(t)):
        d = list(t).count(t[i])
        if r < d:
            r = d
    if r > (len(t)) /2:
        p = m + 1
        q = n 
    if (m-N+2)**2 + (n-N)**2 == 0:
        break
    if n != N:
        n += 1
    else:
        m += 1
        n = m + 2
   
print(p, q)

### FIXED CODE ###

s = input()
n = len(s)
for i in range(n-1):
    if s[i] == s[i+1]:
        print(i+1,i+2)
        break
    if i != n-2:
        if s[i] == s[i+2] or s[i+1] == s[i+2]:
            print(i+1,i+3)
            break
    if i == n-2:
        print(-1,-1)
### BUGGY CODE ###

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

p = 1
ans = 0
while True:
    if p not in a_list:
        ans += len(a_list)
        break
    i = a_list.index(p)
    ans += i
    a_list = a_list[i+1:]
    p += 1
if ans == n:
    ans = -1
print(ans)


### FIXED CODE ###

from collections import deque

n = int(input())
a_list = deque(map(int, input().split()))

p = 1
ans = 0
while len(a_list) > 0:
    if a_list.popleft() == p:
        p += 1
    else:
        ans += 1
if ans == n:
    ans = -1
print(ans)