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

tmp = int(input())
timing = [int(i) for i in input().split()]
ans = []
for i in range(0,tmp):
    #ans.append(timing.index(i+1)+1)
    print(timing.index(i+1)+1,end="")
    if i <tmp-1:
        print(" ",end="")

### FIXED CODE ###

tmp = int(input())
timing = [int(i) for i in input().split()]
num_dict = {}
for i  in range(0,tmp):
    num_dict[timing[i]] = i+1

for i in range (0,tmp):
    print(num_dict.pop(i+1),end="")
    if i <tmp-1:
        print(" ",end="")

#for i in range(0,tmp):
#    #ans.append(timing.index(i+1)+1)
#    print(timing.index(i+1)+1,end="")
#
### BUGGY CODE ###

s=input()
b=0
m=len(s)
c=0
for i in range(m-1,2,-1):
    a=s[i-2]+s[i-1]+s[i]
    for j in range(i-3,-1,-1):
        # if c==1 and int(s[j])%3!=0:
        #     c=0
        #     continue
        a=str(a)
        a=int(s[j]+a)
        # print(a)
        # c=0
        # if a%3!=0:
        #     continue
        # c=1
        if a%2019==0:
            # print(b)
            b+=1
            break

print(b)


### FIXED CODE ###

s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
f=1
s= ''.join(list(reversed(s)))
for i in s:
    e+=int(i)*f
    g=e%2019
    c[g]+=1
    f*=10
    f%=2019
e = sum(i * (i - 1) // 2 for i in c)
print(e)
### BUGGY CODE ###

import math
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


sA = sorted(A)
sB = sorted(B, reverse=True)



m = N//2

if N%2 == 1:
    minMid = sA[m]
    maxMid = sB[m]

    print(maxMid-minMid+1)
    exit()
else:
    m = m-1
    minMidL = sA[m]
    maxMidL = sB[m+1]

    minMidH = sA[m+1]
    maxMidH = sB[m]
    # print(minMidL, maxMidL)
    # print(minMidH, maxMidH)
    # print("=======")
    ans = set()
    for i in range(minMidL, maxMidL+1):
        for j in range(max(i, minMidH), maxMidH+1):
            # print(i, j)
            ans.add(i+j)
    print(len(ans))






### FIXED CODE ###

import math
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


sA = sorted(A)
sB = sorted(B, reverse=True)



m = N//2

if N%2 == 1:
    minMid = sA[m]
    maxMid = sB[m]

    print(maxMid-minMid+1)
    exit()
else:
    m = m-1
    minMidL = sA[m]
    maxMidL = sB[m+1]

    minMidH = sA[m+1]
    maxMidH = sB[m]
    # print(minMidL, maxMidL)
    # print(minMidH, maxMidH)
    # print("=======")
    ans = set()
    aa = minMidL + minMidH
    bb = maxMidL + maxMidH
    # print(aa, bb)
    print(bb-aa + 1)
    # for i in range(minMidL, maxMidL+1):
    #     for j in range(max(i, minMidH), maxMidH+1):
            
    #         ans.add(i+j)
    # print(len(ans))
### BUGGY CODE ###

#!/usr/bin/env python3
def f():
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    dp = [[0]*(ls+1) for _ in range(lt+1)]

    for i,T in enumerate(t):
        for j,S in enumerate(s):
            if T == S:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

    ans = ""
    ti = lt
    sj = ls
    while ti > 0 and sj > 0:
        if dp[ti][sj] == dp[ti-1][sj]:
            ti -= 1
        elif dp[ti][sj] == dp[ti][sj-1]:
            sj -= 1
        elif dp[ti][sj] == dp[ti-1][sj-1] + 1:
            ans += t[ti-1]
            ti -= 1
            sj -= 1
    print(ans[::-1])

if __name__ == '__main__':
    f()


### FIXED CODE ###

#!/usr/bin/env python3
s = input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0 for _ in range(ls+1)] for _ in range(lt+1)]

for i in range(lt):
    for j in range(ls):
        if t[i] == s[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

ans = ""
ti = lt
sj = ls
while ti > 0 and sj > 0:
    if dp[ti][sj] == dp[ti-1][sj]:
        ti -= 1
    elif dp[ti][sj] == dp[ti][sj-1]:
        sj -= 1
    elif dp[ti][sj] == dp[ti-1][sj-1] + 1:
        ans += t[ti-1]
        ti -= 1
        sj -= 1
print(ans[::-1])
### BUGGY CODE ###

# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5 3
1 2 2 4 5
'''

def solve(l,k):
	n = len(l)
	subs = []
	for i in range(n-k+1):
		subs.append(l[i:i+k])
	maxx = -1
	sub = []
	for i in subs:
		summ = sum(i)
		if(summ > maxx):
			maxx = summ
			sub = i
	ans = 0
	for i in sub:
		curr = i*(i+1)/2
		ans += curr/i
	# print(subs)
	return ans
	

N,K = map(int, stdin.readline().rstrip().split())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,K)
print("%.10f"%ans)


### FIXED CODE ###

# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5 3
1 2 2 4 5
'''

def solve(l,k):
	n = len(l)
	pre = [l[0]]
	for i in range(1,n):
		pre.append(pre[i-1] + l[i])
	maxx = 0
	index = -1
	for i in range(k-1,n):
		summ = 0
		if(i == k-1):
			summ = pre[i]
		else:
			summ = pre[i] - pre[i-k]
		if(maxx < summ):
			maxx = summ
			index = i
	startIndex = index - k + 1
	optimalSub = l[startIndex:index+1]
	# print(optimalSub)
	ans = 0
	for i in optimalSub:
		curr = i*(i+1)/2
		ans += curr/i
	return ans

N,K = map(int, stdin.readline().rstrip().split())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,K)
print("%.10f"%ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = []

for i in range(n):
    temp = [a[i]]
    if i % 2 == 0:
        b.append(a[i])
    else:
        temp.extend(b)
        b = temp

if n % 2 == 0:
    for i in range(n):
        print(b[i], end=" ")
else:
    for i in range(n)[::-1]:
        print(b[i], end=" ")

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
b = collections.deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 == 1:
    b.reverse()

print(*b)
### BUGGY CODE ###

import numpy as np
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
a=np.array(PY)
p=a[:,0]# 属する県の情報
q=a[:,1]
x=[i for i in range(M)]#答え
def make_number(p,x):
    return str(p*10**6+x).zfill(12)
for i in range(1,N+1):
    y=[]
    for j in range(M):
         if p[j]==i:
                y.append(a[j][1])#県iに属する市の誕生年
    y2=sorted(y) 
    for l in range(len(y2)):
        for k in range(len(q)):
            if q[k]==y2[l]:
                x[k]=make_number(i,l+1)
for i in range(M):
    print(x[i])

### FIXED CODE ###

n,m=map(int,input().split())
pys=[]
def make_number(p,x):
    return str(p*10**6+x).zfill(12)
for i in range(m):
    a,b=map(int,input().split())
    pys.append([a,b,i])
pys.sort()
ans=[i for i in range(m)]
c=-1
j=0
for [p,y,s] in pys:
    if c!=p:
        j=1
        c=p
    ans[s]=make_number(p,j)
    j+=1
for i in range(m):
    print(ans[i])
### BUGGY CODE ###

from itertools import permutations
N, L = map(int, input().split())
S = [input() for _ in range(N)]
p = list(permutations(S))

print(*sorted(p)[0], sep='')

### FIXED CODE ###

n, l = map(int, input().split())
s = [input() for i in range(n)]
print(*sorted(s), sep="")
### BUGGY CODE ###

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

for i in range(m):
  b, c = map(int,input().split())
  for j in range(b):
    if min(a) >= c:
      break
    a[a.index(min(a))] = max(c, min(a))

print(sum(a))


### FIXED CODE ###

#5618213
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
  
for b,c in bc:
  a.extend([c]*b)
  if len(a) > n*2:
    break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

import bisect
from collections import defaultdict

N = int(input())
# 書き換える時に文字列だと不便なのでリスト化しておく
S = list(input())
Q = int(input())

dict = defaultdict(list)
for i in range(N):
    dict[S[i]].append(i)
# print(dict)

ans = []

for _ in range(Q):
    a, b, c = input().split()
    a = int(a)

    if a == 1:
        b = int(b) - 1
        if S[b] == c:
            continue
        else:
            dict[S[b]].remove(b)
            idx = bisect.bisect_left(dict[c], b)
            dict[c].insert(idx, b)
            S[b] = c

    elif a == 2:
        b = int(b) - 1
        c = int(c) - 1
        char_n = 0
        for key, value in dict.items():
            value.sort()
            x1 = bisect.bisect_left(value, b)
            x2 = bisect.bisect_right(value, c)
            if x2 - x1 > 0:
                char_n += 1
        ans.append(char_n)

for i in ans:
    print(i)


### FIXED CODE ###

# test!!!!!!!!!!!

from bisect import bisect_left, bisect_right

N = int(input())

S = list(input())

Q = int(input())

memo = {chr(ord('a') + i): [] for i in range(26)}

for key,val in enumerate(S):
    memo[val].append(key)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1])-1, query[2]
        now = S[i]
        if now == x:
            continue
        memo[now].remove(i)
        next_i = bisect_left(memo[x], i)
        memo[x].insert(next_i, i)
        S[i] = x
    else:
        start, end = int(query[1])-1, int(query[2])-1
        tmp_cout = 0
        for alf_array in memo.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
        print(tmp_cout)
### BUGGY CODE ###

n,q = map(int,input().split())
node = [[]for _ in range(n)]
looked = [1 for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    node[b-1].append(a-1)
    node[a-1].append(b-1)
counter = [0 for _ in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x
queue = [0]
looked[0] = 0
while(len(queue)):
    now = queue.pop(0)
    for i in node[now]:
        if looked[i]:
            queue.append(i)
            counter[i] += counter[now]
            looked[i] = 0
print(" ".join(map(str,counter)))

### FIXED CODE ###

from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()
### BUGGY CODE ###

from collections import deque


class Dinic:
    def __init__(self, n):
        self.n = n
        self.links = [[] for _ in range(n)]
        self.depth = None
        self.progress = None

    def add_link(self, _from, to, cap):
        self.links[_from].append([cap, to, len(self.links[to])])
        self.links[to].append([0, _from, len(self.links[_from]) - 1])

    def bfs(self, s):
        depth = [-1] * self.n
        depth[s] = 0
        q = deque([s])
        while q:
            v = q.popleft()
            for cap, to, rev in self.links[v]:
                if cap > 0 and depth[to] < 0:
                    depth[to] = depth[v] + 1
                    q.append(to)
        self.depth = depth

    def dfs(self, v, t, flow):
        if v == t:
            return flow
        links_v = self.links[v]
        for i in range(self.progress[v], len(links_v)):
            self.progress[v] = i
            cap, to, rev = link = links_v[i]
            if cap == 0 or self.depth[v] >= self.depth[to]:
                continue
            d = self.dfs(to, t, min(flow, cap))
            if d == 0:
                continue
            link[0] -= d
            self.links[to][rev][0] += d
            return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.depth[t] < 0:
                return flow
            self.progress = [0] * self.n
            current_flow = self.dfs(s, t, float('inf'))
            while current_flow > 0:
                flow += current_flow
                current_flow = self.dfs(s, t, float('inf'))


n, a, b = map(int, input().split())
aaa = list(map(int, input().split()))
mf = Dinic(2 * n + 2)
t = 2 * n + 1
for i in range(1, n + 1):
    mf.add_link(0, i, b)
    mf.add_link(n + i, t, a)
INF = 10 ** 18
for i in range(n):
    r = aaa[i]
    for l in aaa[:i]:
        if l > r:
            mf.add_link(r, l + n, INF)
print(mf.max_flow(0, t))


### FIXED CODE ###

from bisect import bisect
from operator import itemgetter

n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [i for i, p in sorted(enumerate(ppp, start=1), key=itemgetter(1))]
INF = 10 ** 15

dp = [(0, 0)]
for i in qqq:
    ndp = []
    s = bisect(dp, (i,))
    tmp_min = INF
    for j, cost in dp[:s]:
        cost += b
        ndp.append((j, cost))
        tmp_min = cost
    stay_cost = dp[s - 1][1]
    if tmp_min > stay_cost:
        ndp.append((i, stay_cost))
        tmp_min = stay_cost
    for j, cost in dp[s:]:
        cost += a
        if tmp_min > cost:
            ndp.append((j, cost))
            tmp_min = cost
    dp = ndp

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

from collections import deque
N = int(input())
s = input().split()
a = [int(i) for i in s]

b = deque()

for i in range(N) : 
    b.append(a[i])
    b.reverse()

ans = ""
for i in b : 
    ans += str(i) + " "
print(ans)

### FIXED CODE ###

from collections import deque
N = int(input())
s = input().split()
a = [int(i) for i in s]

b = deque()

for i in range(N) : 
    if i % 2 == 0 : b.append(a[i])
    if i % 2 == 1 : b.appendleft(a[i])

if i % 2 == 0 : b.reverse()        

print(" ".join(map(str, b)))
### BUGGY CODE ###

n = int(input())
map_ = {}
memo = []

for i in range(n):
  a = int(input())
  if a not in memo:
    map_.update({str(a):1})
    memo.append(a)
  else:
    map_[str(a)] += 1
    map_[str(a)] %= 2
print(sum(map_.values()))

### FIXED CODE ###

n = int(input())
a_list = [int(input()) for _ in range(n)]

my_set = set()
for i in a_list:
  if i in my_set:
    my_set.remove(i)
  else:
    my_set.add(i)
print(len(my_set))
### BUGGY CODE ###

from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
MENU = [100,101,102,103,104,105]
ok = False

X = int(input())
def readInts():
  return list(map(int,input().split()))
def dfs(Price):
    global X
    global ok
    if Price >= X:
        if Price == X:
            ok = True
            return
        else:
            return
    if not ok:
        for v in MENU:
            Price += v
            dfs(Price)
            Price -= v
def main():
    dfs(0)
    print(1 if ok else 0)
if __name__ == '__main__':
  main()


### FIXED CODE ###

from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    X = int(input())
    # O(1)解法
    quo = X//100
    mo_ = X % 100
    # 0 <= Xを100で割った余り <= 5 * Xを100で割った時の商 (最大で、5 * 商まで表せれるから)
    if 0 <= mo_ <= 5*quo:
        print(1)
    else:
        print(0)

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

n, m = map(int, input().split())
a = [int(i) for i in input().split()]
list_ = []
for i in range(m):
    b, c = map(int, input().split())
    list_ += [c] * b

a.sort()
list_.sort(reverse=True)

res = sum(a)
for i in range(min(len(a), len(list_))):
    if a[i] >= list_[i]:
        break
    else:
        res += list_[i] - a[i]

print(res)

### FIXED CODE ###

n, m = map(int, input().split())
a = [(int(i), 1) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    a += [(c, b)]

a.sort(reverse=True)

ans = 0
i = 0
j = 0
while True:
    ans += a[i][0] * min(a[i][1], n-j)
    j += a[i][1]
    i += 1
    if j >= n:
        print(ans)
        break
### BUGGY CODE ###

import math
from functools import reduce

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

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

K = int(input()) + 1

sum = 0
for i in range(1, K):
    for j in range(1, K):
        for k in range(1, K):
            sum += gcd(i, j, k)

print(sum)

### FIXED CODE ###

import math
from functools import reduce

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

K = int(input()) + 1
cache = []

for i in range(1, K):
    for j in range(i, K):
        if (i == j):
            continue
        else:
            cache.append(gcd(i, j))


sum = 0
for j in range(1, K):
    for i in range(len(cache)):
        if (cache[i] == 1 or j == 1):
            sum += 1 * 2
        else:
            sum += gcd(cache[i], j) * 2
    for k in range(1, K):
        sum += gcd(j, k)

print(sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a//gcd(a, b)*b

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
#N = 10**4
#A = [i for i in range(10**6, 10**6-N, -1)]

L = 1

for Ai in A:
    L = lcm(L, Ai)

ans = 0

for Ai in A:
    ans += L//Ai
    ans %= MOD

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a//gcd(a, b)*b
    
def inv(x):
    return pow(x, MOD-2, MOD)
    

def factorize(n):
    factors = []
    
    for i in range(2, int(n**0.5)+1):
        cnt = 0
        
        while n%i==0:
            n //= i
            cnt += 1
    
        if cnt>0:
            factors.append((i, cnt))
    
    if n>1:
        factors.append((n, 1))
    
    return factors

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
#N = 10**4
#A = [i for i in range(10**6, 10**6-N, -1)]

L = 1
d = defaultdict(int)

for Ai in A:
    f = factorize(Ai)
    
    for n, c in f:
        d[n] = max(d[n], c)

for v, c in d.items():
    L *= v**c
    L %= MOD
    
ans = 0

for Ai in A:
    ans += L*inv(Ai)
    ans %= MOD

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

#!/usr/bin/env python3
import sys


def solve(s: str, t: str):
    N = len(s)
    W = len(t)
    dp = [[''] * (W+1) for i in range(N+1)]

    for i in range(N):
        for j in range(W):
            if(s[i] == t[j]):
                dp[i+1][j+1] = dp[i][j]+s[i]
            else:
                if(len(dp[i][j+1]) > len(dp[i+1][j])):
                    dp[i+1][j+1] = dp[i][j+1]
                else:
                    dp[i+1][j+1] = dp[i+1][j]

    print(dp[N][W])

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(s: str, t: str):
    N = len(s)
    W = len(t)
    dp = [[0] * (W+1) for i in range(N+1)]

    for i in range(N):
        for j in range(W):
            if(s[i] == t[j]):
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]) 

    ans = []
    while N > 0 and W > 0:
        if(dp[N][W] == dp[N-1][W]):
            N -= 1
        elif(dp[N][W] == dp[N][W-1]):
            W -= 1
        elif(dp[N][W] == dp[N-1][W-1]+1):
            ans = [s[N-1]] + ans
            N -= 1
            W -= 1


    print(''.join(ans))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)

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

def solve2(s):
    ans = 0
    for i, c in enumerate(s): #見る数字を右に広げていく
        if c in '02468':
            ans += i + 1 # 見ている数字のの一番右の桁が偶数ならその頭に乗っている数字の数だけ
                        # 答えに追加する
                        # 例 2254とし2→偶数、22→偶数（さらに先頭の2をどけても偶数）
                        # →225（奇数）→2254（偶数、上の3つをそれぞれどけても偶数）
    return ans


def solve5(s): # p==2のときと同じ原理
    ans = 0
    for i, c in enumerate(s):
        if c in '05':
            ans += i + 1
    return ans


def solve_other(s, p):
    ans = 0
    last_mod=0
    mods = [0]*p
    mods[0] = 1 #初期値として何も選んでない状態を1個加えとく
    digit = 1
    for i in range(n-1,-1,-1): # 一番右のけたから見る
        last_mod = (last_mod + int(s[i])*digit)%p # 最新のmodに新しく見ている桁*(10**x)を足してmod計算
        ans += mods[last_mod] # modリストに直前までのの値を答えに追加
        mods[last_mod] += 1 # modリスト更新
        digit *=10 # 桁上げ
    return ans


n, p = list(map(int, input().split()))
s = input()
if p == 2:
    print(solve2(s))
elif p == 5:
    print(solve5(s))
else:
    print(solve_other(s, p))

### FIXED CODE ###

def solve2(s):
    ans = 0
    for i, c in enumerate(s): #見る数字を右に広げていく
        if c in '02468':
            ans += i + 1 # 見ている数字のの一番右の桁が偶数ならその頭に乗っている数字の数だけ
                        # 答えに追加する
                        # 例 2254とし2→偶数、22→偶数（さらに先頭の2をどけても偶数）
                        # →225（奇数）→2254（偶数、上の3つをそれぞれどけても偶数）
    return ans


def solve5(s): # p==2のときと同じ原理
    ans = 0
    for i, c in enumerate(s):
        if c in '05':
            ans += i + 1
    return ans


def solve_other(s, p):
    ans = 0
    last_mod=0
    mods = [0]*p
    mods[0] = 1 #初期値として何も選んでない状態を1個加えとく
    digit = 1
    for i in range(n-1,-1,-1): # 一番右のけたから見る
        last_mod = (last_mod + int(s[i])*digit)%p # 最新のmodに新しく見ている桁*(10**x)を足してmod計算
        ans += mods[last_mod] # modリストに直前までのの値を答えに追加
        mods[last_mod] += 1 # modリスト更新
        digit=digit*10%p # 桁上げ
    return ans


n, p = list(map(int, input().split()))
s = input()
if p == 2:
    print(solve2(s))
elif p == 5:
    print(solve5(s))
else:
    print(solve_other(s, p))