CodeEff/ECCO huggingface dataset:
# Original solution
a , b = list(map(int,input().split()))
print(((1900*b+(a-b)*100)*2**b))

# Optimized solution
n,m = list(map(int,input().split()))
print((2**m*1900*m + 2**m*100*(n-m)))
# Original solution
n,m = [int(x) for x in input().split()]

print((( (n - m) * 100 + m * 1900) * 2 ** m))

# Optimized solution
n,m = [int(x) for x in input().split()]

ans = (100 * (n-m) + 1900 * m) * 2 ** m
print(ans)
# Original solution
def main():
    N, M = (int(i) for i in input().split())
    p = (0.5)**M
    np = 1 - p
    t = (1900*M + 100*(N-M))
    ans = 0
    for i in range(1, 10**5)[::-1]:
        ans += i*t*p*(np**(i-1))
    print((round(ans)))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N, M = (int(i) for i in input().split())
    t = 1900*M + 100*(N-M)
    p = 2**M
    print((t*p))


if __name__ == '__main__':
    main()
# Original solution
N, M = list(map(int, input().split()))
t = 1900*M + 100*(N-M)
p = 1/((1/2)**M)
print((int(t*p)))

# Optimized solution
N, M = list(map(int,input().split()))
print(((M * 1900 + (N-M) * 100)*(2 ** M)))
# Original solution
# -*- coding: utf-8 -*-

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

L, S = 1900, 100

time = (N - M) * S + M * L
# bunbo = (2**M - 1)**2

print((int((2**M)*time)))


# Optimized solution
N, M = list(map(int, input().split()))

t = (N - M) * 100 + M * 1900
print((t * (2 ** M)))
# Original solution
N, M = list(map(int, input().split()))

Tone = M * 1900 + (N - M) * 100
Pone = 1.0 / 2**M
prob = 1 - 1.0 / 2**M

ans = 1
for time in range(2, 100000):
    ans += prob * time
    prob *= (1.0 - Pone)

print((int(ans * Tone * Pone + 0.5)))

# Optimized solution
N, M = list(map(int, input().split()))

tOne = M * 1900 + (N - M) * 100

ans = tOne * (2**M)
print(ans)
# Original solution
#78 C - HSI
N,M = list(map(int,input().split()))
# 全て AC となる確率
p = (1/2)**M

# 全て AC となるときの期待値
# k 回目までに「成功しない」確率の期待値
# E = (1-p)**0 + (1-p)**1 + (1-p)**2+...
E = 0
for k in range(10**6):
    E += (1-p)**k

ans = (1900*M + 100*(N-M))*E
ans = round(ans)
print(ans)

# Optimized solution
#78 C - HSI
N,M = list(map(int,input().split()))
# 全て AC となる確率
p = (1/2)**M

# E = 1/p になる
E = 1/p
ans = (1900*M + 100*(N-M))*E
ans = round(ans)
print(ans)
# Original solution
N, M = list(map(int, input().split()))

p = 0.5 ** M
q = 1 - p
i = 0
sum = 0
while True:
    num = (i + 1) * (100 * (N-M) + 1900 * M) * p * (q ** i)
    if num < 10 ** (-6):
        break
    sum += num
    i += 1

print((int(sum+1)))


# Optimized solution
N, M = list(map(int, input().split()))

print((2**M * (100*(N-M) + 1900*M)))
# Original solution
N, M = list(map(int, input().split()))

ans = 0
for i in range(1, 10**6):
    ans += ((1-(1/2)**M)**(i-1)) * ((1/2)**M) * (1900*M+100*(N-M)) * i

print((int(round(ans, -2))))

# Optimized solution
N, M = list(map(int, input().split()))

ans = 0
for i in range(1, 10**5):
    ans += ((1-(1/2)**M)**(i-1)) * ((1/2)**M) * (1900*M+100*(N-M)) * i

print((int(round(ans, -2))))
# Original solution
n,m=[int(i) for i in input().split()]
ans=(n-m)*100
ans=(ans+1900*m)*2**m
print(ans)

# Optimized solution
n,m=list(map(int,input().split()))
print(((m*1900+(n-m)*100)*2**m))
# Original solution
n,m=list(map(int,input().split()));print((1900*m+100*(n-m)<<m))

# Optimized solution
n,m=list(map(int,input().split()));print((100*(18*m+n)<<m))
# Original solution
N,M = list(map(int, input().split()))

print(((1900*M+100*(N-M))*(2**M)))

# Optimized solution
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

print(((1900*m + 100*(n-m))*(2**m)))
# Original solution
n, m = list(map(int, input().split()))
print((2**m*(1900*m+100*(n-m))))

# Optimized solution
n, m = list(map(int, input().split()))
ans = ((1900 * m) + (100 * (n-m))) * 2 ** m
print(ans)
# Original solution
N, M = list(map(int, input().split()))
print(((M * 1900 + (N - M) * 100) * pow(2, M)))

# Optimized solution
N, M = list(map(int, input().split()))
print(((1800 * M + 100 * N) * 2 ** M))
# Original solution
n,m = list(map(int,input().split()));print((100*(18*m+n)*2**m))

# Optimized solution
n,m=list(map(int,input().split()));print(((1900*m+100*(n-m))*2**m))
# Original solution
n, m = list(map(int, input().split()))

print((2**m * (1900*m + 100*(n-m))))

# Optimized solution
n, m = list(map(int, input().split()))

x = ((n-m) * 100 + 1900 * m) * 2**m
print(x)
# Original solution
from math import ceil

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

left = 1
prob = 0
ac = 0.5 ** m
for i in range(1, 10000):
    prob += i * left * ac
    left -= left * ac

ans = (100 * (n - m) + 1900 * m) * prob
ans = ceil(ans)
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
ans = (100 * (n - m) + 1900 * m) * 2 ** m
print(ans)
# Original solution
from fractions import Fraction
import math

n,m = [int(x) for x in input().split()]
tle = m
ac = n-m

p_ok = Fraction(1, 2)**tle
p_ng = 1 - p_ok

time = 0
p_sum = 0

i = 1
while True:
    p = (p_ng**(i-1))*p_ok
    time += i*(100*ac+1900*tle)*p
    p_sum += p
    if 1-p_sum < 0.000000000001:
        break
    i += 1

print((math.ceil(time)))


# Optimized solution
from fractions import Fraction
import math

n,m = [int(x) for x in input().split()]
tle = m
ac = n-m

p_ok = Fraction(1, 2)**tle
p_ng = 1 - p_ok

time = 0
p_sum = 0

i = 1
while True:
    p = (p_ng**(i-1))*p_ok
    time += i*(100*ac+1900*tle)*p
    p_sum += p
    if 1-p_sum < 0.00000001:
        break
    i += 1

print((math.ceil(time)))
# Original solution
#1回の実行にかかるじかんをx、答えとなる時間(全体実行時間の総和の期待値)をYとする
#n回目までで成功する時の実行時間の総和の期待値をy(n)とおくとY=lim(n→∞)y(n)である
#ここでx=1900M+100(N-M)で固定ある。
#ここで各試行で成功する率p=1/2^Mである。
#ここでn回目までで成功する時の実行時間の総和の期待値をy(n)からn+1回目までで成功する時の実行時間の総和の期待値をy(n+1)を求めることを考える
#(i)n=1の時
#1回目までやった時の実行時間の総和の期待値は1通りしかなくxであるためy(1)=xで固定である。
#2回目までやった時の実行時間の総和の期待値は2回目の実行時間xに、1回目までの期待値y(1)のうち、成功せず2回目まで続く1-p分を重みづけ加算して
#y(2)=x+(1-p)y(1)である
#(ii)n=2の時
#3回目までやった時の実行時間の総和の期待値は
#3回目での実行時間xに2回目までの期待値y(2)のうち成功せず3回目まで続く1-p分を重み付け加算して
#y(3)=x+(1-p)y(2)である
#(iii)n=kの時
#y(k+1)=x+(1-p)y(k)
#であることが容易に予想できる
#
#ここでn→∞にした時y(n+1)とy(n)は共にYとなることより
#Y=x+(1-p)Y
#Y=x/p=x*2^Mである
import math
N,M=list(map(int,input().split()))
time=max(0,N-M)*100+1900*M
print((time*pow(2,M)))

# Optimized solution
#ここで求めるのはジャッジ終了時間の期待値である。
#よって1回の実行時間T=max(0,N-M)*100+1900*M、成功率p=1/2^Mとして、
#求める値yは
#y=1*T*p+2*T*p(1-p)+3*T*p(1-p)(1-p)+…
#=(lim N→∞)Σ(1<=i<=N)i*T*p*(1-p)^(i-1)
#=Tp*(lim N→∞)Σ(1<=i<=N)i*(1-p)^(i-1)
#ここで摂動法を用いればΣ(1<=i<=N)i*(1-p)^(i-1)=1/p^2-((1-p)^(N+1))/p^2-((N+1)(1-p)^N)/p
#よってここで1-p<1,p<1より(lim N→∞)Σ(1<=i<=N)i*(1-p)^(i-1)=1/p^2
#よってy=Tp/p^2=T/p=T*2^M

import math
N,M=list(map(int,input().split()))
time=max(0,N-M)*100+1900*M
print((time*pow(2,M)))
# Original solution
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    N, P = list(map(int, input().split()))
    S = list(map(int, input().rstrip("\r\n")))
    S.reverse()
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            if S[i] % P == 0:ans += N-i
    else:
        D = [0] * (N+1)
        tenpow = 1
        for i in range(N):
            S[i] = S[i] * tenpow % P
            tenpow *= 10 % P
            D[i+1] = (S[i] + D[i]) % P
        c = Counter(D)
        for v in list(c.values()):
            ans += v*(v-1)//2
    print(ans)
if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    N, P = list(map(int, input().split()))
    S = list(map(int, input().rstrip("\r\n")))
    S.reverse()
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            if S[i] % P == 0:ans += N-i
    else:
        A = [0] * N
        tenpow = 1
        for i in range(N):
            A[i] = (S[i]*tenpow) % P
            tenpow *= 10
            tenpow %= P
        D = [0] * (N+1)
        for i in range(N):
            D[i+1] = (D[i] + A[i]) % P
        c = Counter(D)
        for v in list(c.values()):
            ans += v*(v-1)//2
    print(ans)
if __name__ == "__main__":
    main()
# Original solution
def main():
    import collections
    N, P = list(map(int, input().split()))
    S = input()[::-1]
    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if int(s) % P == 0:
                ans += N - i
    else:
        mod = [0] * P
        mod[0] = 1
        current = 0
        X = 0
        for s in S:
            current = (current + int(s) * 10 ** X) % P
            ans += mod[current]
            mod[current] += 1
            X += 1
    
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import collections
    N, P = list(map(int, input().split()))
    S = input()[::-1]
    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if int(s) % P == 0:
                ans += N - i
    else:
        mod = [0] * P
        mod[0] = 1
        current = 0
        X = 1
        for s in S:
            current = (current + int(s) * X) % P
            ans += mod[current]
            mod[current] += 1
            X = X * 10 % P
    
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import sys
import itertools
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, P = [int(x) for x in input().split()]
    S = input().strip()

    if P == 2 or P == 5:
        ans = 0
        for i, s in enumerate(S[::-1]):
            if int(s) % P == 0:
                ans += N - i
        print(ans)
        return

    M = [0] * N
    for i, s in enumerate(S[::-1]):
        M[i] = (int(s) * (10 ** i)) % P

    MA = []
    MA.append(M[0])
    c = collections.Counter()
    ans = 0
    c[0] += 1
    ans += c[MA[0]]
    c[M[0]] += 1
    for i in range(1, N):
        MA.append((MA[i - 1] + M[i]) % P)
        ans += c[MA[i]]
        c[MA[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import itertools
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, P = [int(x) for x in input().split()]
    S = input().strip()

    if P == 2 or P == 5:
        ans = 0
        for i, s in enumerate(S[::-1]):
            if int(s) % P == 0:
                ans += N - i
        print(ans)
        return

    M = [0] * N
    for i, s in enumerate(S[::-1]):
        M[i] = (int(s) * pow(10, i, P)) % P

    MA = []
    MA.append(M[0])
    c = collections.Counter()
    ans = 0
    c[0] += 1
    ans += c[MA[0]]
    c[M[0]] += 1
    for i in range(1, N):
        MA.append((MA[i - 1] + M[i]) % P)
        ans += c[MA[i]]
        c[MA[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, P = LI()
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[N-1 - i]) % P == 0:
            ans += N-i
    print(ans)
else:
    A = [0] * (N+1)
    for i in range(N):
        A[i+1] = (A[i] + int(S[N-1 - i]) * (10**i)) % P

    c = collections.Counter(A)
    ans = 0
    for k, v in c.items():
        ans += v * (v-1) // 2
    
    print(ans)


# Optimized solution
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, P = LI()
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[N-1 - i]) % P == 0:
            ans += N-i
    print(ans)
else:
    A = [0] * (N+1)
    for i in range(N):
        A[i+1] = (A[i] + int(S[N-1 - i]) * pow(10, i, P)) % P

    c = collections.Counter(A)
    ans = 0
    for v in c.values():
        ans += v * (v-1) // 2
    
    print(ans)
# Original solution
import sys
input = sys.stdin.readline

N, P = list(map(int, input().split()))
S = list(map(int, list(input().rstrip())))
ans = 0
if P == 2 or P == 5:
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1
else:
    U = [0] * (N+1)
    count = [0] * P
    count[0] = 1
    factor = 10
    for i in range(N)[::-1]:
        x = S[i] * 10**(N-i-1) + U[i+1]
        U[i] = (S[i] * factor + U[i+1]) % P
        factor = factor * 10 % P
        ans += count[U[i]]
        count[U[i]] += 1
print(ans)


# Optimized solution
import sys
input = sys.stdin.readline

N, P = list(map(int, input().split()))
S = list(map(int, list(input().rstrip())))
ans = 0
if P == 2 or P == 5:
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1
else:
    U = [0] * (N+1)
    count = [0] * P
    count[0] = 1
    factor = 10
    for i in range(N)[::-1]:
        U[i] = (S[i] * factor + U[i+1]) % P
        factor = factor * 10 % P
        ans += count[U[i]]
        count[U[i]] += 1
print(ans)
# Original solution
N,P=list(map(int,input().split()))
S=str(eval(input()))

ans=0
if 10%P==0:
    for i in range(N):
        if int(S[i])%P==0:
            ans+=i+1
else:
    rem=[0]*P
    rem[0]=1
    for i in range(N-1,-1,-1):
        rem[int(S[i:N])%P]+=1
    for j in rem:
        ans+=(j*(j-1))//2
print(ans)


# Optimized solution
N,P=list(map(int,input().split()))
S=str(eval(input()))
ans=0

if 10%P==0:
    for i in range(N):
        if int(S[i])%P==0:
            ans+=i+1
else:
    rem = [0]*P
    mod = 0
    ten = 1
    rem[mod]=1
    for i in range(N):
        mod=(mod+int(S[N-i-1])*ten)%P
        ten=ten*10%P
        rem[mod]+=1
    for j in rem:
        ans+=(j*(j-1))//2
print(ans)
# Original solution
import sys
from collections import Counter
n, p = [int(i) for i in sys.stdin.readline().split()]
s = sys.stdin.readline().strip()
if p == 2:
    ans = 0
    for i, _s in enumerate(s, 1):
        if int(_s) % 2 == 0:
            ans += i
    print(ans)
elif p == 5:
    ans = 0
    for i, _s in enumerate(s, 1):
        if int(_s) in {0, 5}:
            ans += i
    print(ans)
else:
    us = Counter([])
    cur = ""
    ans = 0
    mod = 0
    for i, _s in enumerate(s[::-1]):
        mod = (10 ** i % p * int(_s) + mod) % p
        if mod == 0:
            ans += us[mod] + 1
        else:
            ans += us[mod]
        us.update([mod])
    print(ans)

# Optimized solution
import sys
from collections import Counter
n, p = [int(i) for i in sys.stdin.readline().split()]
s = sys.stdin.readline().strip()
if p == 2:
    ans = 0
    for i, _s in enumerate(s, 1):
        if int(_s) % 2 == 0:
            ans += i
    print(ans)
elif p == 5:
    ans = 0
    for i, _s in enumerate(s, 1):
        if int(_s) in {0, 5}:
            ans += i
    print(ans)
else:
    us = Counter([])
    cur = ""
    ans = 0
    mod = 0
    keta_mod = 1
    for i, _s in enumerate(s[::-1]):
        keta_mod = keta_mod * 10 % p
        mod = (keta_mod * int(_s) + mod) % p
        if mod == 0:
            ans += us[mod] + 1
        else:
            ans += us[mod]
        us.update([mod])
    print(ans)
# Original solution
N, P = list(map(int,input().split()))
S = str(eval(input()))
L = len(S)
ans = 0
dic = {0:1} #一番右端は0なのでこれは常に必要
now = 0
if P == 2 or P == 5:
  kotae = 0
  for i in range(L):
    if int(S[L-1-i])%P == 0:
      kotae += L-i
  print(kotae)
  exit(0)
else:
  for i in range(L):
    now += int(S[L-1-i])*pow(10,i)
    temp = now%P
    if temp not in dic:
      dic[temp] = 1
    else:
      dic[temp] += 1
#print(dic)
ans = 0  
for i in list(dic.values()):
  if i != 1:
    ans += i*(i-1)//2
print(ans)

# Optimized solution
N, P = list(map(int,input().split()))
S = str(eval(input()))
L = len(S)
ans = 0
dic = {0:1} #一番右端は0なのでこれは常に必要
now = 0
if P == 2 or P == 5:
  kotae = 0
  for i in range(L):
    if int(S[L-1-i])%P == 0:
      kotae += L-i
  print(kotae)
  exit(0)
else:
  for i in range(L):
    now += int(S[L-1-i])*pow(10,i,P)
    temp = now%P
    if temp not in dic:
      dic[temp] = 1
    else:
      dic[temp] += 1
#print(dic)
ans = 0  
for i in list(dic.values()):
  if i != 1:
    ans += i*(i-1)//2
print(ans)
# Original solution
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, p = list(map(int, input().strip().split()))
  s = input().strip()
  ans = 0
  if 10 % p == 0:
    for r in range(n):
      if int(s[r]) % p == 0:
        ans += r+1
    print(ans)
    return
  
  remains = [0] * (n+1)
  x = 1
  for r in range(n-1, -1, -1):
    remain = (int(s[r]) * x) % p
    remains[r] = (remains[r+1] + remain) % p
    x *= 10
  
  counts = [0] * p
  for remain in remains:
    counts[remain] += 1
  for count in counts:
    ans += (count * (count - 1)) // 2
  print(ans)

if __name__=='__main__':
  main()



# Optimized solution
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, p = list(map(int, input().strip().split()))
  s = input().strip()
  ans = 0
  if 10 % p == 0:
    for r in range(n):
      if int(s[r]) % p == 0:
        ans += r+1
    print(ans)
    return
  
  remains = [0] * (n+1)
  counts = [0] * p
  counts[0] += 1
  x = 1
  for r in range(n):
    remain = (int(s[-(r+1)]) * x) % p
    remains[-(r+1)] = (remains[-r] + remain) % p
    counts[remains[-(r+1)]] += 1
    x = (x * 10) % p
  for count in counts:
    ans += (count * (count - 1)) // 2
  print(ans)

if __name__=='__main__':
  main()
# Original solution
n, p = list(map(int,input().split()))
s = str(eval(input()))
mods = [(i*10)%p for i in range(p)]
sums = [0] * p

tmp = 0
dp = [[0]*p for i in range(n+1)]

if p == 2 or p == 5:
    ans = 0
    for i in range(n):
        if int(s[i])%p == 0:
            ans += i+1
    print(ans)
    exit()

for i in range(1,n+1):
    now = int(s[i-1])%p
    dp[i][now] += 1
    for j in range(p):
        dp[i][(mods[j]+now)%p] += dp[i-1][j]
#         tmp[(mods[j]+now)%p] += sums[j]
print((sum([dp[i][0] for i in range(n+1)])))
# print(*dp,sep="\n")

# Optimized solution
n, p = list(map(int,input().split()))
s = str(eval(input()))
ans = 0

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i])%p == 0:
            ans += i+1
    print(ans)
    exit()

tmp = [0] * p
tmp[0] = 1
mod = 0
for i in range(1,n+1):
    mod += (int(s[-i]) * 10**i) % p
    mod %= p
    ans += tmp[mod]
    tmp[mod] += 1

print(ans)
# Original solution
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import defaultdict
def main():
    N, P = MI()
    S_ = S()
    mod_list = defaultdict(int)
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            num = int(S_[i])
            if num % P == 0:
                ans += i + 1

    else:
        num = 0
        point = 1
        for i in S_[::-1]:
            num += int(i) * point
            mod = int(num) % P
            mod_list[mod] += 1
            point *= 10
    values_ = list(mod_list.values())
    ans += mod_list[0]
    for value in values_:
        ans += (value - 1) * value // 2

    print(ans)

if __name__ == "__main__":
    main()


# Optimized solution
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import defaultdict
def main():
    N, P = MI()
    S_ = S()
    mod_list = defaultdict(int)
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            num = int(S_[i])
            if num % P == 0:
                ans += i + 1

    else:
        num = 0
        point = 1
        for i in S_[::-1]:
            num += int(i) * point
            mod = int(num) % P
            mod_list[mod] += 1
            point *= 10
            point %= P
    values_ = list(mod_list.values())
    ans += mod_list[0]
    for value in values_:
        ans += (value - 1) * value // 2

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def toint(l, r):
    return int(''.join(map(str, S[l:r])))


def test():
    ans = 0
    for l, r in itertools.combinations_with_replacement(list(range(N)), r=2):
        s = toint(l, r + 1)
        ans += s % P == 0
    print(ans)


def solve25():
    ret = 0
    for d in range(N):
        if S[d] % P == 0:
            ret += d + 1
    return ret


def mod_invs(max, mod):
    """
    逆元 0, 1/1, 1/2, 1/3, ..., 1/max
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    invs[0] = 0
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


N, P = list(map(int, sys.stdin.buffer.readline().split()))
S = list(map(int, list(sys.stdin.buffer.readline().decode().rstrip())))

# 10 mod P で割れない
if P in [2, 5]:
    ans = solve25()
    print(ans)
    exit()

# test()

powers = []
p = 1
for _ in range(N):
    powers.append(p)
    p = p * 10 % P
# int(S[1:1]), int(S[1:2]), int(S[1:3]), ...
s_additions = [0]
s = 0
for i in range(1, N):
    s = (s * 10 + S[i]) % P
    s_additions.append(s)
invs = mod_invs(max=P - 1, mod=P)


def to_index(i, p):
    # もともと x だったのが、i 番目で p になっているときの x を返す
    if i == 0:
        return p % P
    return (p - s_additions[i]) * invs[powers[i]] % P


mod_counts = [0] * P
ans = 0
for i, c in enumerate(S):
    mod_counts[to_index(i, c)] += 1
    ans += mod_counts[to_index(i, 0)]
print(ans)


# Optimized solution
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説
# P で割り切れるなら 10^n で割っても割り切れる。
N, P = list(map(int, sys.stdin.buffer.readline().split()))
S = sys.stdin.buffer.readline().decode().rstrip()


def solve25():
    ans = 0
    for i, c in enumerate(S):
        if int(c) % P == 0:
            ans += i + 1
    return ans


if P in (2, 5):
    ans = solve25()
    print(ans)
    exit()

# U[i]: int(S[i:]) % P
U = [0] * N
n = 0
p = 1
for i, c in reversed(list(enumerate(S))):
    n += int(c) * p
    n %= P
    U[i] = n
    p *= 10
    p %= P

counts = [0] * P
for u in U:
    counts[u] += 1

ans = counts[0]
for i in reversed(list(range(N))):
    # U[i] を引いたときに 0 (mod P) となる数
    counts[U[i]] -= 1
    ans += counts[U[i]]
print(ans)