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

s = input()

rests = []
n = 0
a = 0
m = 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    rests.append(n % 2019)
    m *= 10

c = Counter(rests)

for v in c.values():
    a += v * (v-1) // 2
 
a += c[0]
 
print(a)






Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

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

s = input()
l = len(s)
s = int(s)

rests = []

d = 10**(l-1)

while s > 0:
    r = s % 2019
    rests.append(r)

    s = s % d
    d = d // 10

a = 0

c = Counter(rests)

for v in c.values():
    if v >= 2:
        a += v * (v-1) // 2

a += c[0]

print(a)





Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

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

rests = [0]*2019

d = 10**(l-1)

while s > 0:


    r = s % 2019
    rests[r] +=  1

    s = s % d
    d = d // 10

a = 0

for v in rests:
    if v >= 2:
        a += v * (v-1) // 2

a += rests[0]

print(a)





Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

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

rests = {}

d = 10**(l-1)

while s > 0:


    r = s % 2019
    rests[r] = rests.get(r, 0) + 1

    s = s % d
    d = d // 10

a = 0

for v in rests.values():
    if v >= 2:
        a += v * (v-1) // 2

a += rests.get(0,0)

print(a)





Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

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

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:])
	while num > 2019:
		if num % 2019 == 0:
			s += 1
			num = num // 10
		elif num % 2019 < 10:
			num = num // 10
		elif num % 2019 < 100:
			num = num // 100
		elif num % 2019 < 1000:
			num = num // 1000
		else:
			num = num // 10000
print(s)

Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

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

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:])
	while num > 2019:
		if num % 2019 == 0:
			s += 1
		num = num // 10

print(s)

Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

Buggy python submission (verdict: Runtime Error):
inp = input()

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:-1])
    while num >2019:
		if num % 2019 == 0:
			s += 1
		num = num / 10

print(s)

Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

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

s = 0

for i in range(len(inp)-3):
	for j in range(i+4, len(inp)+1):
		num = int(inp[i:j])
		if num % 2019 == 0:
			s += 1

print(s)

Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)