Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
    S = input()
    Q = int(input())
    reverse = False
    front = ""
    end = S
     
    for i in range(Q):
        inp = input()
        if inp[0] == "1":
            reverse = ~reverse
        else:
            _, F, C = inp.split()
            if (F == "1") ^ reverse:
                front =front+C
            else:
                end = end+C
     
     
    if reverse:
        print(end[::-1]+front)
    else:
        print(front[::-1]+end)

Fixed submission:
S = input()
Q = int(input())
reverse = False
front = ""
end = S

for _ in range(Q):
    I = input().split()
    if I[0] == "1":
        reverse = not reverse
    else:
        if (I[1] == "1") ^ reverse:
            front =front + I[2]
        else:
            end = end + I[2]


if reverse:
    print("".join(list(reversed(end)))+front)
else:
    print("".join(list(reversed(front)))+end)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
reverse = False
front = ""
end = ""

for i in range(Q):
    print(end[::-1]+S[::-1]+front)
    inp = input()
    if inp[0] == "1":
        reverse = ~reverse
    else:
        _, F, C = inp.split()
        if (F == "1" and reverse == False) or (F == "2" and reverse == True):
            front = front+C
        else:
            end = end+C

if reverse:
    print(end[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+end)


Fixed submission:
S = input()
Q = int(input())
reverse = False
front = ""
end = S

for _ in range(Q):
    I = input().split()
    if I[0] == "1":
        reverse = not reverse
    else:
        if (I[1] == "1") ^ reverse:
            front =front + I[2]
        else:
            end = end + I[2]


if reverse:
    print("".join(list(reversed(end)))+front)
else:
    print("".join(list(reversed(front)))+end)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
result = [False]*N
count = 0
for i in range(N):
    flag = True
    for j in range(i):
        if not P[i] <= P[j]:
            flag = False
            break
        elif result[i] == True:
            break
    if flag == True:
        result[i] = True
        count += 1


print(count)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
result = [False]*N
count = 0
mn = P[0]
for i in range(N):
    if P[i] <= mn:
        count += 1
        mn = P[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
count = 0
for i in range(N):
    flag = True
    for j in range(i):
        if not P[i] <= P[j]:
            flag = False
            break
    if flag == True:
        count += 1

print(count)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
result = [False]*N
count = 0
mn = P[0]
for i in range(N):
    if P[i] <= mn:
        count += 1
        mn = P[i]

print(count)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
PS = []
for i in range(M):
    p, s = input().split()
    PS += [(int(p),s)]

CA = 0
PN = 0
l = [True]*M
for i in range(len(PS)):
    if l[PS[i][0]]:
        if PS[i][1] == "WA":
            PN += 1
        elif PS[i][1] == "AC":
            CA += 1
            l[PS[i][0]] = False

print(CA, PN)

Fixed submission:
N, M = map(int, input().split())
P = []
S = []
for i in range(M):
    p, s = input().split()
    P += [int(p)]
    S += [s]

CA = 0
PN = 0
d = {key:0 for key in P}
for i in range(len(P)):
    if d[P[i]] >= 0:
        if S[i] == "WA":
            d[P[i]] += 1
        elif S[i] == "AC":
            PN += d[P[i]]
            CA += 1
            d[P[i]] = -1

print(CA, PN)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
PS = []
for i in range(M):
    p, s = input().split()
    PS += [(int(p),s)]

CA = 0
PN = 0
l = [True]*N
for i in range(len(PS)):
    if l[PS[i][0]]:
        if PS[i][1] == "WA":
            PN += 1
        elif PS[i][1] == "AC":
            CA += 1
            l[PS[i][0]] = False

print(CA, PN)

Fixed submission:
N, M = map(int, input().split())
P = []
S = []
for i in range(M):
    p, s = input().split()
    P += [int(p)]
    S += [s]

CA = 0
PN = 0
d = {key:0 for key in P}
for i in range(len(P)):
    if d[P[i]] >= 0:
        if S[i] == "WA":
            d[P[i]] += 1
        elif S[i] == "AC":
            PN += d[P[i]]
            CA += 1
            d[P[i]] = -1

print(CA, PN)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int,input().split())

result = 0
for n in range(N):
    sm = 0
    for i in range(len(n)):
        sm += n[i]
    if A<=sm<=B:
        result += 1

print(result)

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

result = 0
for n in range(1,N+1):
    sm = 0
    for i in range(len(str(n))):
        sm += int(str(n)[i])
    if A<=sm<=B:
        result += n

print(result)
Buggy python submission (verdict: Runtime Error):
import math

def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in range(1, K+1):
    if N == K:
        if i == 1:
            A = 1
        else:
            A = 0
    else:
        A = C(N - K + 1, i) * C(K - 1, i - 1) % 1000000007
    print(A)


Fixed submission:
import math

def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in range(1, K+1):
    if N - K + 1 < i:
        A = 0
    else:
        A = C(N - K + 1, i) * C(K - 1, i - 1) % 1000000007
    print(A)
Buggy python submission (verdict: Runtime Error):
import numpy as np


arr = np.zeros(9000, dtype=np.int32)

for s in range(3, 64+1):
    for x in range(1, s-2+1):
        for y in range(1, s-1+1):
            z = s - (x + y)
            if z <= 0:
                continue
            arr[s**2 - (x*y + y*z + z*x) - 1] += 1

num = int(input())
for i in range(0, num):
    print(arr[i])


Fixed submission:
import numpy as np


arr = np.zeros(100000, dtype=np.int32)

for s in range(3, 128+1):
    for x in range(1, s-2+1):
        for y in range(1, s-1+1):
            z = s - (x + y)
            if z <= 0:
                continue
            arr[s**2 - (x*y + y*z + z*x) - 1] += 1

num = int(input())
for i in range(0, num):
    print(arr[i])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
import sympy


len_arr = int(input())
arr = list(map(int, input().split()))
counter = Counter(arr)
st = set(arr)

ans = 0
for value, count in counter.items():
    if count > 1:
        continue
    divs = set(sympy.divisors(value))
    if len(divs & st) == 1:
        ans += 1

print(ans)


Fixed submission:
import numpy as np
from collections import Counter


len_arr = int(input())
arr = list(map(int, input().split(' ')))
counter = Counter(arr)
x_max = max(counter.keys())

dp = np.empty(x_max+1, dtype=np.bool_)
dp[:] = True

ans = 0

for x, count in sorted(counter.items()):
    multi = [x*y for y in range(1, x_max//x+1)]
    if count == 1 and dp[x]:
        ans += 1
    dp[multi] = False

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


len_arr = int(input())
arr = np.array(list(map(int, input().split())))

ans = 0
for i in arr:
    mods = np.mod(i, arr)
    num_zeros = np.count_nonzero(mods == 0)
    ans += (num_zeros == 1)

print(ans)


Fixed submission:
import numpy as np
from collections import Counter


len_arr = int(input())
arr = list(map(int, input().split(' ')))
counter = Counter(arr)
x_max = max(counter.keys())

dp = np.empty(x_max+1, dtype=np.bool_)
dp[:] = True

ans = 0

for x, count in sorted(counter.items()):
    multi = [x*y for y in range(1, x_max//x+1)]
    if count == 1 and dp[x]:
        ans += 1
    dp[multi] = False

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
num_query = int(input())

for _ in range(0, num_query):
    query = input()
    if query[0] == "1":
        s = s[::-1]
    else:
        _, pos, character = query.split()
        if pos == "1":
            s = character + s
        else:
            s = s + character
print(s)


Fixed submission:
s = input()
num_query = int(input())

former = ""
latter = ""
is_rev = False

for _ in range(0, num_query):
    query = input()
    if query[0] == "1":
        is_rev = not is_rev
    else:
        pos = query[2]
        character = query[4]
        if pos == "1":
            if is_rev:
                latter += character
            else:
                former = character + former
        else:
            if is_rev:
                former = character + former
            else:
                latter += character

if is_rev:
    ans = latter[::-1] + s[::-1] + former[::-1]
else:
    ans = former + s + latter
print(ans)
Buggy python submission (verdict: Runtime Error):
# from fractions import gcd
from math import gcd

a, b = map(int, input().split())
print(a * b // gcd(a, b))
exit(0)


Fixed submission:
from fractions import gcd
# from math import gcd

a, b = map(int, input().split())
print(a * b // gcd(a, b))
exit(0)
Buggy python submission (verdict: Runtime Error):
num_price, digit_price, budget = map(int, input().split())
min_by_digit = {x: int('1'+'0'*x) * num_price + (x+1) * digit_price for x in range(0, 10)}

max_digit = 0
for i in range(0, 10):
    if min_by_digit[i] > budget:
        break
    else:
        max_digit = i+1

if max_digit == 0:
    print("0")
    exit(0)

if max_digit == 10:
    print("1000000000")
    exit(0)

least = int('1'+'0'*(max_digit-1))
ans = min((budget - (digit_price * max_digit)) // num_price, least*10-1)
print(ans)


Fixed submission:
week = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", ""]
week.reverse()
day = input()
print(week.index(day))
Buggy python submission (verdict: Runtime Error):
_ = input()
input_string = input()

if input_string.count('R') > input_string.count('B')
    print("Yes")
else:
    print("No")

exit(0)


Fixed submission:
_ = input()
input_string = input()

if input_string.count('R') > input_string.count('B'):
    print("Yes")
else:
    print("No")

exit(0)
Buggy python submission (verdict: Runtime Error):
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_list = []
min_sunuke_div = 10 ** 20
for d in reversed(range(1, 16)):
    for n in reversed(range(10, 100)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        if min_sunuke_div >= sunuke_div:
            sunuke_list.append(i)
            min_sunuke_div = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    if min_sunuke_div >= sunuke_div:
        sunuke_list.append(i)
        min_sunuke_div = sunuke_div

sunuke_list.reverse()

for i in range(0, input_num):
    print(sunuke_list[i])


Fixed submission:
input_line = input().split()

num_array = int(input_line[0])
num_equal = int(input_line[1])

input_line = input()
array_str = input_line.split()

array = list(map(int, array_str))

for index, number in enumerate(array):
    if number == 1:
        index_min = index
        break

# from forward

equalized = 1
i = 1
while equalized < num_array:
    equalized += (num_equal - 1)
    # print(i, equalized)
    i += 1

print(i - 1)
Buggy python submission (verdict: Runtime Error):
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_list = []
min_sunuke_div = 10 ** 15
for d in reversed(range(1, 14)):
    for n in reversed(range(10, 100)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        if min_sunuke_div >= sunuke_div:
            sunuke_list.append(i)
            min_sunuke_div = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    if min_sunuke_div >= sunuke_div:
        sunuke_list.append(i)
        min_sunuke_div = sunuke_div

sunuke_list.reverse()

for i in range(0, input_num):
    print(sunuke_list[i])


Fixed submission:
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_dict = {}

min_sunuke_div = 10 ** 20
for d in reversed(range(1, 16)):
    for n in reversed(range(10, 1000)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        sunuke_dict[i] = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    sunuke_dict[i] = sunuke_div

sunuke_sorted = sorted(sunuke_dict.items())
sunuke_list = []

for value, div_value in reversed(sunuke_sorted):
    if min_sunuke_div >= div_value:
        sunuke_list.append(value)
        min_sunuke_div = div_value

sunuke_list.reverse()

for i in range(0, input_num):
    print(str(sunuke_list[i]))

Buggy python submission (verdict: Runtime Error):
def sunuke_sum(arg: str) -> int:
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_list = []
min_sunuke_div = 10 ** 15
for d in reversed(range(1, 14)):
    for n in reversed(range(10, 100)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        if min_sunuke_div >= sunuke_div:
            sunuke_list.append(i)
            min_sunuke_div = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    if min_sunuke_div >= sunuke_div:
        sunuke_list.append(i)
        min_sunuke_div = sunuke_div

sunuke_list.reverse()

for i in range(0, input_num):
    print(sunuke_list[i])


Fixed submission:
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_dict = {}

min_sunuke_div = 10 ** 20
for d in reversed(range(1, 16)):
    for n in reversed(range(10, 1000)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        sunuke_dict[i] = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    sunuke_dict[i] = sunuke_div

sunuke_sorted = sorted(sunuke_dict.items())
sunuke_list = []

for value, div_value in reversed(sunuke_sorted):
    if min_sunuke_div >= div_value:
        sunuke_list.append(value)
        min_sunuke_div = div_value

sunuke_list.reverse()

for i in range(0, input_num):
    print(str(sunuke_list[i]))
Buggy python submission (verdict: Runtime Error):
cake_a = int(input())
cake_b = int(input())

if cake_a > 8 or cake_b > 8:
    print(":(")
    exit(0)
    
print("Yay!")


Fixed submission:
input_line = input().split()

cake_a = int(input_line[0])
cake_b = int(input_line[1])

if cake_a > 8 or cake_b > 8:
    print(":(")
else:
    print("Yay!")

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

if cake_a > 8 or cake_b > 8:
    print(":(")
    exit(0)
    
print("Yay!")


Fixed submission:
input_line = input().split()

cake_a = int(input_line[0])
cake_b = int(input_line[1])

if cake_a > 8 or cake_b > 8:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, intpu().split())
if a+b < 10:
  print(a+b)
else:
  print("error")

Fixed submission:
a, b = map(int, input().split())
if a+b < 10:
    print(a+b)
else:
    print("error")
Buggy python submission (verdict: Runtime Error):
S = int(input())
mod = 10**9 + 7

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range((i+3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[S])


Fixed submission:
S = int(input())
mod = 10**9 + 7

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range((i-3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[S])

Buggy python submission (verdict: Runtime Error):
S = int(input())
mod = 10**9 + 7

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, s+1):
    for j in range((i+3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[S])


Fixed submission:
S = int(input())
mod = 10**9 + 7

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range((i-3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[S])
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
A = list(map(int, input().split())).sort(reverse=True)

if len(A) <= 2:
    print(sum(A))
else:
    ans = A[0] + 2*sum(A[1:math.floor(n/2)]) + (N%2)*A[math.floor[n/2]]
    print(ans)


Fixed submission:
import math
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

ans = A[0] + 2*sum(A[1:math.floor(n/2)]) + (n%2)*A[math.floor(n/2)]
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
A = list(map(int, input().split())).sort(reverse=True)

if len(A) <= 2:
    print(sum(A))
else:
    ans = A[0] + 2*sum(A[1:math.floor(n/2)]) + (N%2)*A[math.floor[N/2]]
    print(ans)


Fixed submission:
import math
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

ans = A[0] + 2*sum(A[1:math.floor(n/2)]) + (n%2)*A[math.floor(n/2)]
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(n):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(n):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while [b] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sympy

n = int(input())

ans = 0
for i in range(1, n+1):
    ans += i * (len(sympy.divisors(i)))

print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1, n+1):
    g = n // i
    ans += i * (g*(g+1))//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list()
C = list()

for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    A = [C[i] if a == B[i] else a for a in A]
    print(sum(A))


Fixed submission:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list()
C = list()

for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

sum_a = sum(A)
c = Counter(A)
for i in range(q):
    b_num = c[B[i]]
    diff = (C[i] - B[i]) * b_num
    c[C[i]] = c[C[i]] + c[B[i]]
    c[B[i]] = 0
    sum_a = sum_a + diff
    print(sum_a)
Buggy python submission (verdict: Runtime Error):
a, b = map(float, input().split())
ans = a * b

print(math.floor(ans))


Fixed submission:
a, b = map(float, input().split())
a = int(a)
b = int(b * 1000)

print(a*b//1000)
Buggy python submission (verdict: Time Limit Exceeded):
input_s = input()
len_s = len(input_s)
ans = 0

for digit in range(4, len_s):
    for i in range(len_s - digit):
        j = i + digit
        if (int(input_s[i:j+1]) % 2019) == 0:
            ans += 1
            i = j

print(ans)


Fixed submission:
s = input()[::-1]
n = len(s)
x = 1
tot = 0 # 累積和
cnt = [0 for i in range(2019)] # 累積和の値になる個数

ans = 0
for i in range(n):
    # print('======={}======'.format(i))
    cnt[tot] += 1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    # print(tot)
    ans += cnt[tot]
    # print('ans:', ans)
    x = x*10%2019

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
input_s = input()
len_s = len(input_s)
ans = 0

for i in range(len_s - 4):
    for j in range(i+3, len_s):
        if (int(input_s[i:j+1]) % 2019) == 0:
            ans += 1
            i = j - 1
            break

print(ans)


Fixed submission:
s = input()[::-1]
n = len(s)
x = 1
tot = 0 # 累積和
cnt = [0 for i in range(2019)] # 累積和の値になる個数

ans = 0
for i in range(n):
    # print('======={}======'.format(i))
    cnt[tot] += 1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    # print(tot)
    ans += cnt[tot]
    # print('ans:', ans)
    x = x*10%2019

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
input_s = input()
len_s = len(input_s)
ans = 0

for i in range(len_s - 4):
    for j in range(i+3, len_s):
        if (int(input_s[i:j+1]) % 2019) == 0:
            ans += 1

print(ans)


Fixed submission:
s = input()[::-1]
n = len(s)
x = 1
tot = 0 # 累積和
cnt = [0 for i in range(2019)] # 累積和の値になる個数

ans = 0
for i in range(n):
    # print('======={}======'.format(i))
    cnt[tot] += 1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    # print(tot)
    ans += cnt[tot]
    # print('ans:', ans)
    x = x*10%2019

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
input_s = input()
len_s = len(input_s)
ans = 0

for i in range(len_s - 4):
    for j in range(i+3, len_s):
        if (int(input_s[i:j+1]) % 2019) == 0:
            ans += 1

print(ans)


Fixed submission:
s = input()[::-1]
n = len(s)
x = 1
tot = 0 # 累積和
cnt = [0 for i in range(2019)] # 累積和の値になる個数

ans = 0
for i in range(n):
    # print('======={}======'.format(i))
    cnt[tot] += 1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    # print(tot)
    ans += cnt[tot]
    # print('ans:', ans)
    x = x*10%2019

print(ans)