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

S = input()
B = defaultdict(int)
B[0]=1
ans=0

for i in range(len(S)):
    m=int(S[-i-1:])%2019
    ans+=B[m]
    B[m]+=1

print(int(ans))

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))

Buggy python submission (verdict: Runtime Error):
S = input()
B = defaultdict(int)
B[0]=1
ans=0

for i in range(len(S)):
    m=int(S[-i-1:])%2019
    ans+=B[m]
    B[m]+=1

print(int(ans))

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))

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

S = input()
B = defaultdict(int)
B[0]=1

for i in range(len(S)):
    B[int(S[-i-1:])%2019]+=1

ans=0

for j in B:
    ans+=(B[j]-1)*B[j]/2

print(int(ans))

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
B = [0]*2019
B[0]+=1

for i in range(len(S)):
    B[int(S[-i-1:])%2019]+=1

ans=0

for j in range(2019):
    ans+=(B[j]-1)*B[j]/2

print(int(ans))

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
B = [0]*2019
B[0]+=1

for i in range(len(S)):
    B[int(S[-i-1:])%2019]+=1

ans=0

for j in range(2019):
    ans+=(B[j]-1)*B[j]/2

print(int(ans))

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
A = []
B = [0]*2019
B[0]+=1

for i in range(len(S)):
    A.append(int(S[-i-1:])%2019)
    B[int(S[-i-1:])%2019]+=1

ans=0

for j in range(len(B)):
    ans+=(B[j]-1)*B[j]/2

print(int(ans))

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))

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

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

print(ans)

Fixed submission:
from collections import defaultdict

S = input()
B = defaultdict(int)
B[0]=1
ans=0
prev=0

for i in range(len(S)):
    m=(prev+int(S[-i-1])*pow(10,i,2019))%2019
    ans+=B[m]
    B[m]+=1
    prev=m

print(int(ans))