Buggy python submission (verdict: Time Limit Exceeded):
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
for i in range(len(s)):
    S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[S[i+1]]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Fixed submission:
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
for n,i in enumerate(s):
    # print(s[n], i, n)
    S.append((int(S[n]) + int(i) * 10**n) % 2019)
    cnt[S[n+1]]+=1

# print(S)
ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Fixed submission:
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
for n,i in enumerate(s):
    # print(s[n], i, n)
    S.append((int(S[n]) + int(i) * 10**n) % 2019)
    cnt[S[n+1]]+=1

# print(S)
ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Fixed submission:
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

s=input()
s= s[::-1]

S=[0,]

for n,i in enumerate(s):
    # print(s[n], i, n)
    S.append((int(S[n]) + int(i) * 10**n) % 2019)

# print(S)
ans=0
for i in range(0,len(s)-4):
    for j in range(i+5, len(s)+1):
        if S[i]- S[j]==0:
            ans+=1

print(ans)

Fixed submission:
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
for i in range(0,len(s)-4):
    for j in range(i+5, len(s)+1):
        if int(s[i:j])%2019==0:
            ans+=1

print(ans)

Fixed submission:
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
for i in range(0,len(s)-4):
    for j in range(i+5, len(s)+1):
        if int(s[i:j])%2019==0:
            ans+=1

print(ans)

Fixed submission:
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)