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

MAXN=5000
def deleteBlocks():
    i=MAXN-1
    while i>=0 and set(L[i])!=set([False]):
        if set(L[i])==set([True]):
            del L[i]
            L.insert(0,[False]*5)
        else:
            i-=1

def setBlocks(d,lng,pos):
    if d==1:
        for i in range(MAXN):
            if set(L[i][pos:pos+lng])!=set([False]):
                L[i-1][pos:pos+lng]=[True]*lng
                break
        else:
            L[i][pos:pos+lng]=[True]*lng
    elif d==2:
        for i in range(MAXN):
            if L[i][pos]:
                for j in range(i-lng,i):
                    L[j][pos]=True
                break
        else:
            for j in range(i-lng+1,i+1):
                L[j][pos]=True
    deleteBlocks()

while True:
    n=input()
    if n==0:break
    L=[[False]*5 for i in range(MAXN)]
    for i in range(n):
        d,p,q=map(int,raw_input().split())
        setBlocks(d,p,q-1)
    cnt,i=0,MAXN-1
    while i>=0 and set(L[i])!=set([False]):
        cnt+=sum(L[i])
        i-=1
    print cnt

### FIXED CODE ###

MAXN=5000
def setBlocks(d,lng,pos):
    if d==1:
        for i in range(MAXN):
            if set(L[i][pos:pos+lng])!=set([False]):
                L[i-1][pos:pos+lng]=[True]*lng
                if set(L[i-1])==set([True]):
                    del L[i-1]
                    L.insert(0,[False]*5)
                break
        else:
            L[i][pos:pos+lng]=[True]*lng
            if set(L[i])==set([True]):
                del L[i]
                L.insert(0,[False]*5)
    elif d==2:
        for i in range(MAXN):
            if L[i][pos]:
                for j in range(i-lng,i):
                    L[j][pos]=True
                for j in range(i-lng,i):
                    if set(L[j])==set([True]):
                        del L[j]
                        L.insert(0,[False]*5)
                break
        else:
            for j in range(i-lng+1,i+1):
                L[j][pos]=True
            for j in range(i-lng+1,i+1):
                if set(L[j])==set([True]):
                    del L[j]
                    L.insert(0,[False]*5)

while True:
    n=input()
    if n==0:break
    L=[[False]*5 for i in range(MAXN)]
    for i in range(n):
        d,p,q=map(int,raw_input().split())
        setBlocks(d,p,q-1)
    print sum(sum(i) for i in L)
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
l = []
for i in range(min(A),max(A)+1):
  cnt = 0
  for a in A:
    if i == a or i == a-1 or i == a+1:
      cnt += 1
  l.append(cnt)
print(max(l))
  

### FIXED CODE ###

n = int(input())
cnt = [0] * 100002
a = list(map(int, input().split()))
for v in a:
    cnt[v] += 1
    cnt[v+1] += 1
    cnt[v+2] += 1
    
print(max(cnt))
### BUGGY CODE ###

N,M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = int(1e9+7)
"""
dp[i][j] : S の i 文字目までと T の j 文字目までを考慮し、
この 2 文字 (S[i] と T[j]）をペアにするときの場合の数とすると、

dp[i][j] = (sum(dp[1:i-1][1:j-1]) + 1 if S[i] == T[j] else 0)

2-D cumsumをつかう
i,j = 0のときにきをつけて
DS[i][j] = DS[i-1][j] + DS[i][j-1] - DS[i-1][j-1] + dp[i][j]
"""

dp = [[ 0 for _ in range(M)] for _ in range(N)]
DS = [[ 0 for _ in range(M+1)] for _ in range(N+1)]
dp[0][0] = 0
#dp[0] = [ 1 ] * (M+1)
#for i in range(N+1):
#  dp[i][0] = 1

  
for i in range(N):
  for j in range(M):
    #dp[i][j] = (sum(dp[:i-1][:j-1]) + 1 if S[i-1] == T[j-1] else 0)
    if S[i] != T[j]:
      continue
    dp[i][j] += 1
    for k in range(i):
      for l in range(j):
        #if i==k and j==l:
          #continue
        dp[i][j] += dp[k][l]
    #ii = i+1 if i>0 else 0
    #jj = j+1 if j>0 else 0
    #Sumpart = DS[ii][j] + DS[i][jj] - DS[ii][jj] + dp[ii][jj]
    #dp[i][j] += (Sumpart + 1 if S[i] == T[j] else 0)
    #DS[i][j] = DS[i][j-1] + dp[i][j]
    
ans = 1 # 何も選ばない
for p in dp:
  ans += sum(p)
  ans %= mod
print(ans)


### FIXED CODE ###

# numpyでかいてもTLEした。
# pypyでlistでかくととおる？

#import numpy as np
N,M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = int(1e9+7)
"""
dp[i][j] : S の i 文字目までと T の j 文字目までを考慮し、
この 2 文字 (S[i] と T[j]）をペアにするときの場合の数とすると、

dp[i][j] = (sum(dp[1:i-1][1:j-1]) + 1 if S[i] == T[j] else 0)
このsumの部分をどうもとめるか。

最終的な答えはsum(dp[:][:])。

2-D cumsumをつかう
i,j = 0のときにきをつけて
DS[i][j] = DS[i-1][j] + DS[i][j-1] - DS[i-1][j-1] + dp[i][j]
"""

dp = [[ 0 for _ in range(M)] for _ in range(N)]
DS = [[ 0 for _ in range(M+1)] for _ in range(N+1)]

for i in range(N):
  for j in range(M):
    if S[i] != T[j]:
      dp[i][j] = 0
    else:
      dp[i][j] += 1
      dp[i][j] += DS[i-1][j-1]
      dp[i][j] %= mod
    DS[i][j] = DS[i-1][j] + DS[i][j-1] - DS[i-1][j-1] + dp[i][j]
    DS[i][j] %= mod
print(DS[-2][-2]+1)
#print(dp)
#print(DS)
### BUGGY CODE ###

# D - Triangles
import itertools


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

ans=0

l=list(itertools.combinations(Li,3))
for i in range(len(l)):
    a=l[i][0]
    b=l[i][1]
    c=l[i][2]
    if a<b+c and b<c+a and c<a+b:
        ans+=1
    else:
        pass

print(ans)


### FIXED CODE ###

# D - Triangles
import bisect

N=int(input())
Li=list(map(int,input().split()))
Li.sort()

ans=0

for i in range(N):
    for j in range (i+1,N):
        a=Li[i]+Li[j]
        t=bisect.bisect_left(Li,a)
        ans+=t-(j+1)

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

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

B=[0]*N

for i in range(N):
    B[i]=A.count(i+1)

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

### FIXED CODE ###

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

B=[0]*N

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

for i in range(N):
    print(B[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]

b = [a[0]]
b_min = a[0]
for i in range(1, n):
    if a[i] > b_min:
        x = -1
        for j in range(len(b)):
            if b[j] < a[i]:
                if x == -1 or b[j] > b[x]:
                    x = j

        if x == -1:
            b.append(a[i])
        else:
            b[x] = a[i]
    else:
        b.append(a[i])
        b_min = min(b_min, a[i])

print(len(b))


### FIXED CODE ###

from bisect import bisect_left, bisect_right
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]

dq = deque([a[0]])
for i in range(1, n):
    idx = bisect_left(dq, a[i])
    if idx == 0:
        dq.appendleft(a[i])
    else:
        dq[idx-1] = a[i]

print(len(dq))
### BUGGY CODE ###

n = int(input())
s = input()
mod = 10**9+7

dp = [[0] * (n+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for j in range(n):
        if(j==0):
            dp[i+1][0] += dp[i][0]
            dp[i+1][0] %= mod
            dp[i+1][1] += dp[i][0]*2
            dp[i+1][1] %= mod
        else:
            dp[i+1][j-1] += dp[i][j]
            dp[i+1][j-1] %= mod
            dp[i+1][j+1] += dp[i][j]*2
            dp[i+1][j+1] %= mod

ans = dp[-1][len(s)] * pow(pow(2,mod-2,mod),len(s),mod)
ans %= mod
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
mod = 10**9+7

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

for i in range(n):
    next = [0] * (n+1)
    for j in range(n):
        if(j==0):
            next[0] += dp[0]
            next[0] %= mod
            next[1] += dp[0]*2
            next[1] %= mod
        else:
            next[j-1] += dp[j]
            next[j-1] %= mod
            next[j+1] += dp[j]*2
            next[j+1] %= mod
    dp = next[::]

ans = dp[len(s)] * pow(pow(2,mod-2,mod),len(s),mod)
ans %= mod
print(ans)
### BUGGY CODE ###

n=int(input())
p=list( float(s) for s in input().split() )

res=[1-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    for j in range(len(res)-1, 0, -1):
        res[j]=(res[j]*(1-p[i]) + (res[j-1]*p[i]) )
    res[0]=res[0]*(1-p[i])
print( (1-sum(res[:1+n//2])) )

### FIXED CODE ###

n=int(input())
p=list( float(s) for s in input().split() )
 
res=[1-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    for j in range(len(res)-1, 0, -1):
        res[j]=(res[j]*(1-p[i]) + (res[j-1]*p[i]) )
    res[0]=res[0]*(1-p[i])
print( (1-sum(res[:1+n//2])) )
### BUGGY CODE ###

from collections import deque

S = list(input())
s = deque(S)
q = int(input())
Q = [list(input().split()) for _ in range(q)]

rev = 0
for i in range(q):
    if len(Q[i]) == 1:
        rev += 1
        rev %= 2
    elif rev == 0:
        if Q[i][1] == "1":
            s.appendleft(Q[i][2])
        else:
            s.append(Q[i][2])
    else:
        if Q[i][1] == "2":
            s.appendleft(Q[i][2])
        else:
            s.append(Q[i][2])

if rev == 0:
    for i in range(len(s)):
        print(s[i],end="")
else:
    for i in reversed(range(len(s))):
        print(s[i],end="")
print()


### FIXED CODE ###

from collections import deque

S = list(input())
s = deque(S)
q = int(input())
Q = [list(input().split()) for _ in range(q)]

rev = 0
for i in range(q):
    if len(Q[i]) == 1:
        rev += 1
        rev %= 2
    else:
        if rev == 0:
            if Q[i][1] == "1":
                s.appendleft(Q[i][2])
            else:
                s.append(Q[i][2])
        else:
            if Q[i][1] == "2":
                s.appendleft(Q[i][2])
            else:
                s.append(Q[i][2])

s = list(s)
if rev == 0:
    for i in range(len(s)):
        print(s[i],end="")
else:
    for i in reversed(range(len(s))):
        print(s[i],end="")
print()
### BUGGY CODE ###

def main():
    n,k=map(int,input().split(' '))
    h=list(map(int,input().split(' ')))
    dp = [float('inf') for i in range(n)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(n):
        for j in range(i,min(i+k+1,n)):
            if dp[j] > dp[i]+abs(h[i]-h[j]):
                dp[j] = dp[i]+abs(h[i]-h[j])
    print(dp[-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n,k=map(int,input().split(' '))
    h=list(map(int,input().split(' ')))
    dp = [float('inf') for i in range(n)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(n):
        for j in range(i,min(i+k+1,n)):
            if dp[j] > dp[i]+abs(h[i]-h[j]):
                dp[j] = dp[i]+abs(h[i]-h[j])
    print(dp[-1])


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

import collections,math,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ans = 1
def prime_factor(num):
    prime_factor = collections.defaultdict(int)
    for i in range(2,int(num**0.5)+1):
        while num%i==0:
            prime_factor[i] += 1
            num //= i
    if num>1:
        prime_factor[num]=1
    return prime_factor
for v in prime_factor(M).values():
    ans *= math.factorial(v+N-1)//math.factorial(v)//math.factorial(N-1)
    ans %= 10**9+7
print(ans)

### FIXED CODE ###

import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ans = 1
def prime_factor(num):
    prime_factor = collections.defaultdict(int)
    for i in range(2,int(num**0.5)+1):
        while num%i==0:
            prime_factor[i] += 1
            num //= i
    if num>1:
        prime_factor[num]=1
    return prime_factor
def nCr(n,r,mod):
    comb_count = 1
    for i in range(r):
        comb_count *= n-i
        comb_count %= mod
    for j in range(1,r+1):
        comb_count *= pow(j,mod-2,mod)
        comb_count %= mod
    return comb_count
for v in prime_factor(M).values():
    ans *= nCr(v+N-1,v,10**9+7)
    ans %= 10**9+7
print(ans)
### BUGGY CODE ###

N = int(input())
S = []
for x in range(N):
    S.append(input())
maxi = max([S.count(x) for x in S])
P = sorted(set([x for x in S if S.count(x) == maxi]))
for x in P:
    print(x)

### FIXED CODE ###

from collections import defaultdict

N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k] += 1
    else:
        ans.update({k: 1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)
### BUGGY CODE ###

import numpy as np


def solve(s):
    MOD = 10 ** 9 + 7
    dp = np.zeros(13, dtype=np.int64)
    dp[0] = 1
    idx = np.zeros(13, dtype=np.int8)
    for i in range(13):
        idx[i * 10 % 13] = i
    window = np.ones(10, dtype=np.int8)
    for c in s:
        if c == '?':
            dp = np.convolve(dp[idx], window) % MOD
            dp[:9] += dp[13:]
            dp = dp[:13] % MOD
        else:
            dp = np.roll(dp[idx], int(c))
    return dp[5]


s = input()
print(solve(s))


### FIXED CODE ###

import numpy as np


def solve(s):
    MOD = 10 ** 9 + 7
    dp = np.zeros(13, dtype=np.int64)
    dp[0] = 1
    idx = np.zeros(13, dtype=np.int8)
    for i in range(13):
        idx[i * 10 % 13] = i
    window = np.ones(10, dtype=np.int8)
    for c in s:
        if c == '?':
            tdp = dp[idx]
            ndp = np.concatenate([tdp[4:], tdp])
            dp = np.convolve(ndp, window, mode='valid') % MOD
        else:
            dp = np.roll(dp[idx], int(c))
    return dp[5]


s = input()
print(solve(s))
### BUGGY CODE ###

S=input()
Q=int(input())
for i in range(Q):
    query=input()
    if(query=="1"):
        S=S[::-1]
    else:
        query, F, C =query.split()
        S=C+S if(F=="1") else S+C
print(S)

### FIXED CODE ###

S=input()
Q=int(input())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
print((forward+S+back)[::1 if(fb) else -1])
### BUGGY CODE ###

N = int(input())
array = list(map(int, input().split()))
for i in range(0, N):
    konichiwa = list(array)
    konichiwa.pop(i)
    konichiwa.sort()
    print(konichiwa[int(N / 2) - 1])


### FIXED CODE ###

N = int(input())
array = list(map(int, input().split()))
test = list(array)
test.sort()
wow = test[int(N / 2) - 1: int(N / 2) + 1]
for i in range(0, N):
    if array[i] > wow[0]:
        print(wow[0])
    else:
        print(wow[1])
### BUGGY CODE ###

n = int(input())
arr = list(map(int, input().split()))
s = 0
m = 1000000007
for i in range(len(arr)):
    for j in range(i+1, len(arr)):
        s = (s+(arr[i]*arr[j])%m)%m
print(s)
        


### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
sq_s = 0
for i in range(len(arr)):
    sq_s += arr[i]*arr[i]
m = 1000000007
print(((s**2 - sq_s)//2)%m)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
def main():
    N, W = map(int, input().split())
    V = 10**3 * 100
    
    dp = [[float("inf")]*(V) for _ in range(N+1)]
    dp[0][0] = 0
    
    for i in range(1, N+1):
        w, v = map(int, input().split())
        for j in range(V):
            if j-v >= 0:
                dp[i][j] = min(dp[i][j], dp[i-1][j-v]+w)
            dp[i][j] = min(dp[i][j], dp[i-1][j])
        
    ans = 0
    for i in range(len(dp[N])):
        if dp[N][i] > W:
            continue
        if i >= ans:
            ans = i
            
    # print(dp)
    print(ans)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
N, W = map(int, input().split())
 
items = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0
 
for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)
 
print(np.max(np.where(dp <= W)))
### BUGGY CODE ###

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

if n%k==0:
    print(0)
    exit()

while abs(n-k)<n:
    n=abs(n-k)

print(n)

### FIXED CODE ###

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

print(min(n%k,abs(n%k-k)))
### BUGGY CODE ###

# -*- coding:utf-8 -*-
import sys
nyuryoku = [int(i) for i in sys.stdin]

N = nyuryoku[0]
a_list = nyuryoku[1:]

"""
a_list=[]

for _ in range(N):
    a_list.append(int(input()))
"""


cnt_push = 1
button_list = []
cur_but_posi = a_list[0]

while True:
    #cur_but_posi = a_list[cur_but_posi - 1]
    if cur_but_posi == 2:
        print(cnt_push)
        break
    elif cur_but_posi in button_list:
        print(-1)
        break
    else:
        button_list.append(cur_but_posi)
        cur_but_posi = a_list[cur_but_posi - 1]    
        cnt_push += 1    



### FIXED CODE ###

import sys

l = [int(i) - 1 for i in sys.stdin]

N = l[0] + 1

a = l[1:]

done = [False] * N

i = 0

ans = 0

while True:
    if done[i] == False:
        done[i] = True
        ans += 1
        if a[i] == 1:
            break
        i = a[i]
    else:
        ans = -1
        break

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

#「辺」彩色
#最大次数で可
#構成はset()使って色管理
n = int(input())
Ad = [set() for i in range(n)]
Deg = [0]*n
E = []
for i in range(n-1):
    ai,bi = map(int, input().split( ))
    ai-=1
    bi-=1
    Ad[ai].add(bi)
    Ad[bi].add(ai)
    Deg[ai]+=1
    Deg[bi]+=1
    E.append((ai,bi))

cl = max(Deg)
Deg2 = [set(range(cl)) for i in range(n)]
print(cl)
for ai,bi in E:
    c = 0
    while c  not in Deg2[ai] or c not in Deg2[bi]:
        c+=1
    print(c+1)
    Deg2[ai].remove(c)
    Deg2[bi].remove(c)
    


### FIXED CODE ###


n = int(input())
Ad = [[] for _ in range(n)]
Deg = [0]*n
E = {}
E2 =[]
for i in range(n-1):
    ai,bi = map(int, input().split( ))
    ai-=1
    bi-=1
    Ad[ai].append(bi)
    Ad[bi].append(ai)
    Deg[ai] += 1
    Deg[bi] += 1
    E[(ai,bi)]=-1
    E[(bi,ai)]=-1
    E2.append((ai,bi))
mx = max(Deg)
print(mx)
E[(0,0)] = -1#後の都合
P =[-1]*n#parent
from collections import deque
Q = deque()
Q.append(0)
P[0] = 0

while Q:
    v = Q.popleft()
    for u in Ad[v]:
        if P[u]<0:
            P[u] = v
            Q.append(u)

Q = deque()
cnt = 1
for v in Ad[0]:
    E[(0,v)]=cnt
    E[(v,0)]=cnt
    cnt+=1
    Q.append(v)

while Q:
    v = Q.popleft()
    cnt = 1
    for u in Ad[v]:
        if E[(u,v)]<0:
            if cnt==E[(v,P[v])]:
                cnt +=1
            E[(u,v)] = cnt
            E[(v,u)] = cnt
            cnt+=1
            Q.append(u)
for i in range(n-1):
    print(E[E2[i]])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7
S=S[::-1]

dp=defaultdict(lambda: 0)

for i,x in enumerate(S):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[(i,(x*pow(10,i,13))%13)]=1
        else:
            for x in range(10):
                dp[(i,(x*pow(10,i,13))%13)]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*pow(10,i,13)+j)%13
                dp[(i,n)]+=dp[(i-1,j)]
                dp[(i,n)]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*pow(10,i,13)+j)%13
                    dp[(i,n)]+=dp[(i-1,j)]%mod
                    dp[(i,n)]%=mod
print dp[(N-1,5)]%mod


### FIXED CODE ###

S=raw_input()
S=S[::-1]
l=len(S)

dp=[ 0 for j in range(13) ]
dp[0]=1

mod=10**9+7

dp2=[ 0 for _ in range(13) ]

keta=1

for i in range(1,l+1):
	dp2=[0]*13
	for j in range(13):
		if dp[j]!=0:
			if S[i-1]=="?":
				for k in range(10):
					next=(k*keta+j)%13 
					dp2[next]+=dp[j]
					dp2[next]%=mod
			else:
				k=int(S[i-1])
				next=(k*keta+j)%13
				dp2[next]+=dp[j]
				dp2[next]%=mod

	dp=dp2
	keta=(keta*10)%13

print dp[5]
### BUGGY CODE ###

N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    X = A[i]
    A[i] = 0
    print(max(A))
    A[i] = X

  

### FIXED CODE ###

N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
am = sorted(A,reverse = True)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    print(am[1])
### BUGGY CODE ###

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

mod = 10**9+7
s = readline().rstrip().decode('utf-8')

dp = [0]*13 #あまりが0~12の13通りとなる場合の数
dp[0] = 1
dig = 1 #今見てる桁数
for i in range(len(s)-1,-1,-1): #小さい方の桁から見ていく
    c = s[i]
    next_dp = [0]*13 #逐次更新してはいけないので、次の桁の数についてjを回して入れていく
    if c == "?": #?なら0~10の10通り全てについてあたる必要がある
        for d in range(10):
            for j in range(13):
                next_dp[(d*dig + j)%13] += dp[j]
                next_dp[(d*dig + j)%13] %= mod

    
    else:
        d = int(c)
        for j in range(13):
            next_dp[(d*dig + j)%13] += dp[j]
            next_dp[(d*dig + j)%13] %= mod


    dig *= 10
    dp = next_dp

print(dp[5]%mod)

### FIXED CODE ###

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

mod = 10**9+7
s = readline().rstrip().decode('utf-8')

dp = [0]*13 #あまりが0~12の13通りとなる場合の数
dp[0] = 1
dig = 1 #今見てる桁数
for i in range(len(s)-1,-1,-1): #小さい方の桁から見ていく
    c = s[i]
    next_dp = [0]*13 #逐次更新してはいけないので、次の桁の数についてjを回して入れていく
    if c == "?": #?なら0~10の10通り全てについてあたる必要がある
        for d in range(10):
            for j in range(13):
                next_dp[(d*dig + j)%13] += dp[j]
                next_dp[(d*dig + j)%13] %= mod

    
    else:
        d = int(c)
        for j in range(13):
            next_dp[(d*dig + j)%13] += dp[j]
            next_dp[(d*dig + j)%13] %= mod


    dig *= 10
    dig %= 13
    dp = next_dp

print(dp[5]%mod)
### BUGGY CODE ###

def main():
    import os
    import sys
    from io import BytesIO, IOBase
    
    BUFSIZE = 8192
    
    
    class FastIO(IOBase):
        newlines = 0
    
        def __init__(self, file):
            self._fd = file.fileno()
            self.buffer = BytesIO()
            self.writable = "x" in file.mode or "r" not in file.mode
            self.write = self.buffer.write if self.writable else None
    
        def read(self):
            while True:
                b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
                if not b:
                    break
                ptr = self.buffer.tell()
                self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
            self.newlines = 0
            return self.buffer.read()
    
        def readline(self):
            while self.newlines == 0:
                b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
                self.newlines = b.count(b"\n") + (not b)
                ptr = self.buffer.tell()
                self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
            self.newlines -= 1
            return self.buffer.readline()
    
        def flush(self):
            if self.writable:
                os.write(self._fd, self.buffer.getvalue())
                self.buffer.truncate(0), self.buffer.seek(0)
    
    
    class IOWrapper(IOBase):
        def __init__(self, file):
            self.buffer = FastIO(file)
            self.flush = self.buffer.flush
            self.writable = self.buffer.writable
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")
    
    
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
    mod = 10**9 + 7
    n = int(input())
    a = [int(x) for x in input().split()]
    a_set = set(a)
    #約数の列挙
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)

        divisors.sort()
        return divisors
    from collections import Counter
    c = Counter(a)
    cnt = 0
    for i in a:
        prime = make_divisors(i)
        flag = 1
        if c[i] > 1:
            continue
        for j in prime:
            if j == i:
                continue
            if j in a_set:
                flag = 0
                break
        if flag:
            cnt += 1
    print(cnt)
main()


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
max_a = a[-1]
is_True = [1]*(max_a + 1)
for i in a:
    if is_True[i]:
        for j in range(2*i, max_a + 1, i):
            is_True[j] = False
cnt = 0
from collections import Counter
c = Counter(a)
for i in a:
    if is_True[i] and c[i] == 1:
        cnt += 1
print(cnt)