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

import sys

input = sys.stdin.readline

n = int(input())

e = [[] for _ in range(n)]
for i in range(n):
    a = map(int, input().split())
    for aa in a:
        aa -= 1
        e[i].append((i, aa))

inds = [0] * n
st = set(e[i][0] for i in range(n))
cnt = 0
while st:
    flg = False
    nst = set()
    for tpl in st.copy():
        x, y = tpl
        if x > y: continue
        if (y, x) in st:
            # print(st, x, y, inds)
            flg = True
            inds[x] += 1
            inds[y] += 1
            st.discard(tpl)
            st.discard((y, x))
            if inds[x] < n - 1:
                nst.add(e[x][inds[x]])
            if inds[y] < n - 1:
                nst.add(e[y][inds[y]])
            # print(nst)
    # print(st, nst, inds, flg)
    if not flg:
        print(-1)
        exit()

    cnt += 1
    st.update(nst)
print(cnt)


### FIXED CODE ###

def check(player):
    if not a[player]:
        return
    opponent = a[player][-1]
    if not a[opponent]:
        return
    if a[opponent][-1] == player:
        tpl = (player, opponent)
        q.add((min(tpl), max(tpl)))


n = int(input())

a = []
for _ in range(n):
    t = list(map(lambda x: int(x) - 1, input().split()))
    t.reverse()
    a.append(t)

q = set()
for i in range(n):
    check(i)

day = 0
while q:
    day += 1
    prev_q = set()
    q, prev_q = prev_q, q
    for player, opponent in prev_q:
        a[player].pop()
        a[opponent].pop()
    for player, opponent in prev_q:
        check(player)
        check(opponent)

if any(a[player] for player in range(n)):
    print(-1)
    exit()

print(day)
### BUGGY CODE ###

from collections import Counter
import bisect

N = int(input())
cnt_A = Counter(map(int, input().split()))
keys = sorted(cnt_A.keys())
max_keys = max(keys)
flags = {key: True for key in keys}

for key in keys:
    if flags[key] is False:
        continue

    factor = 2
    while key * factor <= max_keys:
        idx = bisect.bisect(keys, key * factor)
        if keys[max(0, idx - 1)] == key * factor:
            del cnt_A[key * factor]
            flags[key * factor] = False
        factor += 1

print(sum([val if val == 1 else 0 for val in cnt_A.values()]))



### FIXED CODE ###

from collections import Counter
import bisect

N = int(input())
cnt_A = Counter(map(int, input().split()))
keys = sorted(cnt_A.keys())
max_keys = max(keys)
flags = {key: True for key in keys}

for key in keys:
    if flags[key] is False:
        continue

    factor = 2
    while key * factor <= max_keys:
        idx = bisect.bisect(keys, key * factor)
        if keys[max(0, idx - 1)] == key * factor:
            del cnt_A[key * factor]
            flags[key * factor] = False
        factor += 1

print(sum([val if val == 1 else 0 for val in cnt_A.values()]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7) #再帰回数の上限を変更
from collections import deque
N,M=map(int,input().split())
G=[[]for _ in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

dist=[10**9 for _ in range(N)]
chk=[0 for _ in range(N)]
dist[0]=0
prev=[-1 for _ in range(N)]


que=deque()
que.append((0,-1))

while(len(que)):
    v,p=que.popleft()
    if p==-1:
        pass
    else:
        val=dist[p]+1
        if val<dist[v]:
            dist[v]=val
            prev[v]=p
    chk[v]=1
    for tmp in G[v]:
        if tmp==p:
            continue
        if chk[tmp]==1:
            continue
        que.append((tmp,v))

print("Yes")
#print(dist)
for i in range(N):
    if i==0:
        continue
    print(prev[i]+1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7) #再帰回数の上限を変更
from collections import deque
N,M=map(int,input().split())
G=[[]for _ in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

dist=[-1 for _ in range(N)]
chk=[0 for _ in range(N)]
dist[0]=0
prev=[-1 for _ in range(N)]


que=deque()
que.append((0,-1))

while(len(que)):
    v,p=que.popleft()
    for tmp in G[v]:
        if dist[tmp]!=-1:
            continue
        dist[tmp]=dist[v]+1
        prev[tmp]=v
        que.append((tmp,v))

print("Yes")
#print(dist)
for i in range(N):
    if i==0:
        continue
    print(prev[i]+1)
### BUGGY CODE ###

from heapq import heappop, heappush

import sys
def input():return sys.stdin.readline().strip()

def main():
    N, M, S = map(int, input().split())
    to = [{} for _  in range(N)]
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        to[u][v] = (a, b)
        to[v][u] = (a, b)
    info = tuple(tuple(map(int, input().split())) for _ in range(N))

    MAX_SILVER = 50 * (N-1)
    INF = 10 ** 18
    # dijkstra (time, vertex, money)
    visited = [[False]*(MAX_SILVER+1) for _ in range(N)]
    cost = [[INF]*(MAX_SILVER+1) for _ in range(N)]
    q = []
    S = min(S, MAX_SILVER)
    heappush(q, (0, 0, S)) # (time, vertex, silver)

    while q:
        t, now, s = heappop(q)
        if visited[now][s]:continue
        visited[now][s] = True
        cost[now][s] = t

        # next node
        for nv, (a, b) in to[now].items():
            nt = t + b
            rest = s - a
            if rest >= 0:
                if cost[nv][rest] <= nt : continue 
                heappush(q, (nt, nv, rest))
        
        # exchange gold with silver
        rate, time = info[now]
        for i, ns in enumerate(range(s + rate, MAX_SILVER, rate), 1):
            nt = t + time * i
            if cost[nv][ns] <= nt : continue
            heappush(q, (nt, now, ns))
    
    for i in range(1, N):
        print(min(cost[i]))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from heapq import heappop, heappush

import sys
def input():return sys.stdin.readline().strip()

def main():
    N, M, S = map(int, input().split())
    to = [{} for _  in range(N)]
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        to[u][v] = (a, b)
        to[v][u] = (a, b)
    info = tuple(tuple(map(int, input().split())) for _ in range(N))

    MAX_SILVER = 50 * (N-1)
    INF = 10 ** 18
    # dijkstra (time, vertex, money)
    visited = [[False]*(MAX_SILVER+1) for _ in range(N)]
    cost = [[INF]*(MAX_SILVER+1) for _ in range(N)]
    q = []
    S = min(S, MAX_SILVER)
    heappush(q, (0, 0, S)) # (time, vertex, silver)

    while q:
        t, now, s = heappop(q)
        if visited[now][s]:continue
        visited[now][s] = True
        cost[now][s] = t

        # next node
        for nv, (a, b) in to[now].items():
            nt = t + b
            rest = s - a
            if rest >= 0:
                if cost[nv][rest] <= nt : continue 
                heappush(q, (nt, nv, rest))
        
        # exchange gold with silver
        rate, time = info[now]
        nt = t + time
        ns = min(s+rate, MAX_SILVER)
        heappush(q, (nt, now, ns))
        
    
    for i in range(1, N):
        print(min(cost[i]))

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

#   C

import numpy as np

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

sum_poss = 0
for n in range(1, N+1):
    m = 0
    poss = 1
    while n*2**m < K:
        m *= 2
        poss /= 2
    sum_poss += poss/N
    
#sum_poss /= N


print(sum_poss)

### FIXED CODE ###

#   C

import numpy as np

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

sum_poss = 0
for n in range(1, N+1):
    m0 = 0
    if n >= K:
        m0 = 0
    else:
        m0 = int(np.log2(K/n))
        if np.log2(K/n) - int(np.log2(K/n)) != 0:
            m0 += 1
#    print(m0, 1/(2**m0))
    sum_poss += 1/((2**m0)*N)
    
#sum_poss /= N


print(sum_poss)
### BUGGY CODE ###

N, Q = map(int, input().split())
s = input()

golems = [1 for _ in range(N)]

index_table = {}
for i, c in enumerate(s):
    if c in index_table:
        index_table[c].append(i)
    else:
        index_table[c] = [i]

for i in range(Q):
    t_i, d_i = input().split()
    if t_i not in index_table:
        continue
    indexes = index_table[t_i]
    if indexes is not None and len(indexes) > 0:
        for index in indexes:
            golem_num = golems[index]
            golems[index] = 0
            if d_i == 'L' and index != 0:
                golems[index - 1] += golem_num
            elif d_i == 'R' and index != N - 1:
                golems[index + 1] += golem_num

count = 0
for i, g in enumerate(golems):
    count += g

print(count)

### FIXED CODE ###

N, Q = map(int, input().split())
s = input()

t = []
d = []
for i in range(Q):
    t_i, d_i = input().split()
    t.append(t_i)
    d.append(d_i)


def calc_group(n):
    for i in range(Q):
        if s[n] == t[i]:
            if d[i] == 'L':
                n -= 1
                if n == -1:
                    return -1
            elif d[i] == 'R':
                n += 1
                if n == N:
                    return 1
    return 0


l = -1
r = N
n = (l + r) // 2
while l != n:
    if calc_group(n) == -1:
        l = n
    else:
        r = n
    n = (l + r) // 2
l_max = l

l = -1
r = N
n = (l + r) // 2
while l != n:
    if calc_group(n) == 1:
        r = n
    else:
        l = n
    n = (l + r) // 2
r_min = r

if r_min == l_max:
    count = 0
else:
    count = r_min - l_max - 1
print(count)
### BUGGY CODE ###

n, m = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
ct = 0
for i in range(1, n + 1):
    high = H[i-1]
    flag = 0
    for j in range(m):
        if AB[j][0] == i:
            if H[AB[j][1] - 1] >= high:
                flag = 1
                break
        elif AB[j][1] == i:
            if H[AB[j][0] - 1] >= high:
                flag = 1
                break
    if flag == 0:
        ct += 1
print(ct)

### FIXED CODE ###

n, m = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
no = []
for i in AB:
    if H[i[0] - 1] > H[i[1] - 1]:
        no.append(i[1] - 1)
    elif H[i[0] - 1] < H[i[1] - 1]:
        no.append(i[0] - 1)
    else:
        no.append(i[1] - 1)
        no.append(i[0] - 1)
print(n - len(set(no)))
### BUGGY CODE ###

N = int(input())
# A[0]
A = [int(input())-1]
 
count = [-1]*N
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break
  
  if A[n]+1 > len(A):
    for _ in range(A[n]+1 - len(A)):
      A.append(int(input()) -1)
    continue
  
  n = A[n]
  if n in count:
    ans = -1
    break
  count[n] = n
  ans += 1
 
print(ans)

### FIXED CODE ###

n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)
### BUGGY CODE ###

A, B = map(int, input().split())

def cf(a, b):
    cf = [1]
    for i in range(2, min(a, b)+1):
        if a % i == 0 and b % i == 0:
            if (i == 2) or (i > 2 and i % 2 != 0):
                if i >= 5 and i % cf[-1] == 0:
                    pass
                else:
                    cf.append(i)
            else:
                pass
    return cf

cf_l = cf(A, B)

print(len(cf_l))

### FIXED CODE ###

def prime_factorize(n):
    pf = []
    while n % 2 == 0:
        pf.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            pf.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        pf.append(n)
    return pf

A, B = map(int, input().split())

prime_A = set(prime_factorize(A))
prime_B = set(prime_factorize(B))
ans = len(prime_A & prime_B) + 1

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

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
# 20億^2で10^18を超えるので19乗で
INF = 10 ** 19
MOD = 10 ** 9 + 7

N, K = MAP()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

ans = INF
# 4点組み合わせ全部試す
for i in range(N):
    x1, y1 = XY[i]
    for j in range(i, N):
        x2, y2 = XY[j]
        for k in range(j, N):
            x3, y3 = XY[k]
            for l in range(k, N):
                x4, y4 = XY[l]
                xl, xr = min(x1, x2, x3, x4), max(x1, x2, x3, x4)
                yl, yr = min(y1, y2, y3, y4), max(y1, y2, y3, y4)
                # 4点の内側にいくつ点があるか数える
                cnt = 0
                for x5, y5 in XY:
                    if xl <= x5 <= xr and yl <= y5 <= yr:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans, (xr-xl) * (yr-yl))
print(ans)


### FIXED CODE ###

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

"""
・座標圧縮
・2次元累積和
"""

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

X, Y = [0]*N, [0]*N
for i in range(N):
    X[i], Y[i] = map(int, input().split())

# 座標圧縮
zip_x, zip_y, unzip_x, unzip_y = {}, {}, {}, {}
X2 = sorted(set(X))
Y2 = sorted(set(Y))
# この後の処理のために添字は1-indexedにする
for i in range(len(X2)):
    zip_x[X2[i]] = i+1
    unzip_x[i+1] = X2[i]
for i in range(len(Y2)):
    zip_y[Y2[i]] = i+1
    unzip_y[i+1] = Y2[i]

# 圧縮した座標に点を割り当て(グリッドは累積和用に一回り大きく作る)
grid = [[0] * (len(X2)+1) for _ in range(len(Y2)+1)]
for i in range(N):
    grid[zip_y[Y[i]]][zip_x[X[i]]] += 1

# 2次元累積和
for i in range(len(Y2)+1):
    for j in range(1, len(X2)+1):
        grid[i][j] += grid[i][j-1]
for i in range(1, len(Y2)+1):
    for j in range(len(X2)+1):
        grid[i][j] += grid[i-1][j]

ans = float('inf')
for i in range(1, len(Y2)+1):
    for j in range(1, len(X2)+1):
        # 終点がK以上あれば始点を動かし始める
        if grid[i][j] >= K:
            for k in range(i):
                for l in range(j):
                    # 部分累積和を出して、点がK以上あるか確認
                    if grid[i][j] - grid[i][l] - grid[k][j] + grid[k][l] >= K:
                        # 長方形の面積を出して最小を保持
                        ans = min((unzip_x[j]-unzip_x[l+1]) * (unzip_y[i]-unzip_y[k+1]), ans)
print(ans)
### BUGGY CODE ###

import numpy as np

n, k = map(int, input().split())
h = np.array([int(i) for i in input().split()])

dp = np.array([float('inf')]*n)
dp[0] = 0

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

print(int(dp[-1]))

### FIXED CODE ###

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

# dp=[0 for i in range(N)]
dp = [float("inf")]*(N)
dp[0] = 0
dp[1] = abs(h[1] - h[0])


for i in range(N-1):
  for j in range(1, min(K+1, N - i)):
    dp[i+j]=min(dp[i+j], dp[i]+ abs(h[i+j]-h[i]))
print(dp[N-1])
### BUGGY CODE ###

# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit,jit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
from networkx import Graph,shortest_path,single_target_shortest_path,astar_path,single_source_dijkstra
G = Graph()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
rows = [list(map(int,input().split())) for _ in range(M)]

G.add_edges_from(rows)

# shortestPath = shortest_path(G,target=1)
# shortestPath = single_target_shortest_path(G,target=1)
shortestPathLength,shortestPath = single_source_dijkstra(G,source=1)
# print(shortestPath)
if len(shortestPathLength) != N:
    print("No")
    exit()

print("Yes")
for i in range(2,N+1):
    print(shortestPath[i][-2])


# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


### FIXED CODE ###

# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit,jit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
from networkx import Graph
from networkx.algorithms.traversal.breadth_first_search import bfs_predecessors
G = Graph()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
rows = [list(map(int,input().split())) for _ in range(M)]

G.add_edges_from(rows)

# shortestPath = shortest_path(G,target=1)
preds = bfs_predecessors(G,source=1)
# shortestPath = single_target_shortest_path(G,target=1)
# shortestPathLength,shortestPath = single_source_dijkstra(G,source=1)

preds = dict(preds)
if len(preds)+1 != N:
    print("No")
    exit()

print("Yes")
for i in range(2,N+1):
    print(preds[i])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# 18:01 -> 
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

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

A = []
first_black = []

for i in range(H):
    A.append(list(input()))
    first_black.extend([(i,j) for j in range(W) if A[i][j] == '#'])

black_deque = deque()
black_deque.extend(first_black)

max_depth = 0
while len(black_deque) != 0:
    x,y = black_deque.popleft()
    if A[x][y] == '#':
        depth = 0
    else:
        depth = A[x][y]
    max_depth = max(max_depth, depth)
    for k in range(4):
        new_x = x+dx[k]
        new_y = y+dy[k]
        if 0 <= new_x < H and \
           0 <= new_y < W and \
           A[new_x][new_y] == '.':
            black_deque.append((new_x, new_y))
            A[new_x][new_y] = depth+1
            
print(depth)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# 18:01 -> 18:36 (give up. TLE)
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

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

A = []
black_deque = deque()

for i in range(H):
    A.append(list(input()))
    black_deque.extend([(i,j) for j in range(W) if A[i][j] == '#'])

if len(black_deque) == H*W:
    print(0)
    exit(0)

for x,y in black_deque:
    A[x][y] = 0

while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    for k in range(4):
        new_x = x+dx[k]
        new_y = y+dy[k]
        if 0 <= new_x < H and \
           0 <= new_y < W and \
           A[new_x][new_y] == '.':
            black_deque.append((new_x, new_y))
            A[new_x][new_y] = depth+1

print(depth)
### BUGGY CODE ###

S=input()
ans=0
while ('10' in S) | ('01' in S):
	ans += S.count('10')
	S = S.replace('10','')
	ans += S.count('01')
	S = S.replace('01','')
print(2*ans)

### FIXED CODE ###

S=input()
num0 = S.count('0')
num1 = S.count('1')
ans = 2*min(num0,num1)
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
L, R = map(int, input().split())
end = min(R, L + 4038)

ans = 2018
for i in range(L, end+1):
    for j in range(i+1, end+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
L, R = map(int, input().split())
end = min(R, L + 637*2)

ans = 2018
for i in range(L, end+1):
    for j in range(i+1, end+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)
### BUGGY CODE ###

#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    lr=list(map(int,input().split()))
    lis.append(lr)
L=[0]*(li[0]-1)
for i in range(li[0]-1):
    if S[i:i+2]=="AC":
        L[i]+=1
for i in range(li[1]):
    ans=sum(L[lis[i][0]-1:lis[i][1]-1])
    print(ans)


### FIXED CODE ###

#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    #l_i r_i
    lr=list(map(int,input().split()))
    lis.append(lr)
L=[0]*(li[0])
for i in range(li[0]-1):
    L[i+1]+=L[i]
    if S[i:i+2]=="AC":
        L[i+1]+=1
for i in range(li[1]):
    print(L[lis[i][1]-1]-L[lis[i][0]-1])
### BUGGY CODE ###

N = int(input())
A = [input() for i in range(N)]
M = N * 10
T = [0 for i in range(M)]

def convert_str_to_int(s):
    if s == "A":
        return 1
    elif s == "C":
        return 2
    elif s == "G":
        return 3
    elif s == "T":
        return 4
    else:
        return 0

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

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

D = {}
for row in A:
    order, key = row.split()
    if order[0] == "i":
        D[key] = 1
    else:
        if key in D.keys():
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

N = int(input())
S = input()
# N桁のSからN-3桁の数字を削除して(N<30000)３桁の数字を残す．残った数字の組み合わせて押してありえるのは何通りか？
# 実際に10^4通りから３通り選ぶのは 10^4C3通りくらい計算量的には計算できる?
# 更にあり得る組み合わせの上限==1000通りを終えた時点で終了すれば更に早い？
# 右の数字から数えていって1を取れるかみたいにしていけば最大１０００のループで終わる？
# 0001がNの中から取れるかの判定まず最初の0について左側からとっていって，0があれば存在すればとり，そこのindexを記録，．次に1として次のindexから検索していく

#for n in N_str:
#なぜ224とかの時に上手く行かないのだ?
#0224
count=0
NUM = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
for i in NUM:
    i_3d = i
    index_num = 0
    for j,i_s in enumerate(i_3d): # 1,2
        for s_s in S[index_num:]: # 2
            index_num+= 1 #3
            if s_s == i_s: #2 == 2
                if j == len(i_3d)-1:  # 最後の文字がマッチングした
                    count+=1
                break
        # i_sについて探索しても何も見つからなかった場合,最後まで探索したとき，次のindexがあふれる時には停止する
        if index_num == len(S): # 3==4:False
            break
print(count)




### FIXED CODE ###

N = int(input())
S = input()
# N桁のSからN-3桁の数字を削除して(N<30000)３桁の数字を残す．残った数字の組み合わせて押してありえるのは何通りか？
# 実際に10^4通りから３通り選ぶのは 10^4C3通りくらい計算量的には計算できる?
# 更にあり得る組み合わせの上限==1000通りを終えた時点で終了すれば更に早い？
# 右の数字から数えていって1を取れるかみたいにしていけば最大１０００のループで終わる？
# 0001がNの中から取れるかの判定まず最初の0について左側からとっていって，0があれば存在すればとり，そこのindexを記録，．次に1として次のindexから検索していく

#for n in N_str:
#なぜ224とかの時に上手く行かないのだ?
#0224
count=0
NUM = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
for i in NUM:
    i_3d = i
    S_mid = S
    for j,i_s in enumerate(i_3d): # 1,2
        if i_s in S_mid: # S_mid中にi_sがそんざいしていたら
            ind = S_mid.index(i_s)
            if j == len(i_3d)-1:  # 最後の文字がマッチングした
                count+=1
                break # break はforとwhileを抜け出すのに使われる
            elif ind+1 == len(S): # 文字はマッチングしたが最後の文字ではなく次の探索ができない場合
                break
            S_mid = S_mid[ind+1:]
        else: # S_mid中に存在しない
            break
print(count)