Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

S = list(map(int,list(input())))
N = len(S)
L = [0]
for i in range(N):
    L.append((L[-1] + S[-i-1] * pow(10, i)) % 2019)
count = Counter(L)
ans = 0
for value in count.values():
    ans += value * (value - 1) // 2
print(ans)

Fixed submission:
from collections import Counter

S = list(map(int,list(input())))
S.reverse()
N = len(S)
L = [0]
power = 1
for i in range(N):
    L.append((L[-1] + S[i] * power) % 2019)
    power *= 10
    power %= 2019
count = Counter(L)
ans = 0
for value in count.values():
    ans += value * (value - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
S = list(map(int,list(input())))
N = len(S)
ans = 0
pre_d = defaultdict(int)
for i in range(N):
    new_d = defaultdict(int)
    for k, v in pre_d.items():
        new_d[(10 * k + S[i]) % 2019] += v
    new_d[S[i]] += 1
    ans += new_d[0]
    pre_d = new_d
print(ans)

Fixed submission:
from collections import Counter

S = list(map(int,list(input())))
S.reverse()
N = len(S)
L = [0]
power = 1
for i in range(N):
    L.append((L[-1] + S[i] * power) % 2019)
    power *= 10
    power %= 2019
count = Counter(L)
ans = 0
for value in count.values():
    ans += value * (value - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
S = list(map(int,list(input())))
N = len(S)
ans = 0
pre_d = defaultdict(int)
for i in range(N):
    new_d = defaultdict(int)
    for k, v in pre_d.items():
        new_d[(10 * k + S[i]) % 2019] += v
    new_d[S[i]] += 1
    ans += new_d[0]
    pre_d = new_d
print(ans)

Fixed submission:
from collections import Counter

S = list(map(int,list(input())))
S.reverse()
N = len(S)
L = [0]
power = 1
for i in range(N):
    L.append((L[-1] + S[i] * power) % 2019)
    power *= 10
    power %= 2019
count = Counter(L)
ans = 0
for value in count.values():
    ans += value * (value - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,list(input())))
N = len(S)
dp = [[0 for i in range(2019)] for j in range(N + 1)]
for i in range(N):
    for j in range(2019):
        dp[i+1][(10 * j + S[i]) % 2019] += dp[i][j]
    dp[i+1][S[i]] += 1
ans = 0
for i in range(N+1):
    ans += dp[i][0]
print(ans)

Fixed submission:
from collections import Counter

S = list(map(int,list(input())))
S.reverse()
N = len(S)
L = [0]
power = 1
for i in range(N):
    L.append((L[-1] + S[i] * power) % 2019)
    power *= 10
    power %= 2019
count = Counter(L)
ans = 0
for value in count.values():
    ans += value * (value - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,list(input())))
N = len(S)
dp = [[0 for i in range(2019)] for j in range(N + 1)]
for i in range(N):
    for j in range(2019):
        dp[i+1][(10 * j + S[i]) % 2019] += dp[i][j]
    dp[i+1][S[i]] += 1
ans = 0
for i in range(N+1):
    ans += dp[i][0]
print(ans)

Fixed submission:
from collections import Counter

S = list(map(int,list(input())))
S.reverse()
N = len(S)
L = [0]
power = 1
for i in range(N):
    L.append((L[-1] + S[i] * power) % 2019)
    power *= 10
    power %= 2019
count = Counter(L)
ans = 0
for value in count.values():
    ans += value * (value - 1) // 2
print(ans)