Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

def make_divisors(n: int):
    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)
    return divisors

m = [0] * (N+1)
for i in range(N):
    divisors = make_divisors(A[i])
    for d in divisors:
        m[d] += 1

ans = 1
for i in range(N+1):
    if (N-1) <= m[i] and ans < m[i]:
        ans = m[i]

print(ans)

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

from fractions import gcd
left = [A[0]]
right = [A[-1]]

for i in range(1, N-1):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[-1-i]))

ans = 1
for i in range(N):
    if i == 0:
        tmp = right[-1]
    elif i == N-1:
        tmp = left[-1]
    else:
        tmp = gcd(left[i-1], right[N-2-i])
    ans = max(ans, tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def make_divisors(n: int):
    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)
    return divisors

from collections import defaultdict
m = defaultdict(int)

for i in range(N):
    divisors = make_divisors(A[i])
    for d in divisors:
        m[d] += 1

ans = 1
for k, v in sorted(m.items(), key=lambda x: x[0]):
    if v >= N-1 and ans < k:
        ans = k

print(ans)

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

from fractions import gcd
left = [A[0]]
right = [A[-1]]

for i in range(1, N-1):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[-1-i]))

ans = 1
for i in range(N):
    if i == 0:
        tmp = right[-1]
    elif i == N-1:
        tmp = left[-1]
    else:
        tmp = gcd(left[i-1], right[N-2-i])
    ans = max(ans, tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

from functools import lru_cache
@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

ans = 1
for i in range(N):
    if i != 0:
        a = A[0]
    else:
        a = A[1]
    for j in range(N):
        if i == j:
            continue
        a = gcd(a, A[j])
    ans = max(ans, a)
print(ans)

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

from fractions import gcd
left = [A[0]]
right = [A[-1]]

for i in range(1, N-1):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[-1-i]))

ans = 1
for i in range(N):
    if i == 0:
        tmp = right[-1]
    elif i == N-1:
        tmp = left[-1]
    else:
        tmp = gcd(left[i-1], right[N-2-i])
    ans = max(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

ans = []
for k in range(len(bin(10**12))-2):
    one = 0
    for i in range(A, B+1):
        x = (i >> k) & 1
        if x == 1: one += 1
    if one % 2 == 0:
        ans += '0'
    else:
        ans += '1'
ans.reverse()
print(int(''.join(ans), 2))

Fixed submission:
A, B = map(int, input().split())

def f(n, k):
    if n < 0:
        return 0
    if n // 2**k == 0:
        if n >= 2**(k-1):
            return n - 2**(k-1) + 1
        else:
            return 0
    else:
        return int((n // 2**k) * (2**(k-1))) + f(n-(n // 2**k)*(2**k), k)

ans = []
for k in range(1, len(bin(10**12))-1):
    b = f(B, k)
    a = f(A-1, k)
    one = b-a
    if one % 2 == 0:
        ans += '0'
    else:
        ans += '1'

ans.reverse()
print(int(''.join(ans), 2))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
t = ''
for i in range(len(S)):
    if t == '':
        t += S[i]
    elif t[-1] != S[i]:
        t = t[:-1]
    else:
        t += S[i]
print(len(S)-len(t))

Fixed submission:
S = input()
t = []
for s in S:
    if len(t) == 0:
        t += s
    elif t[-1] != s:
        t.pop()
    else:
        t += s
print(len(S)-len(t))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
pre = S
while True:
    t = pre.replace('01', '')
    t = t.replace('10', '')
    if pre == t:
        break
    pre = t
print(len(S)-len(t))

Fixed submission:
S = input()
t = []
for s in S:
    if len(t) == 0:
        t += s
    elif t[-1] != s:
        t.pop()
    else:
        t += s
print(len(S)-len(t))
Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = sorted(list(map(int, input().split())))

d = deque(A)
ans = d[0]
while d:
    l = d.popleft()
    r = d.popleft()
    a = r % l
    if a == 0:
        d.appendleft(l)
    elif a == 1:
        ans = 1
        break
    else:
        ans = min(ans, a)
        d.appendleft(r)
        d.appendleft(a)
print(ans)


Fixed submission:
from fractions import gcd
N = int(input())
A = sorted(list(map(int, input().split())))
ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
l = list(map(int, input().split()))
dp = [0]+[float('inf')]*(N-1)
for i in range(N):
    for k in range(1, K+1):
        if i < N-k:
            dp[i+k] = min(dp[i+k], dp[i]+abs(l[i+k]-l[i]))
print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
l = list(map(int, input().split()))
dp = [0]+[float('inf')]*(N-1)
for i in range(N):
    for k in range(1, K+1):
        if i < N-k:
            dp[i+k] = min(dp[i+k], dp[i]+abs(l[i+k]-l[i]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

from fractions import gcd
ans = 0
for i in range(1, (M//N)+1):
    ans = max(ans, gcd(i, M-(i*(N-1))))

print(ans)

Fixed submission:
N, M = map(int, input().split())

from fractions import gcd

def make_divisors(n: int):
    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)
    return divisors

divisors = make_divisors(M)

ans = 0
for i in range(len(divisors)):
    d = divisors[i]
    if d*(N-1) >= M:
        continue
    ans = max(ans, gcd(d, M-(d*(N-1))))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
r = 0
for l in range(N):
    tmp = 0
    for r in range(l, N):
        if tmp + A[r] != tmp ^ A[r]:
            break
        tmp += A[r]
        ans += 1

print(ans)

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

ans = 0
l = r = 0
total = A[0]
xor = A[0]

while True:
    if xor == total:
        ans += r - l + 1
        r += 1
        if r == N:
            break
        total += A[r]
        xor ^= A[r]
    else:
        total -= A[l]
        xor ^= A[l]
        l += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

N = len(s)
words = set()
for i in range(N):
    for j in range(i+1, N+1):
        w = s[i:j]
        words.add(w)

print(sorted(list(words))[K-1])

Fixed submission:
s = input()
K = int(input())

N = len(s)
words = set()
for i in range(N):
    for j in range(i+1, i+K+1):
        w = s[i:j]
        if w not in words:
            words.add(w)

print(sorted(list(words))[K-1])
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]

from collections import deque
q = deque([(0, 0)])
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
l[0][0] = 0

while q:
    y, x = q.popleft()
    for dy, dx in d:
        if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.':
            l[y+dy][x+dx] = l[y][x] + 1
            q.append((y+dy, x+dx))

g = l[H-1][W-1]
total = 0
for _l in l:
    for i in _l:
        if i != '#':
            total += 1
print(total - g - 1)

Fixed submission:
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]

from collections import deque
q = deque([(0, 0)])
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
l[0][0] = 0

while q:
    y, x = q.popleft()
    for dy, dx in d:
        if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.':
            l[y+dy][x+dx] = l[y][x] + 1
            q.append((y+dy, x+dx))

try:
    g = l[H-1][W-1]
    total = 0
    for _l in l:
        for i in _l:
            if i != '#':
                total += 1
    print(total - g - 1)
except:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i): 
        for k in range(n + 1 - i - j):
            if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n:
                print(i, j, k)
                break
        else:
            continue
        break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i): 
        k = n - i - j
        if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = tuple(map(int, input().split()))
count = 0
while all(i % 2 == 0 for i in l):
    count += 1
    l = tuple(map(lambda x: x / 2, l))
print(count)

Fixed submission:
print(input().count('1'))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(500000)

N = int(input())

tree = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    tree[a].append((b, c))
    tree[b].append((a, c))

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

from functools import lru_cache
@lru_cache(maxsize=None)
def dfs(start, end, dist, f=None):
    if start == end:
        return 0
    for n, d in tree[start]:
        if n == f:
            continue
        if n == end:
            return dist + d
        else:
            result = dfs(n, end, dist+d, start)
            if result is not None:
                return result

xy = [list(map(int, input().split())) for i in range(Q)]

for i in range(Q):
    x, y = xy[i]
    print(dfs(x, K, 0) + dfs(K, y, 0))


Fixed submission:
import sys
sys.setrecursionlimit(500000)

N = int(input())

tree = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    tree[a].append((b, c))
    tree[b].append((a, c))

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

def dfs(start, dist, dists, f=None):
    for n, d in tree[start]:
        if n == f:
            continue
        dists[n] = dist + d
        dfs(n, dist+d, dists, start)

xy = [list(map(int, input().split())) for i in range(Q)]

dists = [0] * (N+1)
dfs(K, 0, dists)

for i in range(Q):
    x, y = xy[i]
    print(dists[x] + dists[y])
Buggy python submission (verdict: Runtime Error):
s = input()
print(f'{s[0]}{len(s)-2}{s[-1]}')

Fixed submission:
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]))

Buggy python submission (verdict: Runtime Error):
s = input()
print(f'{s[0]}{len(s)-2}{s[-1]}')

Fixed submission:
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.reverse()

from collections import deque
b1 = deque([])
b2 = deque([])

for i in range(N):
    if i % 2 == 0:
        b1.append(A[i])
    else:
        b2.appendleft(A[i])
print(*(b1+b2))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.reverse()

from collections import deque
b1 = deque([])
b2 = deque([])

for i in range(N):
    if i % 2 == 0:
        b1.append(A[i])
    else:
        b2.appendleft(A[i])
print(*(list(b1)+list(b2)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(int, input().split()))

c = 0
prev = 0
for i in range(n):
    flag = False
    s = sum(arr[:i+1])
    if i > 0:
        if prev > 0 and s >= 0:
            diff = s + 1
            c += diff
            arr[i] -= diff 
        elif prev < 0 and s <= 0:
            diff = -1 * s + 1
            c += diff
            arr[i] += diff
        else:
            flag = True
    prev = s if flag else sum(arr[:i+1])
print(c)

Fixed submission:
n = int(input())
_arr = list(map(int, input().split()))

ans = []
for first in (_arr[0], -1 * _arr[1] + 1, -1 * _arr[1] - 1, 1, -1):
    arr = _arr[:]
    c = 0
    prev = 0
    for i in range(n):
        t = prev + arr[i]
        if i == 0:
            c += abs(arr[i] - first)
            arr[i] = first
        elif prev > 0 and t >= 0:
            diff = t + 1
            c += diff
            arr[i] -= diff
        elif prev < 0 and t <= 0:
            diff = -1 * t + 1
            c += diff
            arr[i] += diff
        prev += arr[i]
    ans.append(c)
print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                count += 1
print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        if s - k <= x + y <= s:
            count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import re
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

while s != '':
    tmp = s
    s = re.sub(r'dream$', '', s)
    s = re.sub(r'dreamer$', '', s)
    s = re.sub(r'erase$', '', s)
    s = re.sub(r'eraser$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break


Fixed submission:
s = input()
while s != '':
    tmp = s
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Buggy python submission (verdict: Time Limit Exceeded):
import re
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

while s != '':
    tmp = s
    for word in words:
        s = re.sub(r'dream$', '', s)
        s = re.sub(r'dreamer$', '', s)
        s = re.sub(r'erase$', '', s)
        s = re.sub(r'eraser$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Fixed submission:
s = input()
while s != '':
    tmp = s
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Buggy python submission (verdict: Runtime Error):
import re
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

while s != '':
    tmp = s
    for word in words:
        s = re.sub(f'{word}$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Fixed submission:
s = input()
while s != '':
    tmp = s
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

t = 1
a = 1

for i in range(N):
    T, A = TA[i]
    mul = 2
    while t > T or a > A:
        T = TA[i][0] * mul
        A = TA[i][1] * mul
        mul += 1
    t = T
    a = A
print(t+a)

Fixed submission:
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

t = 1
a = 1

for i in range(N):
    T, A = TA[i]
    if t > T or a > A:
        tmul = (t+T-1) // T
        amul = (a+A-1) // A
        mul = max(tmul, amul)
        T *= mul
        A *= mul
    t = T
    a = A
print(t+a)
Buggy python submission (verdict: Runtime Error):
import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = []

nums = input().rsplit()

# for i in range(0, N - 1):
#     a = input()
#     if a == 0:
#         print(0)
#         sys.exit(1)
#     nums.append(a)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except OverflowError:
        print(-1)
        sys.exit(1)

    if accum > limit:
        print(-1)
        sys.exit(1)

print(accum)


Fixed submission:
import sys

N = int(input().rstrip())

limit = pow(10, 18)

nums = list(input().split())

for num in nums:
    num = int(num)
    if num == 0:
        print(0)
        sys.exit(0)

accum = 1
for num in nums:
    num = int(num)
    try:
        accum *= num
    except Exception:
        accum = -1
        break

    if accum > limit:
        accum = -1
        break

print(accum)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
ans=0
for i in range(N-1):
	#print(A[N-i-1],A[:N-1-i])
	ans+=A[N-i-1]*(sum(A[:N-1-i]))
	ans=ans%(10**9+7)
					
print(ans)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
ans=0
SM=sum(A)
for i in range(N-1):
	SM-=A[N-1-i]
	ans+=A[N-i-1]*SM
	ans=ans%(10**9+7)
					
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
ans=0
for i in range(N-1):
	for j in range(i+1,N):
		ans+=(A[i]*A[j])
		ans=ans%(10**9+7)	
print(ans)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
ans=0
SM=sum(A)
for i in range(N-1):
	SM-=A[N-1-i]
	ans+=A[N-i-1]*SM
	ans=ans%(10**9+7)
					
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
ans=0
for i in range(N-1):
	for j in range(i+1,N):
		ans+=(A[i]*A[j])
		ans=ans%(10**9+7)	
print(ans)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
ans=0
SM=sum(A)
for i in range(N-1):
	SM-=A[N-1-i]
	ans+=A[N-i-1]*SM
	ans=ans%(10**9+7)
					
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
import numpy as np

N,M,X=map(int, input().split())
list_=[list(map(int, input().split())) for _ in range(N)]
gokei=X
cost=100001
list_C=[]

for i in range(N):
	list_C=np.array(list(combinations(list_,N-i)))
	count=0
	for h in range(len(list_C)):

		if all(np.sum(list_C[h], axis=0)[1:]>=X) and np.sum(list_C[h], axis=0)[0]<cost:
				cost=np.sum(list_C[h], axis=0)[0]
				count+=1

		if count==0:
		break

print(cost if cost<100001 else -1)


Fixed submission:
from itertools import combinations
import numpy as np

N,M,X=map(int, input().split())
list_=[list(map(int, input().split())) for _ in range(N)]
cost=100000001
list_C=[]

for i in range(N):
	list_C=np.array(list(combinations(list_,N-i)))
	count=0
	#print(list_C)
	for h in range(len(list_C)):
		if all(np.sum(list_C[h], axis=0)[1:]>=X):
			if np.sum(list_C[h], axis=0)[0]<cost:
				cost=np.sum(list_C[h], axis=0)[0]
			#print(np.sum(list_C[h], axis=0),cost)
			count+=1
	if count==0:
		break

print(cost if cost<100000001 else "-1")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(input())

for i in range(1,N+1):
	if str(i) in A:
		print(A.count(str(i)))
	else:
		print("0")


Fixed submission:
N = int(input())
K = [0]*N
A = [int(i) for i in input().split()]

for i in range(N-1):
    K[A[i]-1] += 1
for i in K:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
A_=list(set(A))
count_=["0\n"]*N

for i in range(len(A_)):
	count_[A_[i]-1]=str(A.count(A_[i]))+"\n"

print("".join(count_))



Fixed submission:
N = int(input())
K = [0]*N
A = [int(i) for i in input().split()]

for i in range(N-1):
    K[A[i]-1] += 1
for i in K:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
countzumi=[]
count_=[0]*N

for i in range(len(A)):
	if A[i] not in countzumi:
		count_[A[i]-1]=A.count(A[i])
		countzumi.append(A[i])

for i in range(N):
	print(count_[i])



Fixed submission:
N = int(input())
K = [0]*N
A = [int(i) for i in input().split()]

for i in range(N-1):
    K[A[i]-1] += 1
for i in K:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
	return reduce(math.gcd, numbers)

K = int(input())
S=0
for i in range(1,K+1):
	for h in range(1,K+1):
		for g in range(1,K+1):
			S+=gcd(g,h,i)

print(S)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
	return reduce(math.gcd, numbers)

K = int(input())
S=0
for i in range(1,K+1):
	for h in range(i,K+1):
		for g in range(h,K+1):

			if i==h and h==g:
				S+=gcd(g,h,i)
			elif i==h or h==g or g==i:
				S+=3*gcd(g,h,i)
			else:
				S+=6*gcd(g,h,i)
			
print(S)
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
if N > K and N//K>2:
	a = N//K
	N= N-K*(a-2)

while N>0:
	T = N
	N = abs(N-K)
	if N >T:
		break

print(min(N,T))

Fixed submission:
N,K = map(int, input().split())
if N > K and N//K>2:
	a = N//K
	N= N-K*(a-2)

while N>0:
	T = N
	N = abs(N-K)
	if N >T:
		break

print(N if N==0 else min(N,T) )
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N=int(input())
S=[input() for _ in range(N)]

S_C=collections.Counter(S).most_common()

keys,values=zip(*S_C)
ans=[]
for i in range(len(values)):
	if values[i]==max(values):
		ans.append(keys[i])

ans=sorted(ans)

for h in range(len(ans)):
	print(ans[h])

Fixed submission:
N=int(input())
Sdict={}

for i in range(N):
	s=input()
	if s in Sdict:
		Sdict[s]+=1
	else:
		Sdict[s]=1

vmax=max(Sdict.values())

#Sdict_sorted=sorted(Sdict.items(), key=lambda x:x[1])
#print(Sdict_sorted)

anskeys = [k for k, v in Sdict.items() if v == vmax]
for ans in sorted(anskeys):
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[i]!=now:
			A.pop(i)
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)
		

Fixed submission:
N=int(input())
A=list(map(int, input().split()))[::-1]

flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[-(i+1)]!=now:
			A.pop(-(i+1))
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[i]!=now:
			A.pop(i)
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)
		

Fixed submission:
N=int(input())
A=list(map(int, input().split()))[::-1]

flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[-(i+1)]!=now:
			A.pop(-(i+1))
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)