Buggy python submission (verdict: Time Limit Exceeded):
s=input()

d=[0]*2019
dp=0
d[0]+=1
l=len(s)
r=1

for i in range(l):
	dp+=int(s[l-1-i])*r
	dp%=2019
	r*=10%2019
	d[dp]+=1

res=0

for a in d:
	res+=a*(a-1)//2
	
print(res)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()

d=[0]*2019
dp=0
d[0]+=1
l=len(s)
r=1

for i in range(l-1,-1,-1):
	dp+=int(s[i])*r
	dp%=2019
	r*=10%2019
	d[dp]+=1

res=0

for a in d:
	res+=a*(a-1)//2
	
print(res)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()

d=[0]*2019
dp=0
d[0]+=1
l=len(s)
r=1
for i in range(l-1,-1,-1):
	dp = (dp+int(s[i])*r)%2019
	r*=10%2019
	d[dp]+=1
res=0

for a in d:
	res+=a*(a-1)//2
	
print(res)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()

d=[0]*2019
dp=0
d[0]+=1
l=len(s)

for i in range(l-1,-1,-1):
	dp = (dp+int(s[i])*(10**(l-1-i)))%2019
	d[dp]+=1
res=0

for a in d:
	res+=a*(a-1)//2
	
print(res)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

s=input()
d=defaultdict(int)

dp=0
d[0]+=1
for i in range(len(s)-1,-1,-1):
	dp = (dp+int(s[i])*(10**(len(s)-1-i)))%2019
	d[dp]+=1
res=0

l=list(d.values())
for a in l:
	res+=a*(a-1)//2
	
print(res)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()

res=0
for i in range(len(s)):
	for j in range(i+4,len(s)):
		if int(s[i:j+1])%2019==0:
			res+=1
			
print(res)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)