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

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+(10**(n-i-1))*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)


Fixed submission:
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)

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

S = list(map(int,list(input())))
n = len(S)

dp = [0]*(n+1)

dp[n-1] = S[-1]

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+(10**(n-i-1))*(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)


Fixed submission:
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)

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

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+(10**(n-i-1))*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)


Fixed submission:
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)

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

li = [0]
for i in range(L):
    li.append(li[-1]+int(S[i]))

li.append(li[-1])

for i in range(0,L-4):
    for j in range(i+5,L+1):
        if (li[j]-li[i]) % 3 == 0:
            integer = int(S[i:j])
            if integer % 673 == 0:
                cnt += 1

print(cnt)


Fixed submission:
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)

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

li = [0]
for i in range(L):
    li.append(li[-1]+int(S[i]))

li.append(li[-1])

for i in range(0,L-3):
    for j in range(i+4,L+1):
        if (li[j]-li[i]) % 3 == 0:
            integer = int(S[i:j])
            if integer % 673 == 0:
                cnt += 1

print(cnt)


Fixed submission:
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)

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

for i in range(0,L-3):
    for j in range(i+4,L+1):
        integer = int(S[i:j])
        if integer % 2019 == 0:
            cnt += 1

print(cnt)


Fixed submission:
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)