Buggy python submission (verdict: Time Limit Exceeded):
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in s:
    num += int(i)*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

# print(counts)
ans = 0
for j in counts:
    ans +=j*(j-1)/2


print(int(ans))

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    ans +=j*(j-1)/2


print(int(ans))

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import math
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    if j>=2:
        ans +=combinations_count(j, 2)


print(ans)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Runtime Error):
import math
s = int(input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += s[i]*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
        ans +=combinations_count(j, 2)


print(ans)



Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import math
s = input()[::-1] # 入力文字列を逆順でsに格納
n = len(s)
# taro = [0]*n
s_ = [0]*n
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    s_[i] = int(s[i])*b +num
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

# for i in range(n):
#     a = s_[i]%2019
#     taro[i]=a
# print(taro)
# counts = [0]*2019
# for i in range(n):
#     counts[taro[i]]+=1
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    if j>=2:
        ans +=combinations_count(j, 2)


print(ans)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import math
s = input()[::-1] # 入力文字列を逆順でsに格納
n = len(s)
taro = [0]*n
s_ = [0]*n
b = 1
num = 0
for i in range(n):
    s_[i] = int(s[i])*b +num
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019

for i in range(n):
    a = s_[i]%2019
    taro[i]=a
# print(taro)
counts = [0]*2019
for i in range(n):
    counts[taro[i]]+=1
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    if j>=2:
        ans +=combinations_count(j, 2)
ans += counts[0]

print(ans)


Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    # d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
n = len(s)
count = 0
for i in range(1,n-2):
    for k in range(3,n+1):
        j = i+k
        if (j<=n):
            st = int(s[i-1:j])
            if int(st)%2019==0:
                count +=1
print(count)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力