Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(map(int, list(input())))
mod = 2019
lens = len(S)
mods = [0]*lens
cum = 0
for i in range(lens):
    s = S[-i-1]
    cum += s*(10**i)
    cum %= mod
    mods[i] = cum
mods += [0]
from collections import Counter
c = Counter(mods)

ans = 0
for num, cnt in c.most_common():
    if cnt<2:
        break
    ans += cnt*(cnt-1)//2
print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l)*int(S[l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1
    if i==0:
        ans += 1

print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1

print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1

print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1

print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    dic[i] += 1

for k in dic.keys():
    num = dic[k]
    ans += num*(num-1)//2

print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

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

mod = 2019
dp = [0]*(L)
zero = 0
for l in range(L):
    t = int(S[-l:])%mod
    dp[l] = t
    if t==0:
        zero+=1

l = len(set(dp))
print(L-l+zero)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)

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

ans = 0
for i in range(L-3):
    for j in range(i+2, L+1):
        if int(S[i:j])%2019==0:
            ans += 1
print(ans)

Fixed submission:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l, mod)*int(S[l])%mod
    t %= mod
    ans += dic[t]
    dic[t] += 1
    if t==0:
        ans += 1

print(ans)