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

n, p = map(int,input().split())
D = input()
out = 0


if 10 % p == 0:
    for i in range(n):
        if int(D[i]) % p == 0:
            out += i + 1
else:
    mod = 0
    count = [0] * p
    ten = 1
    count[mod] += 1
    for i in range(n):
        mod = (mod + int(D[n-i-1]) * ten) % p
        ten = ten * 10
        count[mod] += 1
    for c in count:
        out += (c * (c - 1)) // 2
print(out)

### FIXED CODE ###

n, p = map(int,input().split())
D = input()
out = 0


if 10 % p == 0:
    for i in range(n):
        if int(D[i]) % p == 0:
            out += i + 1
else:
    mod = 0
    count = [0] * p
    ten = 1
    count[mod] += 1
    for i in range(n):
        mod = (mod + int(D[n-i-1]) * ten) % p
        ten = ten * 10 % p
        count[mod] += 1
    for c in count:
        out += (c * (c - 1)) // 2
print(out)
### BUGGY CODE ###

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

cnt = 0
while True:
    g =-1
    for i in range(N):
        if a[i] % 2 == 0:
            g = i
            break
        elif i == N - 1:
            print(cnt)

    if g == -1:
        break

    for i in range(N):
        if g == i:
            a[i] /= 2
    cnt += 1


### FIXED CODE ###

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

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

N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(lis,ans_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')

### FIXED CODE ###

N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')
### BUGGY CODE ###

import itertools


def main():
    N, M, R = list(map(int, input().split(' ')))

    r = [int(a)-1 for a in input().split()]

    d = [[float('inf')]*N for _ in range(N)]

    for _ in range(M):
        a, b, c = list(map(int, input().split(' ')))
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    for a in range(N):
        d[a][a] = 0

    res = float('inf')

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

    for perm in itertools.permutations(r):
        a = 0
        for i in range(len(perm)-1):
            a += d[perm[i]][perm[i+1]]
        if a < res:
            # print(perm, a)
            res = a

    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
import sys

def readline():
    return sys.stdin.readline()

def read_int_list():
    return list(map(int, readline().split()))

def read_int():
    return int(readline())

def main():
    N, M, R = map(int, input().split())
    r = map(int, input().split())

    inf = float("inf")
    d = [[inf] * (N + 1) for _ in range(N + 1)]
    for n in range(1, N + 1):
        d[n][n] = 0

    for _ in range(M):
        a, b, c = map(int, input().split())
        d[a][b] = c
        d[b][a] = c

    for k in range(1, N + 1):
        for i in range(1, N + 1):
            for j in range(1, N + 1):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    min_cost = inf
    for p in itertools.permutations(r):
        cost = 0
        for i in range(len(p) - 1):
            src, dst = p[i:i + 2]
            cost += d[src][dst]
        min_cost = min(min_cost, cost)

    print(min_cost)


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

from scipy.misc import comb
# from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p_red = 0
        for l in range(i-1, m+1):
            p_red += calc_comb(l-1, i-2) * (m-l+1)
            p_red %= MOD
        p = calc_comb(K-1, i-1) * p_red % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()

### FIXED CODE ###

from scipy.misc import comb
# from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p = calc_comb(K-1, i-1) * calc_comb(m+1, i) % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
for i in range(q):
    cnt = 0
    l, r = map(int, input().split())
    for j in range(r-l):
        if s[l-1:r][j:j+2]=="AC": cnt+=1
    print(cnt)

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

R, G, B, N = [int(i) for i in input().split()]

count = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        if (N - R * r - G * g) % B == 0 and (N - R * r - G * g) // B >= 0:
            count += 1

print(count)

### FIXED CODE ###

R, G, B, N = [int(i) for i in input().split()]

count = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        if (N - R * r - G * g) % B == 0 and (N - R * r - G * g) // B >= 0:
            count += 1

print(count)
### BUGGY CODE ###

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

L=[]
l=["*" for i in range(W+2)]
L.append(l)
for i in range(H):
    s=input()
    s="*"+s+"*"
    s=list(s)
    L.append(s)
L.append(l)

#print(L)
Li=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j]=="#":
            Li.append([i,j])
#print(Li)
x=[1,-1,0,0]
y=[0,0,1,-1]
ans=0
for i in range(len(Li)):
    A=[[0 for i in range(W+2)]for j in range(H+2)]
    Arr=[[Li[i][0],Li[i][1],0]]
    #print(Arr)
    A[Arr[0][0]][Arr[0][1]]=1
    for j in range(W*H*2):
        if Arr==[]:
            break
        else:
            #print(Arr,ans)
            
            if (Arr[0][2])%2==0:
                for k in range(4):
                    if L[Arr[0][0]+x[k]][Arr[0][1]+y[k]]=="." and A[Arr[0][0]+x[k]][Arr[0][1]+y[k]]==0:
                        Arr.append([Arr[0][0]+x[k],Arr[0][1]+y[k],Arr[0][2]+1])
                        A[Arr[0][0]+x[k]][Arr[0][1]+y[k]]=1
                        ans+=1
                del Arr[0]
            else:
                for k in range(4):
                    if L[Arr[0][0]+x[k]][Arr[0][1]+y[k]]=="#" and A[Arr[0][0]+x[k]][Arr[0][1]+y[k]]==0:
                        Arr.append([Arr[0][0]+x[k],Arr[0][1]+y[k],Arr[0][2]+1])
                        A[Arr[0][0]+x[k]][Arr[0][1]+y[k]]=1
                del Arr[0]
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
L=[list(input())for i in range(H)]
#print(L)

P=[i for i in range(H*W)]
size=[[0,0]for i in range(H*W)]

for i in range(H):
    for j in range(W):
        if L[i][j]==".":
            size[i*W+j][0]+=1
        else:
            size[i*W+j][1]+=1
#print(size)

def find(z):
    if  z==P[z]:
        return z
    else:
        return find(P[z])
def union(x,y):
    X=find(x)
    Y=find(y)
    if sum(size[X])>=sum(size[Y]):
        P[Y]=P[X]
        size[X][0]+=size[Y][0]
        size[X][0]+=size[Y][1]
    else:
        P[X]=P[Y]
        size[Y][0]+=size[X][0]
        size[Y][0]+=size[X][1]
        
for i in range(H):
    for j in range(W):
        if j+1<=W-1:
            
            if L[i][j]!=L[i][j+1]:
                
                if find(i*W+j)!=find(i*W+j+1):
                    #print(i,j)
                    union(i*W+j,i*W+j+1)
        if i+1<=H-1:
            if L[i][j]!=L[i+1][j]:
                if find((i)*W+j)!=find((i+1)*W+j):
                    union(i*W+j,(i+1)*W+j)
BW=[[0,0]for i in range(H*W)]
for i in range(H):
    for j in range(W):
        if L[i][j]==".":
            BW[find(i*W+j)][0]+=1
        else:
            BW[find(i*W+j)][1]+=1

ans=0
for i in range(H):
    for j in range(W):
        if P[i*W+j]==i*W+j:
            ans+=BW[i*W+j][0]*BW[i*W+j][1]
#print(P)
#print(BW)
print(ans)
### BUGGY CODE ###

import sys

def main():
    def input():
        return sys.stdin.readline()[:-1]
    N = int(input())
    S = input() + "_"
    #shakutori * 2
    ans = 0
    for s in range(N-1):
        for e in range(s+1,N):
            if S[s] == S[e]:
                k = 0
                while s+k < e and e+k < N and S[s+k] == S[e+k]:
                    k += 1
                    if e+k == N:
                        break
                ans = max(ans,k)
    print(ans)
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def main():
    def input():
        return sys.stdin.readline()
    N = int(input())
    S = "_" + input()

    dp = [[0 for k in range(N+1)] for l in range(N+1)]

    for k in range(1,N):
        for l in range(k+1,N+1):
            if S[k] == S[l]:
                dp[k][l] = dp[k-1][l-1] + 1
    ans = 0
    for k in range(1,N):
        for l in range(k+1,N+1):
            if l-k >= dp[k][l]:
                ans = max(ans,dp[k][l])

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

from itertools import combinations

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a, reverse=True)

    x = {}
    for i in a:
        x[i] = True

    for i in range(0, n - 1):
        for j in range(i + 1, n):
            if a[i] % a[j] == 0:
                x[a[i]] = False
                break

    ans = 0
    for i in x.values():
        if i:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)

    max_a = max(a) + 1
    dp = [True] * max_a

    for idx in range(len(a)):
        if idx + 1 != len(a) and a[idx] == a[idx + 1]:
            dp[a[idx]] = False
        i = a[idx]
        x = 2
        while i * x < max_a:
            dp[i * x] = False
            x += 1

    ans = 0
    for i in a:
        if dp[i]:
            ans += 1
    print(ans)


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

N, K = map(int, input().split(" "))
a = sorted(list(map(int, input().split(" "))))
nums = []
# print(int(N * (N -1) /2))
for i in range(N):
    for j in range(i + 1, N):
        num = a[i] * a[j]
        nums.append(a[i] * a[j])
        if a[i] < 0 and a[i] * a[N - 1] > max(nums) and len(nums) >= K:
            print(sorted(nums)[K -1])
            # print(len(nums))
            exit()
        if j + 1 <= N -1 and a[i] >= 0 and a[i] * a[j + 1] > max(nums) and len(nums) >= K:
            print(sorted(nums)[K -1])
            # print(len(nums))
            exit()
print(sorted(nums)[K - 1])
# print(len(nums))

### FIXED CODE ###

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

# 負の個数
num_neg = bisect.bisect_left(A, 0)
# 0の個数
num_zero = bisect.bisect_right(A, 0) - num_neg
# 正の個数
num_pos = N - num_neg - num_zero

A_neg_rev = A[:num_neg] # 絶対値が大きいものからになるようにソート
A_pos = A[num_neg + num_zero:] # 絶対値が小さいものからになるようにソート

A_neg = A_neg_rev[::-1] # 絶対値が大きいものからになるようにソート
A_pos_rev = A_pos[::-1] # 絶対値が小さいものからになるようにソート

# 値が0になるペアの個数
cnt_zero = num_zero * (num_pos + num_neg) + (num_zero * (num_zero - 1) // 2)
# 値が負になるペアの個数
cnt_neg = num_pos * num_neg

# 値が正になるとき
def syakutori_pos(arr, mid):
    if len(arr) == 0:
        return 0
    cnt = 0
    l = 0
    r = len(arr) - 1
    while l < r:
        if arr[l] * arr[r] <= mid:
            cnt += r - l
            l += 1
        else:
            r -= 1
    return cnt

# 値が負になるとき
def syakutori_neg(arr_pos, arr_neg, mid):
    if len(arr_pos) == 0 or len(arr_neg) == 0:
        return 0
    arr = arr_neg + arr_pos
    cnt = 0
    l = 0
    r = len(arr) - 1
    while l < len(arr_neg) and r >= len(arr_neg):
        if arr[l] * arr[r] <= mid:
            cnt += r - len(arr_neg) + 1
            l += 1
        else:
            r -= 1
    return cnt

# 自分以下の数になるペアの個数がK個以上になる
ok = 10 ** 18
ng = -ok - 1
while ng + 1 < ok:
    mid = (ok + ng) // 2
    cnt = 0
    if mid > 0:
        cnt += cnt_zero
        cnt += cnt_neg
        cnt += syakutori_pos(A_pos, mid) + syakutori_pos(A_neg, mid)
    elif mid == 0:
        cnt += cnt_zero
        cnt += cnt_neg
    else:
        cnt += syakutori_neg(A_pos_rev, A_neg_rev, mid)
    if cnt >= K:
        ok = mid
    else:
        ng = mid

print(ok)
### BUGGY CODE ###

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

#  f = open('C_input_29.txt')
#  lines = f.readlines()
#  f.close()
#  N, M = map(int, lines[0].split())
#  A = []
#  for line in lines[1:]:
#      A.append(int(line))

N, M = LI()
A = []
for i in range(M):
    A.append(_I())

#  if M != 0:
#      # 連続した壊れた段がある場合は0
#      B = [i for i in A]
#      B.remove(B[0])
#      B.append(10**15+100)
#      diffs = [b - a for a, b in zip(A,B)]
#      #  print(diffs)

#      if any(i == 1 for i in diffs):
#          # 隣同士なので0
#          print(0)
#          exit()
#  print('hoge')
"""
考え方
xにたどり着く通りは、x-1とx-2段目にたどり着く通りの合計
dp
3が障害のとき
1へは1通り
2へは0からと1からの2通り
3へは0通り
4へは2からの2通りと、3からの0通りで2通り
5へは3からの0通りと4からの2通りで2通り
6へは4からの2通りと5からの2通りで4通り
"""
#  dp = {}
dp = [0 for i in range(N+1)]
#  print('fua')
dp[0] = 1
dp[1] = 1 if 1 not in A else 0
#  [dp.update({i: (dp[i-1] + dp[i-2])%mod}) if i not in A else dp.update({i: 0}) for i in range(2, N+1)]
for i in range(2, N+1):
    #  print(i)
    # i段目までの通りを計算する
    if i not in A:
        # i段目が障害のときは0になっているので飛ばす
        dp[i] = (dp[i-1] + dp[i-2])
        dp[i] %= mod

print(dp[N])


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

mod = 10 ** 9 + 7

def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())


n, m = get_numbers()
a = set(get_nums(m))

dp = [0 for _ in range(n + 1)]
dp[0] = 1
if 1 not in a:
    dp[1] = 1

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

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

N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]

for i in range(1,N+1):
  plus = A.count(i)
  if K - (Q-plus) <= 0:
    print("No")
  else:
    print("Yes")



### FIXED CODE ###

N,K,Q = map(int,input().split())
minas = [-Q]*N
A = [int(input()) for _ in range(Q)]
for i in A:
  minas[i-1] += 1
  
for i in minas:
  if  K + i<= 0:
    print("No")
  else:
    print("Yes")
### BUGGY CODE ###

n = int(input())
*A, = map(int, input().split())
a, b, c = 0, 0, 0
for x in A:
    if x == 1:
        a += 1
    if x == 2:
        b += 1
    if x == 3:
        c += 1
DP = [[[0 for k in range(n+1)] for j in range(n+1)] for i in range(n+1)]
for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(n-j-k+1):
            if i+j+k == 0:
                continue
            tmp = n
            if i > 0:
                tmp += DP[i-1][j][k]*i
            if j > 0:
                tmp += DP[i+1][j-1][k]*j
            if k > 0:
                tmp += DP[i][j+1][k-1]*k
            DP[i][j][k] = tmp/(i+j+k)
print(DP[a][b][c])


### FIXED CODE ###

n = int(input())
*A, = map(int, input().split())
a, b, c = A.count(1), A.count(2), A.count(3)
DP = [[[0.0 for k in range(n+1)] for j in range(n+1)] for i in range(n+1)]
for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(n-j-k+1):
            if i+j+k == 0:
                continue
            tmp = n
            if i > 0:
                tmp += DP[i-1][j][k]*i
            if j > 0:
                tmp += DP[i+1][j-1][k]*j
            if k > 0:
                tmp += DP[i][j+1][k-1]*k
            DP[i][j][k] = tmp/(i+j+k)
print(DP[a][b][c])
### BUGGY CODE ###

n = int(input())
l, r = 0, n - 1
print(0)
data1 = input()
print(n - 1)
data2 = input()

def check(l, r, data1, data2):
    if ( (r - l) % 2 == 0 and data1 != data2) or ( (r - l) % 2 == 1 and data1 == data2):
        return True
    return False

while data1 != "Vacant" and data2 != "Vacant":
    m = (l + r) // 2
    print(m)
    s = input()
    if s == "Vacant":
        exit()
    if check(m, r, data1, s):
        l = m
        data1 = s
    elif check(l, m s, data1):
        r = m
        data2 = s
    
    


### FIXED CODE ###

n = int(input())
l, r = 0, n - 1
print(0)
data = input()
while data != "Vacant":
    m = (l + r) // 2
    print(m)
    s = input()
    if s == "Vacant":
        exit()
    if ( m % 2 == 0 and data == s) or ( m % 2 == 1 and data != s):
        l = m + 1
    else:
        r = m - 1
### BUGGY CODE ###

def calc(N, adj, ignore):
    dp = [0.0] * (N)
    dp[N-1] = 0.0
    s, t = ignore
    for i in range(N-2, -1, -1):
        n = len(adj[i])
        if i == s:
            n -= 1
            if n == 0:
                return float("Inf")
        for nxt in adj[i]:
            if i == s and nxt == t:
                continue
            dp[i] += (dp[nxt] + 1) / n
    return dp[0]


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    x = [(-1, -1)]
    for _ in range(M):
        s, t = map(int, input().split())
        adj[s-1].add(t-1)
        x.append((s-1, t-1))
    ans = float("Inf")
    for ignore in x:
        tmp = calc(N, adj, ignore)
        ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def calc(N, adj, dp, ignore):
    s, t = ignore
    for i in range(N-1, -1, -1):
        dp[i] = 0.0
        n = len(adj[i])
        if i == s:
            n -= 1
        for nxt in adj[i]:
            if i == s and nxt == t:
                continue
            dp[i] += (dp[nxt] + 1) / n
    return dp[0]


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        s, t = map(int, input().split())
        adj[s-1].add(t-1)
    dp1 = [0.0] * N
    ans = calc(N, adj, dp1, (-1, -1))
    dp2 = [0.0] * N
    for i in range(N-1, -1, -1):
        if len(adj[i]) <= 1:
            continue
        j = i
        mx = -1
        for nxt in adj[i]:
            if dp1[nxt] > mx:
                j = nxt
                mx = dp1[nxt]
        tmp = calc(N, adj, dp2, (i, j))
        ans = min(ans, tmp)
    print(ans)


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

#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

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

    a_sorted = sorted(a, reverse=True)

    for i in range(n):
        index = a_sorted.index(a[i])
        if index == 0:
            print(a_sorted[index + 1])
            continue

        print(a_sorted[0])


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

    a = [None] * n
    for i in range(n):
        a[i] = int(input())

    a_sorted = sorted(a, reverse=True)
    a_max = max(a)

    for i in a:
        if i != a_max:
            print(a_max)
            continue

        index = a_sorted.index(i)
        if index == 0:
            print(a_sorted[index + 1])


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

N = int(input())
a = list(map(int,input().split()))
count = 0
tmp = 0
while(1):
    if a[0] == 1:
        tmp = a[0]
        break
    else:
        count += 1
        a.pop(0)
        if not a:
            break
if tmp == 1:
    for i in range(1,N-count):
        if a[i] == tmp + 1:
            tmp = a[i]
        else:
            count += 1
    print(count)
else:
    print(-1)


### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
b = 1
ans = 0
for i in range(0,N):
    if a[i] == b:
        b += 1
        ans += 1
if ans == 0:
    print(-1)
else:
    print(N-ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
bans = []
last = 0
for bi in range(n):
  bnow = b[bi]
  for ci in range(last,n):
    if c[ci] > bnow:
      bans.append([bnow,n-ci])
      last = ci
      break
  else:
    bans.append([bnow,0])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
last = 0
for ai in range(n):
  anow = a[ai]
  for bi in range(last,n):
    if bans[bi][0] > anow:
      ans += bans[bi][2]
      last = bi
      break
#print(bans)
print(ans)

### FIXED CODE ###

#解説より二分探索
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
bans = []
for bi in range(n):
  bnow = b[bi]
  here = bisect.bisect_right(c,bnow)
  bans.append([bnow,n-here])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
for ai in range(n):
  anow = a[ai]
  here = bisect.bisect_right(b,anow)
  if here != n:
    ans += bans[here][2]
#print(bans)
print(ans)
### BUGGY CODE ###

import numpy as np
import sys
read = sys.stdin.read
 

D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS
 
last = np.zeros((26, ))


def getContestType_at_d(d, k):
    s = -10000000
    for i in range(26):
        mask = np.ones((26, ))
        mask[i] = 0
        score = S[d][i] - np.sum(C * (d + 1 - last) * mask)
        score -= np.sum(C * (min(365, d + k) + 1 - last))
        if s < score:
            s = score
            t = i
 
    last[t] = d + 1
 
    return t + 1, s

max_score = -1
for k in range(26):
    score = 0
    ans = []
    for d in range(D):
        t, s = getContestType_at_d(d, k)
        ans.append(t)
        #ans.append(getContestType_at_d(d, k))
        score += s
    #print('score:', score)
    score = min(0, score)
    if max_score < score:
        max_score = score
        ANS = ans
    

print('\n'.join(map(str, ANS)))

### FIXED CODE ###

import numpy as np
import sys
read = sys.stdin.read


D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS

last = np.zeros((26, ))
ans = []

def getContestType_at_d(d):
    s = -10000000
    for i in range(26):
        tmp = S[d][i] - np.sum(C * (d - last)) + C[i] * (d - last[i])
        if s < tmp:
            s = tmp
            t = i

    last[t] += 1

    return t + 1


for d in range(D):
    ans.append(getContestType_at_d(d))


print('\n'.join(map(str, ans)))