Buggy python submission (verdict: Time Limit Exceeded):
import sys
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            v = i*10+c
            dp2[v if v<2019 else v%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
S = [x-ord('0') for x in sys.stdin.buffer.read().rstrip()]
print(solve(S))

Fixed submission:
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            dp2[(i*10+c)%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
S = [x-ord('0') for x in sys.stdin.buffer.read().rstrip()]
print(solve(S))

Fixed submission:
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        c = int(c)
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            dp2[(i*10+c)%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
print(solve(input()))

Fixed submission:
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

dp = [0] * 2019
ans = 0
for c in S:
    c = int(c)
    dp2 = [0] * 2019
    dp2[c] = 1
    for i in range(2019):
        if dp[i] == 0: continue
        dp2[(i*10+c)%2019] += dp[i]
    dp = dp2
    ans += dp[0]
print(ans)

Fixed submission:
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0
for i in range(len(S)):
    for j in range(100):
        if i+j+1 > len(S): break
        if int(S[i:i+j+1]) % 2019 == 0:
            ans += 1
print(ans)

Fixed submission:
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0
for i in range(len(S)):
    for j in range(2020):
        if i+j+1 > len(S): break
        if int(S[i:i+j+1]) % 2019 == 0:
            ans += 1
print(ans)

Fixed submission:
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)