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

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(10**(n-i-1)%mod))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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


Fixed submission:
from collections import defaultdict

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(pow(10,n-i-1,mod)))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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

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

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(10**(n-i-1)))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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


Fixed submission:
from collections import defaultdict

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(pow(10,n-i-1,mod)))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
mod = 2019
arr = {0:1}

num = 0
for i in reversed(range(n)):
    num = (num + int(s[i])*(10**(n-i-1)))%mod
    # print(num)
    if num in arr:
        arr[num]+=1
    else:
        arr[num]=1
# print(arr)
ans = 0
for i in arr.values():
    ans += i*(i-1)//2

print(ans)


Fixed submission:
from collections import defaultdict

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(pow(10,n-i-1,mod)))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
mod = 2019

lst = [None for i in range(n+1)]
arr = {0:1}

for i in range(1,n+1):
    num = int(s[n-i:])%mod
    if num in arr:
        arr[num]+=1
    else:
        arr[num]=1

ans = 0
for i in arr.values():
    ans += i*(i-1)//2

print(ans)


Fixed submission:
from collections import defaultdict

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(pow(10,n-i-1,mod)))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
lst = [None for i in range(l)]
lst[0] = int(s[0])
for i in range(l-1):
    lst[i+1] = lst[i]+int(s[i+1])
lst = [0]+lst
# print(lst)

ans = 0
for i in range(l):
    for j in range(i,l):
        if (lst[j+1]-lst[i])%3==0:
            if int(s[i:j+1])%673==0:
                ans += 1

print(ans)

Fixed submission:
from collections import defaultdict

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(pow(10,n-i-1,mod)))%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

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