Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

ans = 0

for i in range( N - K ):
  ans += A[i]
  
print(ans)

Fixed submission:
H, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

ans = 0

for i in range( H - K ):
  ans += A[i]
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split() )

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

# N -> dp[N - A_i] + B_i

dp = [0 for i in range(H+1)]

for i in range(H+1):
  temp = 10 ** 8 + 1
  for j in range(N): # Use each Magic j
    if i - A[j] > 0:
      temp = min(temp, dp[ i - A[j] ] + B[j] )
    else:
      temp = min(temp, B[j] )
  dp[i] = temp
               
print(dp[H])

Fixed submission:
H, N = map(int, input().split() )

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

# N -> dp[N - A_i] + B_i

dp = [0 for i in range(H+1)]

for i in range(H+1):
  temp = 10 ** 8 + 1
  for j in range(N): # Use each Magic j
    if i - A[j] > 0:
      temp = min(temp, dp[ i - A[j] ] + B[j] )
    else:
      temp = min(temp, B[j] )
  dp[i] = temp
               
print(dp[H])
Buggy python submission (verdict: Runtime Error):
X = int(input())

def is_Prime(x):
  for i in range(2, x+1):
    if i * i + 1 > x:
      return True
    if x % i == 0:
      return False

for i in range(X+1, 2X+1):
  if is_Prime(i):
    print(i)
    break

Fixed submission:
X = int(input())

def is_Prime(x):
  for i in range(2, x+1):
    if i * i + 1 > x:
      return True
    if x % i == 0:
      return False

for i in range(X, 2*X+1):
  if is_Prime(i):
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
s = input()
r = ['SUN','MON','TUE','WED','THU','FRI','SAT']

for i in len(r):
  if s == r[i]:
    print(7-i)

Fixed submission:
s = input()
r = ['SUN','MON','TUE','WED','THU','FRI','SAT']

for i in range(len(r)):
  if s == r[i]:
    print(7-i)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
  for j in range(i+1, N):
    ans += X[i] * X[j]
    
print(ans)


Fixed submission:
N = int(input())
X = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(i+1, N):
    ans += X[i] * X[j]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().spit()))
for i in range(N):
  for j in range(i+1, N):
    ans += X[i] * X[j]
    
print(ans)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(i+1, N):
    ans += X[i] * X[j]
    
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
O = ['R','U','D']
E = ['L','U','D']
ng = False
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] not in O:
      ng = True
      break
  else:
    if S[i] not in E:
      ng = True
      break
print('No') if ng print('Yes')

Fixed submission:
S = input()
O = ['R','U','D']
E = ['L','U','D']
ng = False
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] not in O:
      ng = True
      break
  else:
    if S[i] not in E:
      ng = True
      break
print('No') if ng else print('Yes')
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
count = 0
for i in range(len(3)):
  if S[i] == T[i]:
    count += 1
print(count)

Fixed submission:
S = input()
T = input()
count = 0
for i in range(3):
  if S[i] == T[i]:
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
print( max(A+B A-B, A*B))

Fixed submission:
A, B = map(int, input().split())
print( max(A+B, A-B, A*B))
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N-2):
  if P[i] > P[i+1] and P[i+1] > P[i+2] or P[i] < P[i+1] and P[i+1] < P[i+2] or :
    ans += 1

print(ans)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N-2):
  if P[i] > P[i+1] and P[i+1] > P[i+2] or P[i] < P[i+1] and P[i+1] < P[i+2]:
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())
#L, L+N-1 => sum: (2L+N-1)*N // 2
A = (2L+N-1)*N // 2
if L*(L+N-1) <= 0:
  print( A )
elif L+N-1 < 0:
  print( A - (L+N-1) )
else:
  print( A - L )

Fixed submission:
N, L = map(int, input().split())
#L, L+N-1 => sum: (2L+N-1)*N // 2
A = (2 * L + N - 1)*N // 2
if L*(L+N-1) <= 0:
  print( A )
elif L+N-1 < 0:
  print( A - (L+N-1) )
else:
  print( A - L )
Buggy python submission (verdict: Runtime Error):
N = int(input())
W = [int(i) for i in input().split()]

ans = sum(W)
s = ans
t = 0
for i in range(N):
  s -= W[i]
  t += W[i]
  ans = min(abs(s-t))
  
print(ans)

Fixed submission:
N = int(input())
W = [int(i) for i in input().split()]

ans = sum(W)
s = ans
t = 0
for i in W:
  s -= i
  t += i
  ans = min(abs(s-t), ans)
  
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
s = {"A", "C", "G", "T"}
ans = 0
for i in S:
  if i in s:
    tmp += 1
    ans = max(ans, tmp)
  else:
    tmp = 0
print(ans)

Fixed submission:
S = input()
s = {"A", "C", "G", "T"}
ans = 0
tmp = 0
for i in S:
  if i in s:
    tmp += 1
    ans = max(ans, tmp)
  else:
    tmp = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
t = [0 for i in range(M+1)]
for i in range(N):
  A = map(int, input().split())
  for j in range(1, A[0]+1):
    t[ A[j] ] += 1
ans = 0
for i in t:
  if i == N:
    ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
t = [0 for i in range(M+1)]
for i in range(N):
  A = list(map(int, input().split()))
  for j in range(1, A[0]+1):
    t[ A[j] ] += 1
ans = 0
for i in t:
  if i == N:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
c = 1001
for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)
print(ans) if c < 1001 else print("TLE")

Fixed submission:
N, T = map(int, input().split())
ans = 1001
for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)
print(ans) if ans < 1001 else print("TLE")
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split() ) ).sort()
print( A[0] + A[1] + 10*A[2] )


Fixed submission:
A = sorted( list(map(int, input().split() ) ) )
print( A[0] + A[1] + 10*A[2] )
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

def f(s, t):
  set_s = set()
  set_t = set()
  for i in s:
    set_s.add(i)
  for i in t:
    set_t.add(i)
  return len( set_s & set_t )

for i in range(1,N):
  s = S[i:]
  t = S[:i]
  ans = max(ans, f(s ,t))
print(ans)

Fixed submission:
N = int(input())
S = input()

def f(s, t):
  set_s = set()
  set_t = set()
  for i in s:
    set_s.add(i)
  for i in t:
    set_t.add(i)
  return len( set_s & set_t )

ans = 0
for i in range(1,N):
  s = S[i:]
  t = S[:i]
  ans = max(ans, f(s ,t))
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
L = [s[0], s[1], s[2]].sort().join()
print("Yes") if L == "abc" else print("No")


Fixed submission:
s = input()
L = [s[0], s[1], s[2]]
L.sort()
S = "".join(L)
print("Yes") if S == "abc" else print("No")

Buggy python submission (verdict: Runtime Error):
s = input().sort()
print("Yes") if s == "abc" else print("No")

Fixed submission:
s = input()
L = [s[0], s[1], s[2]]
L.sort()
S = "".join(L)
print("Yes") if S == "abc" else print("No")

Buggy python submission (verdict: Runtime Error):
s = input().sort()
print("Yes") if s = "abc" else print("No")

Fixed submission:
s = input()
L = [s[0], s[1], s[2]]
L.sort()
S = "".join(L)
print("Yes") if S == "abc" else print("No")
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

print( min(A,B) + min(C,D))

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())

print( min(A,B) + min(C,D))
Buggy python submission (verdict: Runtime Error):
x = int(input())

N = x // 11
M = x % 11

ans = 0
if M <= 5:
  ans = 1
else ans = 2

print(2*N + ans)


Fixed submission:
x = int(input())

N = x // 11
M = x % 11

if M == 0:
  ans = 0
elif M <= 6:
  ans = 1
else:
  ans = 2

print(2*N + ans)

Buggy python submission (verdict: Runtime Error):
x = int(input())

N = x // 11
M = x % 11

ans = 0
if M <= 5:
  ans = 1
else ans = 2

print(2N + ans)

Fixed submission:
x = int(input())

N = x // 11
M = x % 11

if M == 0:
  ans = 0
elif M <= 6:
  ans = 1
else:
  ans = 2

print(2*N + ans)
Buggy python submission (verdict: Runtime Error):
A, op, B = input().split()
if op = '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))

Fixed submission:
A, op, B = input().split()
if op == '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = list(map(int, input().split()))
M = int(input())

s = sum(T)
for i in range(N):
  P, X = map(int, input().split())
  print(s - T[P-1] + X)

Fixed submission:
N = int(input())
T = list(map(int, input().split()))
M = int(input())

s = sum(T)
for i in range(M):
  P, X = map(int, input().split())
  print(s - T[P-1] + X)
Buggy python submission (verdict: Runtime Error):
s = set(map(int, input().split()))
print(s.count())

Fixed submission:
s = set(map(int, input().split()))
print(len(s))
Buggy python submission (verdict: Runtime Error):
a, b, h = map(int, input().split())
print( (a+b) * h // 2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print( (a + b) * h // 2)
Buggy python submission (verdict: Runtime Error):
N, K, X, Y = map(int, input().split())

if N <= K:
  print(N * X)
else:
  print(K * X + (N-K) * Y)

Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N <= K:
  print(N * X)
else:
  print(K * X + (N-K) * Y)
Buggy python submission (verdict: Runtime Error):
w = input()

f = True
for i in renge(len(w)):
  if w.count(w[i]) % 2 == 1:
    print("No")
    f = False
if f:
  print("Yes")

Fixed submission:
w = input()

f = True
for i in range(len(w)):
  if w.count(w[i]) % 2 == 1:
    print("No")
    f = False
    break
if f:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for i in range(N)]

r = 200*100

for i in range(-100,101):
  res = 0
  for j in range(N):
    res += (L[j] - i) ** 2
  r = min(r, res)
print(r)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))

r = (200 ** 2)*100

for i in range(-100,101):
  res = 0
  for j in range(N):
    res += (L[j] - i) ** 2
  r = min(r, res)
print(r)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
Dlist = [1,1,1,1,1,1,1,1,1,1]
for i in range(K):
  D = int(input())
  Dlist[D]=0

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1

Fixed submission:
N, K = map(int, input().split())
DL = list(map(int, input().split()))
Dlist = [1,1,1,1,1,1,1,1,1,1]
for i in range(len(DL)):
  Dlist[DL[i]]=0

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1
Buggy python submission (verdict: Runtime Error):
n=int(input())
readints = lambda: map(int,input().split(' '))
a=list(readints())
a.sort()
mid = n//2
x=a[mid]
y=a[mid+1]
print(y-x)


Fixed submission:
n=int(input())
readints = lambda: map(int,input().split(' '))
a=list(readints())
a.sort()
mid = n//2
x=a[mid-1]
y=a[mid]
print(y-x)

Buggy python submission (verdict: Runtime Error):
n=int(input())
readints = lambda: list(map(int,input().split(' ')))
a=readints()
a.sort()
mid = n//2
x=a[mid]
y=a[mid+1]
print(y-x)

Fixed submission:
n=int(input())
readints = lambda: map(int,input().split(' '))
a=list(readints())
a.sort()
mid = n//2
x=a[mid-1]
y=a[mid]
print(y-x)
Buggy python submission (verdict: Runtime Error):
x=input()
if x=='7' or x=='5' or x=='3': print('YES') else print('NO')

Fixed submission:
x=input()
if x=='7' or x=='5' or x=='3':
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
s=input()
s.sort()
if s=='abc':
  print('Yes')
else:
  print('No')

Fixed submission:
s=input()
s=''.join(sorted(s))
if s=='abc':
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
A = list(map(int,(input().split())))
A.sort()
l = []
ans = 0
for i in range(N):
    tmp = A[i-1]
    if i != N-1:
        if A[i] != A[i+1]:
            now = A[i]
            for j in range(len(l)):
                if now % l[j] == 0:
                    flag = 0
                    break
                if now < l[j]*2:
                    flag = 1
                    break
            else:
                flag = 1
            if flag == 1:
                l.append(now)
                if i == 0 or now != tmp:
                    ans += 1
    else:
        now = A[i]
        for j in range(len(l)):
            if now % l[j] == 0:
                flag = 0
                break
            if now < l[j]*2:
                flag = 1
                break
        else:
            flag = 1
        if flag == 1:
            l.append(now)
            if i == 0 or now != tmp:
                ans += 1
print(ans)
#print(l)

Fixed submission:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
A = list(map(int,(input().split())))
A.sort()
A.append(-1)
ans = 0
ok = [True]*(10**6+1)
for i in range(N):
    now = A[i]
    if now != A[i+1]:
        if ok[now]:
            if i == 0 or now != A[i-1]:
                ans += 1
            c = 1
            while now*c < 10**6+1:
                ok[now*c] = False
                c += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,(input().split())))
ans = 1
for i in range(N):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
N = int(input())
a = list(map(int,(input().split())))
ans = 1
if 0 in a:
    print(0)
else:
    for i in range(N):
        ans *= a[i]
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

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

if A[0] != 0:
    flag = -1
if A[-1] == 0:
    flag = -1

S = [-1]*N
S[0] = sum(A)
for i in range(1,N):
    S[i] = S[i-1] - A[i]

M = [-1]*N
M[0] = 2
for i in range(1,N):
    M[i] = (M[i-1]-A[i])*2
    if M[i] <= 0:
        flag = -1
#print(S,M)

if flag != -1:
    V = [-1]*N
    for i in range(N):
        if S[i] > M[i]:
            V[i] = M[i]
        else:
            V[i] = S[i]
    ans = sum(V)+1
    #print(V)
    print(ans)
else:
    print(-1)

Fixed submission:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

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

if N != 0:

    if A[0] != 0:
        flag = -1
    if A[-1] == 0:
        flag = -1

    S = [-1]*N
    S[0] = sum(A)
    for i in range(1,N):
        S[i] = S[i-1] - A[i]

    M = [-1]*N
    M[0] = 2
    for i in range(1,N):
        M[i] = (M[i-1]-A[i])*2
        if M[i] <= 0:
            flag = -1
    #print(S,M)

    if flag != -1:
        V = [-1]*N
        for i in range(N):
            if S[i] > M[i]:
                V[i] = M[i]
            else:
                V[i] = S[i]
        ans = sum(V)+1

        if S[-1] <= M[-1]:
            #print(V)
            print(ans)
        else:
            print(-1)
    else:
        print(-1)

else:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
import itertools

N,M,Q = map(int,(input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,(input().split()))

l = list(itertools.combinations_with_areplacement(range(1,M+1), N))

nax = 0
for x in l:
    score = 0
    for i in range(Q):
        if int(x[b[i]-1]) - int(x[a[i]-1]) == c[i]:
            score += d[i]
    nax = max(nax,score)

print(nax)

Fixed submission:
N,M,Q = map(int,(input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,(input().split()))

lun = [0]*N
l = []

def make(n):
    if len(n) > N:
        return 0
    if int(n) > 3234566667:
        return 0
    else:

        p = []
        for i in range(int(n[-1]),M):
            p.append(str(i))

        lun.append(n)
        for i in p:
            lun.append(n)
            if len(n) == N:
                l.append(n)
            make(n+i)
        return 0
for i in range(M):
    make(str(i))

l = list(set(l))

nax = 0
for x in l:
    score = 0
    for i in range(Q):
        if int(x[b[i]-1]) - int(x[a[i]-1]) == c[i]:
            score += d[i]
    nax = max(nax,score)

print(nax)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
lst = []

for i in range(Q):
    tmp = list(input().split())
    lst.append(tmp)

reverse = 0
c = 1
for i in range(Q):

    if int(lst[i][0]) == 1:
        reverse += 1
        c += 1
    
    if int(lst[i][0]) == 2:
        if c%2 == 1:
            if int(lst[i][1]) == 1:
                S.insert(0,lst[i][2])
            else:
                S.append(lst[i][2])
        else:
            if int(lst[i][1]) == 2:
                S.insert(0,lst[i][2])
            else:
                S.append(lst[i][2])

if reverse%2 == 1:
    S.reverse()

ans = "".join(S)
print(ans)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())
lst = deque()

for i in range(Q):
    tmp = list(input().split())
    lst.append(tmp)

reverse = 0
c = 1
for i in range(Q):

    if int(lst[i][0]) == 1:
        reverse += 1
        c += 1
    
    if int(lst[i][0]) == 2:
        if c%2 == 1:
            if int(lst[i][1]) == 1:
                S.appendleft(lst[i][2])
            else:
                S.append(lst[i][2])
        else:
            if int(lst[i][1]) == 2:
                S.appendleft(lst[i][2])
            else:
                S.append(lst[i][2])

if reverse%2 == 1:
    S.reverse()

ans = "".join(S)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
lst = []

for i in range(Q):
    tmp = list(input().split())
    lst.append(tmp)

for i in range(Q):
    if int(lst[i][0]) == 1:
        S.reverse()
    if int(lst[i][0]) == 2:
        if int(lst[i][1]) == 1:
            S.insert(0,lst[i][2])
        else:
            S.append(lst[i][2])

ans = "".join(S)
print(ans)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())
lst = deque()

for i in range(Q):
    tmp = list(input().split())
    lst.append(tmp)

reverse = 0
c = 1
for i in range(Q):

    if int(lst[i][0]) == 1:
        reverse += 1
        c += 1
    
    if int(lst[i][0]) == 2:
        if c%2 == 1:
            if int(lst[i][1]) == 1:
                S.appendleft(lst[i][2])
            else:
                S.append(lst[i][2])
        else:
            if int(lst[i][1]) == 2:
                S.appendleft(lst[i][2])
            else:
                S.append(lst[i][2])

if reverse%2 == 1:
    S.reverse()

ans = "".join(S)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
s = list(input())
S = [0]*N

for i in range(N):
    S[i] = int(s[i])

count = 0

if P != 2 and P != 5:
    now = 0
    remainder = []
    for i in range(1,N+1):
        now += S[N-i] * (10**(i-1))
        remainder.append(now % P)

    result={}
    for i in range (0,len(remainder)):
        item = remainder[i]
        if item in result:
            result[item] = result[item]+1
        else:
            result[item] = 1

    for k in result.keys():
        if k == 0:
            if result[0] >= 2:
                count += result[0] + result[0]*(result[0]-1)//2
            else:
                count += result[0]
        else:
            count += result[k]*(result[k]-1)//2

else:
    if P == 2:
        for i in range(N):
            if S[i] %2 == 0:
                count += i+1
    if P == 5:
        for i in range(N):
            if S[i] %5 == 0:
                count += i+1

print(count)

Fixed submission:
N,P = map(int,input().split())
s = list(input())
S = [0]*N

for i in range(N):
    S[i] = int(s[i])

count = 0

if P != 2 and P != 5:
    now = 0
    remainder = []
    for i in range(1,N+1):
        now += S[N-i] * (pow(10,(i-1),P) )
        remainder.append(now % P)

    result={}
    for i in range (0,len(remainder)):
        item = remainder[i]
        if item in result:
            result[item] = result[item]+1
        else:
            result[item] = 1

    for k in result.keys():
        if k == 0:
            if result[0] >= 2:
                count += result[0] + result[0]*(result[0]-1)//2
            else:
                count += result[0]
        else:
            count += result[k]*(result[k]-1)//2

else:
    if P == 2:
        for i in range(N):
            if S[i] %2 == 0:
                count += i+1
    if P == 5:
        for i in range(N):
            if S[i] %5 == 0:
                count += i+1

print(count)