Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = []
n = len(s)
mod = 2019
for i in range(n-1, -1, -1):
    l.append(int(s[i:])%mod)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

Fixed submission:
s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = []
n = len(s)
mod = 2019
for i in range(n-1, -1, -1):
    l.append(int(s[i:])%mod)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

Fixed submission:
s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

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

Fixed submission:
s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

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

Fixed submission:
s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

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

Fixed submission:
s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
for i in range(len(s)):
    a = int(s[i:])
    while a > 1000:
        if a % 2019 == 0:
            ans += 1
        a //= 10
print(ans)

Fixed submission:
s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)