Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
n = len(s)
cs = [0] * (n + 1)
for i, x in enumerate(s[::-1]):
    cs[i + 1] = cs[i] + int(x) * 10 ** i % 2019
    cs[i + 1] %= 2019
dp = [0] * 2019
for i, x in enumerate(cs):
    dp[x] += 1
ans = sum(x * (x - 1) // 2 for x in dp)
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
s = input()
n = len(s)
ans = 0
cs = [0] * (n + 1)
cs[1] = cs[0] + int(s[0])
cs[2] = cs[1] + int(s[1])
cs[3] = cs[2] + int(s[2])
for i in range(n):
    for j in range(i + 3, n + 1):
        if i == 0 and j < n:
            cs[j + 1] = cs[j] + int(s[j])
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        k = int(s[i:j])
        if k % 2019 == 0:
            ans += 1
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
n = len(s)
cs = [0] * (n + 1)
for i, x in enumerate(map(int, list(s))):
    cs[i + 1] = cs[i] + x
ans = 0
for i in range(n):
    for j in range(i + 3, n + 1):
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        k = int(s[i:j])
        if k % 2019 == 0:
            ans += 1
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def main():
    s = input().rstrip()
    n = len(s)
    cs = [0] * (n + 1)
    for i, x in enumerate(s):
        cs[i + 1] = cs[i] + int(x)
    ans = 0
    for i in range(n):
        for j in range(i + 3, n + 1):
            if (cs[j] - cs[i]) % 3 != 0:
                continue
            if int(s[i:j]) % 2019 == 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
n = len(s)
cs = [0] * (n + 1)
for i, x in enumerate(s):
    cs[i + 1] = cs[i] + int(x)
ans = 0
for i in range(n):
    for j in range(i + 3, n + 1):
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        if int(s[i:j]) % 2019 == 0:
            ans += 1
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
n = len(s)
cs = [0] * (n + 1)
for i, x in enumerate(s):
    cs[i + 1] = cs[i] + int(x)
ans = 0
for i in range(n):
    for j in range(i + 3, n + 1):
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        k = int(s[i:j])
        if k % 2019 == 0:
            ans += 1
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = input()[::-1]
n = len(s)
cs = [0] * (n + 1)
ten = 1
for i in range(n):
    cs[i + 1] = int(s[i]) * ten % 2019
    ten = ten * 10 % 2019
for i in range(n):
    cs[i + 1] = (cs[i + 1] + cs[i]) % 2019
cnt = [0] * 2019
for i, x in enumerate(cs):
    cnt[x] += 1
ans = sum(x * (x - 1) // 2 for x in cnt)
print(ans)