Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * 10 ** (l - i)) % 2019
    m[t[i - 1]] += 1

for i in m:
    ans += i * (i - 1) // 2

print(ans)

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * 10 ** (l - i)) % 2019
    ans += m[t[i - 1]]
    m[t[i - 1]] += 1
    if t[i - 1] == 0:
        ans += 1

print(ans)

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
t = [2019] * l
t[l - 1] = int(s[l - 1])
ans = 0

for i in range(l - 1, 0, -1):
    mod = (t[i] + int(s[i - 1]) * 10 ** (l - i)) % 2019
    cnt = t.count(mod)
    t[i - 1] = mod
    if mod == 0:
        ans += 1
    if cnt > 0:
        ans += cnt

print(ans)

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
d = [[0] * 2020 for i in range(l + 1)]

for i in range(0, l):
    for j in range(2019):
        if d[i][j] != 0:
            d[i + 1][(j * 10 + int(s[i])) % 2019] = d[i][j]
    d[i + 1][int(s[i])] += 1
    d[i + 1][2019] += d[i][2019] + d[i + 1][0]

print(d[l][2019])

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
d = [[0] * 2020 for i in range(l + 1)]

for i in range(0, l):
    for j in range(2019):
        d[i + 1][(j * 10 + int(s[i])) % 2019] = d[i][j]
    d[i + 1][int(s[i])] += 1
    d[i + 1][2019] += d[i][2019] + d[i + 1][0]

print(d[l][2019])

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
d = [[0] * 2020 for i in range(l + 1)]

for i in range(0, l):
    for j in range(2019):
        d[i + 1][(j * 10 + int(s[i])) % 2019] = d[i][j]
    d[i + 1][int(s[i])] += 1
    d[i + 1][2019] += d[i][2019] + d[i + 1][0]

print(d[l][2019])

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
d = [0] * l

for i in range(2, l - 1):
    cnt = 0
    for j in range(i):
        if int(s[j:i+2]) % 2019 == 0:
            cnt += 1
    d[i + 1] += d[i] + cnt

print(d[l - 1])

Fixed submission:
S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)